Jump to content
  • Advertisement
Sign in to follow this  
int01h

Rotation problem

This topic is 4524 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

Hi guys.. got a question. My Player is at: player.x=10; player.z=10; the tree is at: tree.x=34; tree.z=33; i would like to call glRotatef(...) before rendering player to let him face the tree with his eyes.. what calculation should i perform to rotate his face towards the tree ? Regards!

Share this post


Link to post
Share on other sites
Advertisement
I would guess angle = atan2(tree.x - player.x, tree.z - player.z)
Well, since we are in a 2D plane, then glRotatef(angle, 0, 1, 0) - you may need to use -angle instead, I'm not really shure. I haven't tested this tought. To be honest, I wouldn't trust myself on that, but hey, I think it's quite simple to try it out.

Share this post


Link to post
Share on other sites
float rotater=0;
rotater=atan2(TREE.x-PLAYER.x , TREE.z -PLAYER.z);
glRotatef(rotater,0,1,0);


Doesn't seem to be working, in fact player isnt rotated in ANY direction.. ;(


Share this post


Link to post
Share on other sites
Quote:
Original post by int01h
float rotater=0;
rotater=atan2(TREE.x-PLAYER.x , TREE.z -PLAYER.z);
glRotatef(rotater,0,1,0);


Doesn't seem to be working, in fact player isnt rotated in ANY direction.. ;(
C++ math library functions work with radians; OpenGL functions work with degrees. You will need to convert the angle to degrees before calling glRotatef().

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!