From: Josh <axl...@gm...> - 2009-10-27 10:27:28
|
Euler is a poor choice for this since it doesn't always mathematically work and can Gimbel lock. Why not just save the quaternion values without any conversions? Josh cn...@us... wrote: > Revision: 590 > http://hgengine.svn.sourceforge.net/hgengine/?rev=590&view=rev > Author: cnlohr > Date: 2009-10-27 04:48:57 +0000 (Tue, 27 Oct 2009) > > Log Message: > ----------- > add to euler (useful for saving) it hasn't actually been tested yet... > > Modified Paths: > -------------- > Mercury2/src/MQuaternion.cpp > Mercury2/src/MQuaternion.h > > Modified: Mercury2/src/MQuaternion.cpp > =================================================================== > --- Mercury2/src/MQuaternion.cpp 2009-10-27 03:18:28 UTC (rev 589) > +++ Mercury2/src/MQuaternion.cpp 2009-10-27 04:48:57 UTC (rev 590) > @@ -52,6 +52,14 @@ > *this = this->normalize(); > } > > +void MQuaternion::ToEuler(MercuryVertex&angles) const > +{ > + //According to http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles (Oct 26, 2009) > + angles[0] = atan2( 2 * (m_wxyz[0]*m_wxyz[1] + m_wxyz[2]*m_wxyz[3]), 1 - 2 * (m_wxyz[1]*m_wxyz[1] + m_wxyz[2]*m_wxyz[2] ) ); > + angles[1] = asin( 2 * (m_wxyz[0] *m_wxyz[2] - m_wxyz[3]*m_wxyz[1] ) ); > + angles[2] = atan2( 2 * (m_wxyz[0]*m_wxyz[3] + m_wxyz[1]*m_wxyz[2]), 1 - 2 * (m_wxyz[2]*m_wxyz[2] + m_wxyz[3]*m_wxyz[3] ) ); > +} > + > MQuaternion MQuaternion::CreateFromAxisAngle(const MercuryVertex& p, const float radians) > { > MQuaternion q; > > Modified: Mercury2/src/MQuaternion.h > =================================================================== > --- Mercury2/src/MQuaternion.h 2009-10-27 03:18:28 UTC (rev 589) > +++ Mercury2/src/MQuaternion.h 2009-10-27 04:48:57 UTC (rev 590) > @@ -23,6 +23,9 @@ > static MQuaternion CreateFromAxisAngle(const MercuryVertex& p, const float radians); > void FromAxisAngle(const MercuryVertex& p, const float radians); > void ToAxisAngle(float& angle, float& x, float& y, float& z) const; > + > + //Convert the quaternion back into euler angles (mathematically doesn't always work) > + void ToEuler(MercuryVertex&angles) const; > > ///Access a component of the quaternion with the [] operator > inline float & operator[] ( const WXYZ i ) { return m_wxyz[i]; } > > > This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > http://p.sf.net/sfu/devconference > _______________________________________________ > Hgengine-cvs mailing list > Hge...@li... > https://lists.sourceforge.net/lists/listinfo/hgengine-cvs > |