View Full Version : Rotating a polygon
05-05-2000, 10:54 AM
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.
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:
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!" http://www.opengl.org/discussion_boards/ubb/smile.gif
05-05-2000, 01:37 PM
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.
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...
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.