|
From: <axl...@us...> - 2009-05-31 01:24:43
|
Revision: 283
http://hgengine.svn.sourceforge.net/hgengine/?rev=283&view=rev
Author: axlecrusher
Date: 2009-05-31 01:24:34 +0000 (Sun, 31 May 2009)
Log Message:
-----------
eliminate MQuaternion [] operator confusion
Modified Paths:
--------------
Mercury2/src/Camera.cpp
Mercury2/src/MQuaternion.cpp
Mercury2/src/MQuaternion.h
Mercury2/src/TransformNode.cpp
Mercury2/src/TransformNode.h
Modified: Mercury2/src/Camera.cpp
===================================================================
--- Mercury2/src/Camera.cpp 2009-05-31 00:54:15 UTC (rev 282)
+++ Mercury2/src/Camera.cpp 2009-05-31 01:24:34 UTC (rev 283)
@@ -18,12 +18,11 @@
MercuryMatrix local;
- m_lookAt = m_rotation * MQuaternion(0,0,0,1) * m_rotation.reciprocal();
-// m_lookAt.
- m_lookAt.ToVertex().Print();
+ m_lookAt = GetRotation() * MQuaternion(1, MercuryVector(0,0,1) ) * GetRotation().reciprocal();
+ m_lookAt.Print();
- AngleMatrix( m_rotation.ToVertex()*-1, local);
- local.Translate( m_position*-1 );
+ AngleMatrix( GetRotation().ToVertex()*-1, local);
+ local.Translate( GetPosition()*-1 );
m_globalMatrix = GetParentMatrix() * local;
}
@@ -37,9 +36,9 @@
// MercuryVertex r;
// MQuaternion rot, d(0,0,1,0);
- MQuaternion r = m_rotation;
- r[0] += m->dy/30.0f;
- r[1] += m->dx/30.0f;
+ MQuaternion r = GetRotation();
+ r[MQuaternion::X] += m->dy/30.0f;
+ r[MQuaternion::Y] += m->dx/30.0f;
// r = r.normalize();
// r = r * m_lookAt * r.reciprocal();
@@ -54,16 +53,16 @@
}
if (message == INPUTEVENT_KEYBOARD)
{
- MQuaternion r = m_rotation;
+ MQuaternion r = GetRotation();
KeyboardInput* k = (KeyboardInput*)data;
switch(k->key)
{
case 25:
- r[0] += 1*k->isDown;
+ r[MQuaternion::X] += 1;
break;
case 39:
- r[0] -= 1*k->isDown;
+ r[MQuaternion::X] -= 1;
break;
}
SetRotation(r);
Modified: Mercury2/src/MQuaternion.cpp
===================================================================
--- Mercury2/src/MQuaternion.cpp 2009-05-31 00:54:15 UTC (rev 282)
+++ Mercury2/src/MQuaternion.cpp 2009-05-31 01:24:34 UTC (rev 283)
@@ -3,7 +3,7 @@
MQuaternion::MQuaternion()
{
- m_wxyz[0] = 0;
+ m_wxyz[0] = 1;
m_wxyz[1] = 0;
m_wxyz[2] = 0;
m_wxyz[3] = 0;
@@ -25,7 +25,7 @@
m_wxyz[3] = p[2];
}
-float & MQuaternion::operator [] (int i)
+float & MQuaternion::operator [] (WXYZ i)
{
return m_wxyz[i]; //haha we won't even get here.
}
@@ -221,6 +221,10 @@
return v;
}
+void MQuaternion::Print(const MString& s) const
+{
+ printf("%s: %f %f %f %f\n", s.c_str(), m_wxyz[0], m_wxyz[1], m_wxyz[2], m_wxyz[3]);
+}
//Returns the Euclidian Inner Product of two MQuaternions (Similar to Vector Dot-Product)
Modified: Mercury2/src/MQuaternion.h
===================================================================
--- Mercury2/src/MQuaternion.h 2009-05-31 00:54:15 UTC (rev 282)
+++ Mercury2/src/MQuaternion.h 2009-05-31 01:24:34 UTC (rev 283)
@@ -7,6 +7,8 @@
///Mathematical Quaternion (Used for Rotation)
class MQuaternion {
public:
+ enum WXYZ { W = 0, X, Y, Z };
+
//Defines a Quaternion such that q = w + xi + yj + zk
MQuaternion();
MQuaternion(float W, float X, float Y, float Z);
@@ -19,9 +21,9 @@
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;
-
+ float & operator[] ( const WXYZ rhs );
+ const float & operator[] ( const WXYZ rhs ) const;
+
///Returns the magnitude
float magnitude() const;
///Returns the normalized Quaternion
@@ -58,7 +60,9 @@
bool operator==(const MQuaternion &rhs) const;
inline bool operator!=(const MQuaternion &rhs) const { return !(*this == rhs); }
-
+
+ void Print(const MString& s = "MQuaternion") const;
+
// private:
FloatRow m_wxyz;
} M_ALIGN(32);
Modified: Mercury2/src/TransformNode.cpp
===================================================================
--- Mercury2/src/TransformNode.cpp 2009-05-31 00:54:15 UTC (rev 282)
+++ Mercury2/src/TransformNode.cpp 2009-05-31 01:24:34 UTC (rev 283)
@@ -4,7 +4,7 @@
REGISTER_NODE_TYPE(RotatorNode);
TransformNode::TransformNode()
- :m_scale( MercuryVertex(1,1,1) )
+ :m_scale( MercuryVertex(1,1,1) ), m_rotation(1,0,0,0)
{
SetTaint( true ); //taint because of the scale set above
}
@@ -55,7 +55,7 @@
// local.Identity();
local.Transotale( m_position[0], m_position[1], m_position[2],
- m_rotation[0], m_rotation[1], m_rotation[2],
+ m_rotation[MQuaternion::X], m_rotation[MQuaternion::Y], m_rotation[MQuaternion::Z],
m_scale[0], m_scale[1], m_scale[2] );
m_globalMatrix = GetParentMatrix() * local;
@@ -98,13 +98,13 @@
//only change the values that exist in the XML
if ( !node.Attribute("rotx").empty() )
- rot[0] = StrToFloat( node.Attribute("rotx") );
+ rot[MQuaternion::X] = StrToFloat( node.Attribute("rotx") );
if ( !node.Attribute("roty").empty() )
- rot[1] = StrToFloat( node.Attribute("roty") );
+ rot[MQuaternion::Y] = StrToFloat( node.Attribute("roty") );
if ( !node.Attribute("rotz").empty() )
- rot[2] = StrToFloat( node.Attribute("rotz") );
+ rot[MQuaternion::Z] = StrToFloat( node.Attribute("rotz") );
if ( !node.Attribute("scalex").empty() )
scale.SetX( StrToFloat( node.Attribute("scalex") ) );
@@ -150,9 +150,9 @@
void RotatorNode::Update(float dTime)
{
- MQuaternion r = m_rotation;
- r[0] += (dTime)*25;
- r[1] += (dTime)*75;
+ MQuaternion r = GetRotation();
+ r[MQuaternion::X] += (dTime)*25;
+ r[MQuaternion::Y] += (dTime)*75;
SetRotation( r );
Modified: Mercury2/src/TransformNode.h
===================================================================
--- Mercury2/src/TransformNode.h 2009-05-31 00:54:15 UTC (rev 282)
+++ Mercury2/src/TransformNode.h 2009-05-31 01:24:34 UTC (rev 283)
@@ -39,12 +39,13 @@
private:
void RippleTaintDown();
-// MercuryMatrix m_localMatrix;
- protected:
+ //use of accessor required
MercuryVertex m_scale;
MercuryVertex m_position;
-// MercuryVertex m_rotation;
MQuaternion m_rotation;
+
+// MercuryMatrix m_localMatrix;
+ protected:
MercuryMatrix m_globalMatrix;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|