|
From: <axl...@us...> - 2009-05-22 01:29:05
|
Revision: 271
http://hgengine.svn.sourceforge.net/hgengine/?rev=271&view=rev
Author: axlecrusher
Date: 2009-05-22 01:28:54 +0000 (Fri, 22 May 2009)
Log Message:
-----------
quaternion
Modified Paths:
--------------
Mercury2/src/Camera.cpp
Mercury2/src/TransformNode.cpp
Mercury2/src/TransformNode.h
Added Paths:
-----------
Mercury2/src/MQuaternion.cpp
Mercury2/src/MQuaternion.h
Modified: Mercury2/src/Camera.cpp
===================================================================
--- Mercury2/src/Camera.cpp 2009-05-19 00:21:56 UTC (rev 270)
+++ Mercury2/src/Camera.cpp 2009-05-22 01:28:54 UTC (rev 271)
@@ -16,7 +16,9 @@
MercuryMatrix local;
- local.RotateXYZ( m_rotation*-1 );
+// local.RotateXYZ( m_rotation*-1 );
+// m_rotation.
+ AngleMatrix( m_rotation.ToVertex()*-1, local);
local.Translate( m_position*-1 );
m_globalMatrix = GetParentMatrix() * local;
@@ -28,7 +30,7 @@
{
MouseInput* m = (MouseInput*)data;
- MercuryVector r = m_rotation;
+ MQuaternion r = m_rotation;
r[0] += m->dy/30.0f;
r[1] += m->dx/30.0f;
Added: Mercury2/src/MQuaternion.cpp
===================================================================
--- Mercury2/src/MQuaternion.cpp (rev 0)
+++ Mercury2/src/MQuaternion.cpp 2009-05-22 01:28:54 UTC (rev 271)
@@ -0,0 +1,360 @@
+#include <MQuaternion.h>
+#include <MercuryMath.h>
+
+MQuaternion::MQuaternion(float W, float X, float Y, float Z)
+{
+ m_xyzw[3] = X;
+ m_xyzw[0] = Y;
+ m_xyzw[1] = Z;
+ m_xyzw[2] = W;
+}
+
+MQuaternion::MQuaternion(float* xyzw)
+{
+ for (uint8_t i = 0; i < 4; ++i)
+ m_xyzw[i] = xyzw[i];
+}
+
+MQuaternion::MQuaternion(const MercuryVertex& p)
+{
+ m_xyzw[0] = p.GetX();
+ m_xyzw[1] = p.GetY();
+ m_xyzw[2] = p.GetZ();
+ m_xyzw[3] = 0;
+}
+
+float & MQuaternion::operator [] (int i)
+{
+ switch (i)
+ {
+ case 0: return m_xyzw[0];
+ case 1: return m_xyzw[1];
+ case 2: return m_xyzw[2];
+ case 3: return m_xyzw[3];
+ }
+ return m_xyzw[0]; //haha we won't even get here.
+}
+
+void MQuaternion::SetEuler(const MercuryVector& angles)
+{
+ float X = angles[0]/2.0f; //roll
+ float Y = angles[1]/2.0f; //pitch
+ float Z = angles[2]/2.0f; //yaw
+
+ float cx = COS(X);
+ float sx = SIN(X);
+ float cy = COS(Y);
+ float sy = SIN(Y);
+ float cz = COS(Z);
+ float sz = SIN(Z);
+
+ //Correct according to
+ //http://en.wikipedia.org/wiki/Conversion_between_MQuaternions_and_Euler_angles
+ m_xyzw[3] = cx*cy*cz+sx*sy*sz;//q1
+ m_xyzw[0] = sx*cy*cz-cx*sy*sz;//q2
+ m_xyzw[1] = cx*sy*cz+sx*cy*sz;//q3
+ m_xyzw[2] = cx*cy*sz-sx*sy*cz;//q4
+}
+
+void MQuaternion::CreateFromAxisAngle(const MercuryVector& p, const float radians)
+{
+ float sn = SIN(radians/2.0f);
+ m_xyzw[3] = COS(radians/2.0f);
+ m_xyzw[0] = sn * p.m_xyzw[0];
+ m_xyzw[1] = sn * p.m_xyzw[1];
+ m_xyzw[2] = sn * p.m_xyzw[2];
+}
+
+//Returns the magnitude
+float MQuaternion::magnitude() const {
+ return SQRT((m_xyzw[3]*m_xyzw[3])+(m_xyzw[0]*m_xyzw[0])+(m_xyzw[1]*m_xyzw[1])+(m_xyzw[2]*m_xyzw[2]));
+}
+
+//Returns the normalized MQuaternion
+MQuaternion MQuaternion::normalize() const {
+ return (*this)/magnitude();
+}
+
+//Returns the conjugate MQuaternion
+MQuaternion MQuaternion::conjugate() const {
+ MQuaternion c(m_xyzw[3],-m_xyzw[0],-m_xyzw[1],-m_xyzw[2]);
+ return c;
+}
+
+//Returns the reciprocal MQuaternion
+MQuaternion MQuaternion::reciprocal() const {
+ float m = magnitude();
+ return conjugate()/(m*m);
+}
+
+//Rotate MQuaternion about another MQuaternion
+MQuaternion MQuaternion::rotateAbout(const MQuaternion &spinAxis) const {
+ return (*this)*spinAxis;
+}
+
+//Converts MQuaternion to 4x4 Matrix(3x3 Spatial)
+void MQuaternion::toMatrix( MercuryMatrix &matrix ) const {
+ float X = 2*m_xyzw[0]*m_xyzw[0]; //Reduced calulation for speed
+ float Y = 2*m_xyzw[1]*m_xyzw[1];
+ float Z = 2*m_xyzw[2]*m_xyzw[2];
+ float a = 2*m_xyzw[3]*m_xyzw[0];
+ float b = 2*m_xyzw[3]*m_xyzw[1];
+ float c = 2*m_xyzw[3]*m_xyzw[2];
+ float d = 2*m_xyzw[0]*m_xyzw[1];
+ float e = 2*m_xyzw[0]*m_xyzw[2];
+ float f = 2*m_xyzw[1]*m_xyzw[2];
+
+ //row major
+ matrix[0][0] = 1-Y-Z;
+ matrix[0][1] = d-c;
+ matrix[0][2] = e+b;
+
+ matrix[1][0] = d+c;
+ matrix[1][1] = 1-X-Z;
+ matrix[1][2] = f-a;
+
+ matrix[2][0] = e-b;
+ matrix[2][1] = f+a;
+ matrix[2][2] = 1-X-Y;
+}
+
+void MQuaternion::toMatrix4( MercuryMatrix &matrix ) const {
+ toMatrix( matrix );
+
+ //row major (even though it looks like column)
+ matrix[0][3] = 0;
+ matrix[1][3] = 0;
+ matrix[2][3] = 0;
+ matrix[3][3] = 1;
+
+ matrix[3][0] = 0;
+ matrix[3][1] = 0;
+ matrix[3][2] = 0;
+}
+
+MQuaternion MQuaternion::operator + (const MQuaternion &rhs) const
+{
+ MQuaternion result;
+ result.m_xyzw[3] = m_xyzw[3] + rhs.m_xyzw[3];
+ result.m_xyzw[0] = m_xyzw[0] + rhs.m_xyzw[0];
+ result.m_xyzw[1] = m_xyzw[1] + rhs.m_xyzw[1];
+ result.m_xyzw[2] = m_xyzw[2] + rhs.m_xyzw[2];
+ return result;
+}
+
+MQuaternion MQuaternion::operator - (const MQuaternion &rhs) const
+{
+ MQuaternion result;
+ result.m_xyzw[3] = m_xyzw[3] - rhs.m_xyzw[3];
+ result.m_xyzw[0] = m_xyzw[0] - rhs.m_xyzw[0];
+ result.m_xyzw[1] = m_xyzw[1] - rhs.m_xyzw[1];
+ result.m_xyzw[2] = m_xyzw[2] - rhs.m_xyzw[2];
+ return result;
+}
+
+MQuaternion MQuaternion::operator * (const MQuaternion &rhs) const
+{
+ MQuaternion result;
+ result.m_xyzw[3] = (m_xyzw[3]*rhs.m_xyzw[3])-(m_xyzw[0]*rhs.m_xyzw[0])-(m_xyzw[1]*rhs.m_xyzw[1])-(m_xyzw[2]*rhs.m_xyzw[2]);
+ result.m_xyzw[0] = (m_xyzw[3]*rhs.m_xyzw[0])+(m_xyzw[0]*rhs.m_xyzw[3])+(m_xyzw[1]*rhs.m_xyzw[2])-(m_xyzw[2]*rhs.m_xyzw[1]);
+ result.m_xyzw[1] = (m_xyzw[3]*rhs.m_xyzw[1])-(m_xyzw[0]*rhs.m_xyzw[2])+(m_xyzw[1]*rhs.m_xyzw[3])+(m_xyzw[2]*rhs.m_xyzw[0]);
+ result.m_xyzw[2] = (m_xyzw[3]*rhs.m_xyzw[2])+(m_xyzw[0]*rhs.m_xyzw[1])-(m_xyzw[1]*rhs.m_xyzw[0])+(m_xyzw[2]*rhs.m_xyzw[3]);
+ return result;
+}
+
+MQuaternion& MQuaternion::operator = (const MQuaternion &rhs)
+{
+ m_xyzw[3] = rhs.m_xyzw[3];
+ m_xyzw[0] = rhs.m_xyzw[0];
+ m_xyzw[1] = rhs.m_xyzw[1];
+ m_xyzw[2] = rhs.m_xyzw[2];
+ return (*this);
+}
+
+MQuaternion& MQuaternion::operator += (const MQuaternion &rhs) {
+ m_xyzw[3] += rhs.m_xyzw[3];
+ m_xyzw[0] += rhs.m_xyzw[0];
+ m_xyzw[1] += rhs.m_xyzw[1];
+ m_xyzw[2] += rhs.m_xyzw[2];
+ return (*this);
+}
+
+MQuaternion& MQuaternion::operator -= (const MQuaternion &rhs) {
+ m_xyzw[3] -= rhs.m_xyzw[3];
+ m_xyzw[0] -= rhs.m_xyzw[0];
+ m_xyzw[1] -= rhs.m_xyzw[1];
+ m_xyzw[2] -= rhs.m_xyzw[2];
+ return (*this);
+}
+
+MQuaternion& MQuaternion::operator *= (const MQuaternion &rhs) {
+ m_xyzw[3] = (m_xyzw[3]*rhs.m_xyzw[3])-(m_xyzw[0]*rhs.m_xyzw[0])-(m_xyzw[1]*rhs.m_xyzw[1])-(m_xyzw[2]*rhs.m_xyzw[2]);
+ m_xyzw[0] = (m_xyzw[3]*rhs.m_xyzw[0])+(m_xyzw[0]*rhs.m_xyzw[3])+(m_xyzw[1]*rhs.m_xyzw[2])-(m_xyzw[2]*rhs.m_xyzw[1]);
+ m_xyzw[1] = (m_xyzw[3]*rhs.m_xyzw[1])-(m_xyzw[0]*rhs.m_xyzw[2])+(m_xyzw[1]*rhs.m_xyzw[3])+(m_xyzw[2]*rhs.m_xyzw[0]);
+ m_xyzw[2] = (m_xyzw[3]*rhs.m_xyzw[2])+(m_xyzw[0]*rhs.m_xyzw[1])-(m_xyzw[1]*rhs.m_xyzw[0])+(m_xyzw[2]*rhs.m_xyzw[3]);
+ return (*this);
+}
+
+MQuaternion MQuaternion::operator * (const float &rhs) const {
+ MQuaternion result;
+ result.m_xyzw[3] = m_xyzw[3]*rhs;
+ result.m_xyzw[0] = m_xyzw[0]*rhs;
+ result.m_xyzw[1] = m_xyzw[1]*rhs;
+ result.m_xyzw[2] = m_xyzw[2]*rhs;
+ return result;
+}
+
+MQuaternion MQuaternion::operator / (const float &rhs) const {
+ MQuaternion result;
+ result.m_xyzw[3] = m_xyzw[3]/rhs;
+ result.m_xyzw[0] = m_xyzw[0]/rhs;
+ result.m_xyzw[1] = m_xyzw[1]/rhs;
+ result.m_xyzw[2] = m_xyzw[2]/rhs;
+ return result;
+}
+
+MQuaternion& MQuaternion::operator *= (const float &rhs) {
+ m_xyzw[3] *= rhs;
+ m_xyzw[0] *= rhs;
+ m_xyzw[1] *= rhs;
+ m_xyzw[2] *= rhs;
+ return (*this);
+}
+
+MQuaternion& MQuaternion::operator /= (const float &rhs) {
+ m_xyzw[3] /= rhs;
+ m_xyzw[0] /= rhs;
+ m_xyzw[1] /= rhs;
+ m_xyzw[2] /= rhs;
+ return (*this);
+}
+
+//Returns the Euclidian Inner Product of two MQuaternions (Similar to Vector Dot-Product)
+float innerProduct(const MQuaternion & a, const MQuaternion &b)
+{
+ return (a.m_xyzw[3]*b.m_xyzw[3])+(a.m_xyzw[0]*b.m_xyzw[0])+(a.m_xyzw[1]*b.m_xyzw[1])+(a.m_xyzw[2]*b.m_xyzw[2]);
+}
+
+//Returns the Euclidian Outer Product of two MQuaternions
+MercuryVector outerProduct(MQuaternion a,MQuaternion b)
+{
+ MercuryVector result;
+ result.m_xyzw[0] = (a.m_xyzw[3]*b.m_xyzw[0])-(a.m_xyzw[0]*b.m_xyzw[3])-(a.m_xyzw[1]*b.m_xyzw[2])+(a.m_xyzw[2]*b.m_xyzw[1]);
+ result.m_xyzw[1] = (a.m_xyzw[3]*b.m_xyzw[1])+(a.m_xyzw[0]*b.m_xyzw[2])-(a.m_xyzw[1]*b.m_xyzw[3])-(a.m_xyzw[2]*b.m_xyzw[0]);
+ result.m_xyzw[2] = (a.m_xyzw[3]*b.m_xyzw[2])-(a.m_xyzw[0]*b.m_xyzw[1])+(a.m_xyzw[1]*b.m_xyzw[0])-(a.m_xyzw[2]*b.m_xyzw[3]);
+ return result;
+}
+
+//Returns the Even Product of two MQuaternions
+MQuaternion evenProduct(MQuaternion a,MQuaternion b) {
+ MQuaternion result;
+ result.m_xyzw[3] = (a.m_xyzw[3]*b.m_xyzw[3])-(a.m_xyzw[0]*b.m_xyzw[0])-(a.m_xyzw[1]*b.m_xyzw[1])-(a.m_xyzw[2]*b.m_xyzw[2]);
+ result.m_xyzw[0] = (a.m_xyzw[3]*b.m_xyzw[0])+(a.m_xyzw[0]*b.m_xyzw[3]);
+ result.m_xyzw[1] = (a.m_xyzw[3]*b.m_xyzw[1])+(a.m_xyzw[1]*b.m_xyzw[3]);
+ result.m_xyzw[2] = (a.m_xyzw[3]*b.m_xyzw[2])+(a.m_xyzw[2]*b.m_xyzw[3]);
+ return result;
+}
+
+//Returns the Odd Product of two MQuaternions (Similar to Vector Cross-Product)
+MercuryVector oddProduct(MQuaternion a,MQuaternion b) {
+ MercuryVector result;
+ result.m_xyzw[0] = (a.m_xyzw[1]*b.m_xyzw[2])-(a.m_xyzw[2]*b.m_xyzw[1]);
+ result.m_xyzw[1] = (a.m_xyzw[2]*b.m_xyzw[0])-(a.m_xyzw[0]*b.m_xyzw[2]);
+ result.m_xyzw[2] = (a.m_xyzw[0]*b.m_xyzw[1])-(a.m_xyzw[1]*b.m_xyzw[0]);
+ return result;
+}
+
+//Spherical Linear Interpolation between two MQuaternions at t percent completion(0-1)
+MQuaternion SLERP( const MQuaternion &a, const MQuaternion &b,float t) {
+ MQuaternion an = a.normalize(), bn = b.normalize();
+ float cosTheta = innerProduct(MQuaternion(an),bn);
+ float sinTheta;
+
+ //Careful: If cosTheta is exactly one, or even if it's infinitesimally over, it'll
+ // cause SQRT to produce not a number, and screw everything up.
+ if ( 1 - (cosTheta*cosTheta) <= 0 )
+ sinTheta = 0;
+ else
+ sinTheta = SQRT(1 - (cosTheta*cosTheta));
+
+ float Theta = ACOS(cosTheta); //Theta is half the angle between the 2 MQuaternions
+
+ if(fabs(Theta) < 0.01)
+ return a;
+ if(fabs(sinTheta) < 0.01)
+ return (a+b)/2;
+ return ( (a*SIN((1-t)*Theta)) + (b*SIN(t*Theta)) ) / sinTheta;
+}
+
+bool MQuaternion::operator==(const MQuaternion& p) const
+{
+ for (unsigned int i = 0; i < 4; ++i)
+ if (m_xyzw[i] != p.m_xyzw[i]) return false;
+ return true;
+}
+
+void AngleMatrix (const MercuryVector & angles, MercuryMatrix & matrix )
+{
+ float X = angles[0]*2*Q_PI/360; //Reduced calulation for speed
+ float Y = angles[1]*2*Q_PI/360;
+ float Z = angles[2]*2*Q_PI/360;
+ float cx = COS(X);
+ float sx = SIN(X);
+ float cy = COS(Y);
+ float sy = SIN(Y);
+ float cz = COS(Z);
+ float sz = SIN(Z);
+
+ //Row major
+ matrix[0][0] = cy*cz;
+ matrix[0][1] = (sx*sy*cz)-(cx*sz);
+ matrix[0][2] = (cx*sy*cz)+(sx*sz);
+ matrix[0][3] = 0;
+
+ matrix[1][0] = cy*sz;
+ matrix[1][1] = (sx*sy*sz)+(cx*cz);
+ matrix[1][2] = (cx*sy*sz)-(sx*cz);
+ matrix[1][3] = 0;
+
+ matrix[2][0] = -sy;
+ matrix[2][1] = sx*cy;
+ matrix[2][2] = cx*cy;
+ matrix[2][3] = 0;
+
+ matrix[3][0] = 0;
+ matrix[3][1] = 0;
+ matrix[3][2] = 0;
+ matrix[3][3] = 1;
+}
+
+/****************************************************************************
+ * Copyright (C) 2009 by Joshua Allen, Charles Lohr, Adam Lowman *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
Added: Mercury2/src/MQuaternion.h
===================================================================
--- Mercury2/src/MQuaternion.h (rev 0)
+++ Mercury2/src/MQuaternion.h 2009-05-22 01:28:54 UTC (rev 271)
@@ -0,0 +1,100 @@
+#ifndef MQUATERNION_H
+#define MQUATERNION_H
+
+#include <MercuryVertex.h>
+#include <MercuryMatrix.h>
+
+///Mathematical Quaternion (Used for Rotation)
+class MQuaternion {
+ public:
+ //Defines a Quaternion such that q = w + xi + yj + zk
+ float m_xyzw[4];
+ MQuaternion(float W = 0, float X = 0, float Y = 0, float Z = 0);
+ MQuaternion(float* wxyz);
+ MQuaternion(const MercuryVertex& p);
+
+ ///Make this quaternion represent to a set of euler angles
+ void SetEuler(const MercuryVertex& angles);
+
+ ///Make the quaternion represent a given angle radians around an axis p
+ void CreateFromAxisAngle(const MercuryVertex& p, const float radians);
+
+ ///Access a component of the quaternion with the [] operator
+ float & operator[] ( const int rhs );
+ const float & operator[] ( const int rhs ) const;
+
+ ///Returns the magnitude
+ float magnitude() const;
+ ///Returns the normalized Quaternion
+ MQuaternion normalize() const;
+ ///Returns the conjugate Quaternion
+ MQuaternion conjugate() const;
+ ///Returns the reciprocal Quaternion
+ MQuaternion reciprocal() const;
+ ///Rotates Quaternion about another Quaternion
+ MQuaternion rotateAbout(const MQuaternion &spinAxis) const;
+ ///Converts Quaternion to 4x4 Matrix(3x3 Spatial)
+ void toMatrix( MercuryMatrix & mat ) const;
+ ///Converts Quaternion to complete 4x4 Matrix
+ void toMatrix4( MercuryMatrix & mat ) const;
+ ///Convert the quaternion to a point.
+ MercuryVertex ToVertex() { return MercuryVertex( m_xyzw[0],m_xyzw[1],m_xyzw[2] ); }
+
+ /******************************************************
+ * NOTE: Quaternion multipication is not commutative *
+ * Therefore the / operator could imply for a/b *
+ * a*b.reciprocal() or b.reciprocal()*a *
+ ******************************************************/
+ MQuaternion operator + (const MQuaternion &rhs) const;
+ MQuaternion operator - (const MQuaternion &rhs) const;
+ MQuaternion operator * (const MQuaternion &rhs) const;
+ MQuaternion& operator = (const MQuaternion &rhs);
+ MQuaternion& operator += (const MQuaternion &rhs);
+ MQuaternion& operator -= (const MQuaternion &rhs);
+ MQuaternion& operator *= (const MQuaternion &rhs);
+ MQuaternion operator * (const float &rhs) const;
+ MQuaternion operator / (const float &rhs) const;
+ MQuaternion& operator *= (const float &rhs);
+ MQuaternion& operator /= (const float &rhs);
+
+ bool operator==(const MQuaternion& p) const;
+ inline bool operator!=(const MQuaternion& p) const { return !(*this == p); }
+
+} M_ALIGN(32);
+
+///Produce a matrix out of a rotation x, then y then z (how Mercury does it)
+void AngleMatrix (const MercuryVector & angles, MercuryMatrix & mat );
+
+#endif
+
+/****************************************************************************
+ * Copyright (C) 2009 by Joshua Allen, Charles Lohr, Adam Lowman *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
Modified: Mercury2/src/TransformNode.cpp
===================================================================
--- Mercury2/src/TransformNode.cpp 2009-05-19 00:21:56 UTC (rev 270)
+++ Mercury2/src/TransformNode.cpp 2009-05-22 01:28:54 UTC (rev 271)
@@ -32,7 +32,7 @@
}
}
-void TransformNode::SetRotation( const MercuryVertex& rotation )
+void TransformNode::SetRotation( const MQuaternion& rotation )
{
if (rotation != m_rotation)
{
@@ -94,17 +94,18 @@
void TransformNode::LoadFromXML(const XMLNode& node)
{
- MercuryVertex rot(m_rotation), pos(m_position), scale(m_scale);
+ MercuryVertex pos(m_position), scale(m_scale);
+ MQuaternion rot(m_rotation);
//only change the values that exist in the XML
if ( !node.Attribute("rotx").empty() )
- rot.SetX( StrToFloat( node.Attribute("rotx") ) );
+ rot[0] = StrToFloat( node.Attribute("rotx") );
if ( !node.Attribute("roty").empty() )
- rot.SetY( StrToFloat( node.Attribute("roty") ) );
+ rot[1] = StrToFloat( node.Attribute("roty") );
if ( !node.Attribute("rotz").empty() )
- rot.SetZ( StrToFloat( node.Attribute("rotz") ) );
+ rot[2] = StrToFloat( node.Attribute("rotz") );
if ( !node.Attribute("scalex").empty() )
scale.SetX( StrToFloat( node.Attribute("scalex") ) );
@@ -150,7 +151,7 @@
void RotatorNode::Update(float dTime)
{
- float* r = m_rotation;
+ MQuaternion r = m_rotation;
r[0] += (dTime)*25;
r[1] += (dTime)*75;
Modified: Mercury2/src/TransformNode.h
===================================================================
--- Mercury2/src/TransformNode.h 2009-05-19 00:21:56 UTC (rev 270)
+++ Mercury2/src/TransformNode.h 2009-05-22 01:28:54 UTC (rev 271)
@@ -4,6 +4,7 @@
#include <MercuryNode.h>
#include <MercuryVertex.h>
#include <MercuryMatrix.h>
+#include <MQuaternion.h>
//I am not sure if I like the idea of rippling a taint flag down the tree
//if a transform hs changed. There is probably a better way of doing this.
@@ -16,11 +17,11 @@
void SetScale( const MercuryVertex& scale );
void SetPosition( const MercuryVertex& position );
- void SetRotation( const MercuryVertex& rotation );
+ void SetRotation( const MQuaternion& rotation );
inline const MercuryVertex& GetScale() const { return m_scale; }
inline const MercuryVertex& GetPosition() const { return m_position; }
- inline const MercuryVertex& GetRotation() const { return m_rotation; }
+ inline const MQuaternion& GetRotation() const { return m_rotation; }
inline const MercuryMatrix& GetGlobalMatrix() const { return m_globalMatrix; }
const MercuryMatrix& GetParentMatrix() const;
@@ -42,7 +43,8 @@
protected:
MercuryVertex m_scale;
MercuryVertex m_position;
- MercuryVertex m_rotation;
+// MercuryVertex m_rotation;
+ MQuaternion m_rotation;
MercuryMatrix m_globalMatrix;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|