Rotation problem

Started by
3 comments, last by int01h 17 years, 9 months ago
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!
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.
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.. ;(


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().
It works after conversion

You rule guys!

This topic is closed to new replies.

Advertisement