# The Industry's Foundation for High Performance Graphics

1. ## Rotating an object

Hi,
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!

2. ## Re: Rotating an object

Hi !

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.

Mikael

3. ## Re: Rotating an object

Does it look like this?
Code :
```...
if (bAnimated)
{
fRotate += fIncrement;
if (fRotate < 0.0)
fRotate += 360.0f;
else if (fRotate >= 360.0)
fRotate -= 360.0f;
}
glMatrixMode(GL_MODELVIEW);
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);
DrawMyModel();
SwapBuffers(hdc);
...```

4. ## Re: Rotating an object

yes, my code looks similar:

void display(){
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);

drawNURBS();
glutSwapBuffers();

}

void spinDisplay(){

spin = 1.0;
if(spin>360)
spin = 0;
glutPostRedisplay();

}

any suggestion?

5. ## Re: Rotating an object

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:
push
rotate
rotate
draw
pop

[This message has been edited by Relic (edited 07-03-2003).]

6. ## Re: Rotating an object

thanks =)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•