Jump to content
  • Advertisement
Sign in to follow this  
x86melter

Vector rotation to Euler angles

This topic is 2578 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

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

Share this post


Link to post
Share on other sites
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!