Rotation problem
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!
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.
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.. ;(
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 int01hC++ math library functions work with radians; OpenGL functions work with degrees. You will need to convert the angle to degrees before calling glRotatef().
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.. ;(
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement