Sign in to follow this  

Vector rotation to Euler angles

Recommended Posts

x86melter    100
I'm trying to convert vector rotation angles from a game into euler angles. There is no roll in the game so I don't need to calculate that. I'm just extracting these figures from the game memory.

I wrote this little function here..
[code]void ForwardVectorToEuler2d(real_vector3d *forward, real_euler_angles2d *euler)
euler->yaw = atanf(forward->j/forward->i);
euler->pitch = atanf(forward->k/sqrt((forward->j*forward->j)+(forward->i*forward->i)));
if(euler->yaw < 0.0f)
euler->yaw += CAST(real, 2.0f * M_PI);

Pitch is converted correctly. The problem is the converted yaw goes from 0-360 twice in a full turn. So when I turn the player 180 degrees, it goes from 0-360 degrees, then when I continue rotating the final 180 degrees, it does 0-360 again. I need the converted yaw to be 0-360 degrees in a full turn. Hopefully that makes sense.

[b][u]Update[/u][/b]: For the heck of it, I tried using atan2f instead for yaw and it worked [b]perfectly[/b]. Can anyone explain this?

Share this post

Link to post
Share on other sites
inprazia    107
It's simple. The atan2f function considers the signs of its two arguments, thus yielding the correct result. By using the atanf function, you loose the sign information.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this