PDA

View Full Version : Idle-callback animation



bm365
08-03-2011, 07:20 AM
Im looking for some help with OpenGL for an exam I have. Im doing some sample questions to prepare but stuck with one! Hoping someone might be able to help me.

The program below uses wire spheres to display a 'sun' and a 'planet' in OpenGL:

#include <GL/glut.h>
void display(void) {
glClear (GL_COLOR_BUFFER_BIT);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(60.0, 1.0, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glutWireSphere(1.0, 20, 16); // draw sun
glTranslatef (2.0, 0.0, 0.0);
glutWireSphere(0.2, 10, 8); // draw planet
glutSwapBuffers();
}
int main(int argc, char** argv) {
glutInit(&amp;argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Planets");
glClearColor (0.0, 0.0, 0.0, 0.0);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}


Q) Using idle-callback animation, modify this program so that the planet rotates around the sun. The planet should rotate around its own centre as well as independently rotating around the centre of the sun. One complete rotation around the sun should take 365 times as long as one rotation around its own centre.

ZbuffeR
08-03-2011, 08:12 AM
http://glprogramming.com/red/chapter03.html how convenient