/*****************************************************************
  cave0.cpp
  by Dave Pape
  22 Feb 2003

 This program is a first, simple example of a CAVElib program.
 It draws a bouncing ball, with no interaction.

*****************************************************************/
#include <unistd.h>
#include <stdlib.h>
#include <math.h>
#include <cave_ogl.h>
#include <GL/gl.h>
#include <dms/dms.h>

void drawEverything(void);
void initGraphics(void);
void updateData(void);

float height=0;
GLUquadric * quadric;

int main(int argc, char *argv[])
    {
/* Initialize, & open the window */
    CAVEConfigure(&argc,argv,NULL);
    CAVEInit();  
/* Set callback functions */
    CAVEInitApplication(initGraphics,0);  
    CAVEFrameFunction(updateData,0);  
    CAVEDisplay(drawEverything,0);
/* Loop until Escape is hit */
    while (!CAVEgetbutton(CAVE_ESCKEY))
        usleep(10000);
    CAVEExit();
    }


void initGraphics(void)
    {
/* Create the quadric object */
    quadric = gluNewQuadric();
    gluQuadricDrawStyle(quadric, GLU_LINE);
    }


void drawEverything(void)
    {
/* Clear the window */
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    
/* Draw the bouncing ball */
    glColor3f(1.0, 0.9, 0.0);
    glTranslatef(0.0, height, 0.0);
    gluSphere(quadric, 1.0, 24, 16);
    }


void updateData(void)
    {
/* Update the bouncing ball's data */
    height = fabs(sin(dms::currentTime())) * 4;
    }
