Get euler angles from vector?

Started by
2 comments, last by Jernej.L 18 years, 8 months ago
Hi, I was wondering if anyone knew how to figure out the euler angles required to rotate a vector to it's current position. In other words, take a vector and return its euler angles? Thanks. [Edited by - honayboyz on August 17, 2005 2:25:50 PM]
Advertisement
Probably the easiest way to get the Euler angles from building blocks is to take a quaternion that represents the cross product between the previous and current position and then decompose that quaternion into Euler angles. Most quaternion libraries oriented for use in games should have the primitives necessary to do these operations.
I use this code - ok if you don't need the roll...
(note: angles are in OpenGL-speak)

// Converts a 3d vector into heading and pitch (roll is indeterminate).void NUtils::HdgPitchFromVector3(const TVector3& aDirn, float& aHdg, float& aPitch){	_ASSERT(aDirn.IsNormalised());	aHdg   = -float(RADTODEG * atan2(aDirn.x, -aDirn.z));	aPitch = float(RADTODEG * atan2(aDirn.y, sqrt((aDirn.x*aDirn.x) + (aDirn.z*aDirn.z))));	WrapAngle360(aHdg);}
you can do this by calculating the opposite of sin and cos.

x of a vector is sin of some angle.. and cos is Y of that angle..

Projects: Top Down City: http://mathpudding.com/

This topic is closed to new replies.

Advertisement