hi, im having a bit of trouble keeping this rotating torus at a constant speed, i’ve reduced the increment of it rotation to a really small number. it starts off fine but then speeds up, is this something to do with buffers? i apologise for my ignorance i’m a newbie.
Here’s the code:
#include <gl\glut.h>
float angle=0.0;
void init(void)
{
GLfloat mat_specular[] = {1.0,1.0,1.0,1.0};
GLfloat mat_shininess[] = {50.0};
GLfloat light_position[] = {1.0,1.0,1.0,0.0};
GLfloat white_light[] = {1.0,0.0,0.0,1.0};
GLfloat lmodel_ambient[] = {0.4,0.1,0.1,1.0};
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_SMOOTH);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
glLightfv(GL_LIGHT0, GL_SPECULAR, white_light);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
void display (void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glRotatef(angle,0.0,1.0,0.0);
glutSolidTorus(0.25,0.5,4,100);
angle=angle+0.001;
glutSwapBuffers();
glFlush();
}
int main (int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow(“Rotating Torus”);
init();
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
return 0;
}
Thanks for your help.