Jump to content
  • Advertisement
Sign in to follow this  
CryoSleep

Need Help With Animation

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 matrix
glTranslatef(0.0,-1.0,0.0); // put in a vector pointing up
glRotatef( whatever you did to the arrow ); // rotate it
glGet(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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!