Rotating a polygon

I have a problem i been fighting with over 10 hours today. I have made a program that displays a little triangle att the bottom of the screen pointing up. I know how to rotate it using glRotatef, but how do i move it in the new direction after i rotated it??

Like if i rotated it 30 degrees, and i want the triangle to move in that direction which the tirangle is pointing. Hard to explain maybee… but i would be very happy if someone could help me with this.

Tim Törnström

something like the logo turtle, i suppose…

you can do with only glFunctions, but you have to make it incrementally this way.

each frame of the animation, you do:

glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(matrix);
glTranslatef(…);
glRotatef(…);
glGetFloatv(GL_MODELVIEW,matrix);
<render>

this will make the matrix store the triangle status for any time.
you could also use another schemes, like pushing/popping the matrix onto the stack…
but this seems more understandable to me.

you actually rotate, then translate, the turtle, and you save its current position/heading into matrix.

note that this method can be generally used when you need to move an object into space, relatively to its previous state; you tell the object: “move 10 meters forward!” “turn left 30 degrees!”

Dolo//\ightY

But i want it to be moved around using the keyboard… Btw i think i solved it already…
but now i have a new problem… When i rotate
the triangel it rotates around the original startingpoint instead of rotating around itself… wierd.

after you have done your movement, im assuming you used a little bit of trig if you didnt use the gl functions this should work for you.

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();

glLoadIdentity();
MoveYourObject();
    RenderYourObject();

glPopMatrix();

void MoveYourObject(void)
{
glTranslatef(x,y,z);
glRotated(Roll, 1.0f, 0.0f, 0.0f);
glRotated(Pitch, 0.0f, 1.0f, 0.0f);
glRotated(Heading, 0.0f, 0.0f, 1.0f);
}

hope this helps…

dans