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.

glRotate multiplies the current modelview matrix with a rotation matrix that represents your rotation around the Y-axis.
Every time you call display (), the current modelview matrix is multiplied, including your previous rotations, so they are being summed. After a while your rotation will indeed become huge. You can fix this two ways:

- call glRotatef(angle,0.0,1.0,0.0); in display() without increasing the angle (so leave out angle=angle+0.001;). This way your rotation will be summed with the previous rotation each time (the effect you want to achieve with angle+= 0.001). the next way works better though:

- call glLoadIdentity () right after glClear(GL_COLOR_BUFFER_BIT | L_DEPTH_BUFFER_BIT); this will reset the modelview matrix. You can now rotate the torus each time, without having the effect of the previous rotations (you have to keep angle += 0.001). Usually it's a good idea to start your display function with a call to glLoadIdentity (), so your current drawing won't be affected by previous rotations, translations or scalings.

greetz

jide

10-25-2005, 09:02 AM

Don't use:

angle=angle+0.001;

But:

angle+= angular_speed * dt;

with angular_speed is the speed (number of turns per second) and dt is the elapsed time in seconds since the last draw.