# Vector rotation to Euler angles

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

## 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 on other sites
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.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 21
• 21
• 11
• 25