one very basic question.
I need to rotate my tilted NURBS object on y-axis constantly.In my code, i use glRotatef twice to tilt the object and then to rotate it.
I also use the keyboard functions to start the rotation, simply by calling glutPostRedisplay.
The problem is that everytime i call the function, the program is rotating the object twice(tilting + rotating). I only want it to tilt it in the beginning and then keep rotating the object. it seems very simple, but somehow i can’t get this to work!!!
To do this, what am I supposed to keep in mind? help, please~ Thanks!
It’s difficult to say without seeing the code, if you could post the piece of code that does the rotation it would be easier.
Does it look like this?
fRotate += fIncrement;
if (fRotate < 0.0)
fRotate += 360.0f;
else if (fRotate >= 360.0)
fRotate -= 360.0f;
glTranslatef(0.0f, 0.0f, -fOrigin); // Center of your frustum.
glRotatef(fTilt, 1.0f, 0.0f, 0.0f);
glRotatef(fRotate, 0.0f, 1.0f, 0.0f);
yes, my code looks similar:
init() /for initializing NURBS/
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glRotate(10.0, 1.0, 0.0, 0.0); /titiling/
glRotate(spin, 0.0, 1.0, 0.0);
spin = 1.0;
spin = 0;
Your code incrementally rotates the modelviewmatrix without resetting it.
Spin never changes.
If you do this for some hours, the matrix will run away because of floating point errors accumulating over time.
Read my post again and change your spin angle handling to be actually incremented like in mine. In your example it stays at 1.0 all the time.
Add the modelview initialization with glLoadIdentity(), glTranslatef() or whatever you did to setup you initial view.
Or better put glPushMatrix, glPopMatrix around your code like this:
[This message has been edited by Relic (edited 07-03-2003).]