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

void drawEverything(void);
void key(unsigned char k, int x, int y);
void idle(void);

float height=0;
GLUquadric * quadric;

int main(int argc, char *argv[])
    {
/* Initialize, & open the window */
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("example");
/* Set callback functions */
    glutDisplayFunc(drawEverything);
    glutKeyboardFunc(key);
    glutIdleFunc(idle);
/* Create the quadric object */
    quadric = gluNewQuadric();
    gluQuadricDrawStyle(quadric, GLU_LINE);
/* Start GLUT's event loop */
    glutMainLoop();
    return 0;
    }


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);
    
/* Load the perspective projection */
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60.0, 1.0, 1.0, 10.0);
    glMatrixMode(GL_MODELVIEW);

/* Set up a view transformation */
    glLoadIdentity();
    glTranslatef(0.0, 0.0, -6.0);
    
/* Draw the bouncing ball */
    glColor3f(1.0, 0.9, 0.0);
    glTranslatef(0.0, height, 0.0);
    gluSphere(quadric, 1.0, 24, 16);

/* Swap the buffers to display the result */
    glutSwapBuffers();
    }


void key(unsigned char k, int x, int y)
    {
/* Quit the program when Escape is hit */
    if (k == 27)
        exit(0);
    }


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