# Need Help With Animation

This topic is 4784 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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. // lessbread edit - added a title

##### Share on other sites
i guess you'll need sin and cos laws

e.g:

x=x+cos(angle)*distance
y=y+sin(angle)*distance

(might need some adjustments to work properly)

##### Share on other sites
If you want to do it in 3d, there are lots of ways but it is a little harder. If 2d is all you are doing, ignore me and use sin/cos.

You could get the object's matrix (with glGet), strip off everything but the rotation matrix, and multiply the vector (0,-1,0) by the rotation matrix.

Or probably easier but more messy, is to do it with opengl:
float matrix[16];glLoadIdentity();                           // reset the modelview matrixglTranslatef(0.0,-1.0,0.0);                 // put in a vector pointing upglRotatef( whatever you did to the arrow ); // rotate itglGet(GL_MODELVIEW_MATRIX, matrix);         // get back the rotated vector// the rotated vector is now stored in matrix[12], matrix[13] and matrix[14]

Just typed from memory, hopefully no mistakes :)

This gives you a vector pointing the same way as the arrow, add the vector to the x,y,z co-ordinates of the arrow to move it.

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633323
• Total Posts
3011361
• ### Who's Online (See full list)

There are no registered users currently online

×