Skip to main content
GameDev.net gamedev.net
🔒 Locked

Vector from Euler angles

Started by fatgraham Feb 24, 2003 at 5:16 PM 0 replies 450+ views
Original Post
fatgraham
fatgraham
For some simple rotation stuff im trying to just use a Pitch, Yaw and a normal for all my stuff... Now, Ill need conversions between them Vector -> Pitch/Yaw Yaw = atan2f( Normal.x, Normal.z ); float xzlen = sqrtf( (Normal.x*Normal.x) + (Normal.z*Normal.z) ); Pitch = atan2f( xzlen, Normal.y ); This is right, now, getting the vector seems to be wrong, Im pretty sure the below is correct... Pitch/Yaw -> Vector Normal.x = sinf( Pitch ) * sinf( Yaw ); Normal.z = sinf( Pitch ) * cosf( Yaw ); Normal.y = cosf( Pitch ); but aparently not, does anybody have the proper formulae/calculations?
LilBudyWizer
LilBudyWizer
I think you need to switch the sines and cosines on the pitch. Your conversion between the two representations are consistant. It just isn't clear if you switched x and y on the atan2 function intentionally or by accident. If the only way you change pitch and yaw is through the normal then it doesn't really matter. If you modify it by other means then it does matter. Your pitch is the angle with the y axis. Your yaw is the angle with the z axis. Positioned at the origin a pitch of zero will have you looking straight down the y axis assuming the normal is the forward vector. A pitch of 90 degrees and yaw of zero has you pointing straight down the z axis. So any direct modification of pitch and yaw, such as mouse movement or cursor keys, has to be consistant with that. Moving the mouse down increases pitch. Moving the mouse right, rather than left, should increase yaw since the x axis is at +90 degrees from the z axis, not -90 degrees, i.e. angles are measured clockwise, not counter-clockwise.

Oh, perhaps worth mentioning. That is what I believe your pitch and yaw is doing rather than what I believe pitch and yaw should do. By convention pitch should be your angle with the horizontal plane, not the vertical axis. Yaw is a little less well defined. It is your angle with the forward axis, but that doesn't say whether the forward axis is the x or z axis. I'm also not sure what is normally considered a positive yaw, i.e. turning left or turning right. Seems like it would most likely be right for basically the same reason clocks run clockwise. You can do that by switching axes or switching your interface to add when you go left and subtract when you go right.

[edited by - LilBudyWizer on February 25, 2003 2:02:26 AM]
Keys to success: Ability, ambition and opportunity.

Topic Locked

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

Sign in to reply to this topic.