|
From: <cn...@us...> - 2009-10-27 04:49:07
|
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.
|