rotating spheres
- by Dave
I want to continuously rotate 2 spheres, however the rotation does not seem to work.
Here is my code:
float angle = 0.0f;
void light(){
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
// Create light components
GLfloat positionlight1[] = { 9.0, 5.0, 1.0, 0.0 };
GLfloat positionlight2[] = {0.2,2.5,1.3,0.0};
GLfloat light_ambient1[] = { 0.0, 0.0, 1.0, 1.0};
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient1);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, positionlight1);
glLightfv(GL_LIGHT1, GL_POSITION, positionlight2);
}
void changeSize(int w, int h) {
if (h==0) // Prevent A Divide By Zero By
{
h=1; // Making Height Equal One
}
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
glViewport(0,0,w,h);// Reset The Current Viewport
// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix // Reset The Modelview Matrix
}
void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix(); //set where to start the current object
glTranslatef(0.0,1.2,-6);
glRotatef(angle,0,1.2,-6);
glutSolidSphere(1,50,50);
glPopMatrix(); //end the current object transformations
glPushMatrix(); //set where to start the current object
glTranslatef(0.0,-2,-6);
glRotatef(angle,0,-2,-6);
glutSolidSphere(0.5,50,50);
glPopMatrix(); //end the current object transformations
angle=+0.1;
glutSwapBuffers();
}
int main(int argc, char **argv) {
// init GLUT and create window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(500,500);
glutCreateWindow("Hello World");
// register callbacks
light();
glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
glutIdleFunc(renderScene);
// enter GLUT event processing loop
glutMainLoop();
return 1;
}
Graphicstest::Graphicstest(void)
{
}
In the renderscene where i draw,translate and rotate my 2 spheres. It does not seem to rotate the spheres continuously.
What am i doing wrong?