• FEATURED
• FEATURED
• FEATURED
• FEATURED
• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Vector rotation to Euler angles

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

### #1x86melter  Members

Posted 18 November 2011 - 01:04 PM

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?

### #2inprazia  Members

Posted 23 November 2011 - 07:20 AM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.