# 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.

## 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 on other sites
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 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 on other sites
Quote:
 Original post by int01hfloat 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 on other sites
It works after conversion

You rule guys!

1. 1
Rutin
61
2. 2
3. 3
4. 4
5. 5

• 12
• 10
• 28
• 20
• 9
• ### Forum Statistics

• Total Topics
633412
• Total Posts
3011751
• ### Who's Online (See full list)

There are no registered users currently online

×