Skip to main content
gamedev.net
🔒 Locked

Rotation problem

Started by int01h 3 replies 850+ views
Original Post
int01h
int01h
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!
algumacoisaqualquer
algumacoisaqualquer
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.
int01h
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.. ;(


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

You rule guys!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.