You can subscribe to this list here.
| 2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(46) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2006 |
Jan
(185) |
Feb
(242) |
Mar
(237) |
Apr
(180) |
May
(102) |
Jun
(278) |
Jul
(114) |
Aug
(92) |
Sep
(246) |
Oct
(212) |
Nov
(279) |
Dec
(99) |
| 2007 |
Jan
(130) |
Feb
(194) |
Mar
(22) |
Apr
(72) |
May
(40) |
Jun
(111) |
Jul
(114) |
Aug
(154) |
Sep
(114) |
Oct
(2) |
Nov
(1) |
Dec
(5) |
| 2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(6) |
Oct
(51) |
Nov
(34) |
Dec
(130) |
| 2009 |
Jan
(22) |
Feb
(20) |
Mar
(41) |
Apr
(45) |
May
(82) |
Jun
(96) |
Jul
(48) |
Aug
(90) |
Sep
(13) |
Oct
(49) |
Nov
(31) |
Dec
(21) |
| 2010 |
Jan
(25) |
Feb
(9) |
Mar
(7) |
Apr
(28) |
May
(27) |
Jun
(7) |
Jul
(1) |
Aug
|
Sep
(1) |
Oct
(1) |
Nov
(13) |
Dec
(2) |
| 2013 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <axl...@us...> - 2009-05-31 15:53:45
|
Revision: 294
http://hgengine.svn.sourceforge.net/hgengine/?rev=294&view=rev
Author: axlecrusher
Date: 2009-05-31 15:53:44 +0000 (Sun, 31 May 2009)
Log Message:
-----------
updates
Modified Paths:
--------------
Mercury2/src/Camera.cpp
Modified: Mercury2/src/Camera.cpp
===================================================================
--- Mercury2/src/Camera.cpp 2009-05-31 14:26:36 UTC (rev 293)
+++ Mercury2/src/Camera.cpp 2009-05-31 15:53:44 UTC (rev 294)
@@ -1,6 +1,7 @@
#include <Camera.h>
#include <MercuryMessageManager.h>
#include <MercuryInput.h>
+#include <Viewport.h>
REGISTER_NODE_TYPE(CameraNode);
@@ -14,20 +15,29 @@
{
m_tainted = false;
- MercuryMatrix local;
+ MercuryMatrix local, parent(GetParentMatrix());
MQuaternion r( GetRotation().normalize() );
+ //compute the world space look vector (broken if camera is in transform node)
m_lookAt = MercuryVector(0,0,-1); //by default camera looks down world Z
m_lookAt = m_lookAt.Rotate( r );
m_lookAt.NormalizeSelf();
+ LOOKAT = m_lookAt;
r[MQuaternion::W] *= -1; //reverse angle for camera
+
+ //rotate then translate since we are a camera
r.toMatrix4( local );
-
local.Translate( GetPosition()*-1 );
- m_globalMatrix = GetParentMatrix() * local;
+ m_globalMatrix = local * parent; //fold in any parent transform in reverse (correct rotation)
+
+ //compute camera position in world space (broken if camera is in transform node)
+ local = MercuryMatrix::Identity();
+ local.Translate( GetPosition() );
+ EYE = (parent * local) * MercuryVertex(0,0,0,1);
+// EYE.Print();
}
void CameraNode::HandleMessage(const MString& message, const MessageData* data)
@@ -44,7 +54,6 @@
MQuaternion qx = MQuaternion::CreateFromAxisAngle(Xaxis, m_y);
MQuaternion qy = MQuaternion::CreateFromAxisAngle(MercuryVector(0,1,0), m_x);
-
SetRotation(qx * qy);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-05-31 14:26:37
|
Revision: 293
http://hgengine.svn.sourceforge.net/hgengine/?rev=293&view=rev
Author: axlecrusher
Date: 2009-05-31 14:26:36 +0000 (Sun, 31 May 2009)
Log Message:
-----------
quaternion has to be rebuilt each time to prevent unintended roll
Modified Paths:
--------------
Mercury2/src/Camera.cpp
Mercury2/src/Camera.h
Modified: Mercury2/src/Camera.cpp
===================================================================
--- Mercury2/src/Camera.cpp 2009-05-31 04:56:37 UTC (rev 292)
+++ Mercury2/src/Camera.cpp 2009-05-31 14:26:36 UTC (rev 293)
@@ -5,11 +5,9 @@
REGISTER_NODE_TYPE(CameraNode);
CameraNode::CameraNode()
- :TransformNode()
+ :TransformNode(), m_x(0), m_y(0)
{
REGISTER_FOR_MESSAGE( INPUTEVENT_MOUSE );
-
- REGISTER_FOR_MESSAGE( INPUTEVENT_KEYBOARD );
}
void CameraNode::ComputeMatrix()
@@ -19,12 +17,11 @@
MercuryMatrix local;
MQuaternion r( GetRotation().normalize() );
-
- m_lookAt = MercuryVector(0,0,1);
+
+ m_lookAt = MercuryVector(0,0,-1); //by default camera looks down world Z
m_lookAt = m_lookAt.Rotate( r );
m_lookAt.NormalizeSelf();
-// m_lookAt.Print();
-
+
r[MQuaternion::W] *= -1; //reverse angle for camera
r.toMatrix4( local );
@@ -39,12 +36,16 @@
{
MouseInput* m = (MouseInput*)data;
- MQuaternion qx = MQuaternion::CreateFromAxisAngle(MercuryVector(1,0,0), m->dy/1200.0f);
- MQuaternion qy = MQuaternion::CreateFromAxisAngle(MercuryVector(0,1,0), m->dx/1200.0f);
+ m_y += m->dy/1200.0f;
+ m_x += m->dx/1200.0f;
- MQuaternion rot = GetRotation();
- rot = rot * qx * qy;
- SetRotation(rot);
+ MercuryVector Xaxis = m_lookAt.CrossProduct( MercuryVector(0,1,0) );
+ Xaxis.NormalizeSelf();
+
+ MQuaternion qx = MQuaternion::CreateFromAxisAngle(Xaxis, m_y);
+ MQuaternion qy = MQuaternion::CreateFromAxisAngle(MercuryVector(0,1,0), m_x);
+
+ SetRotation(qx * qy);
}
}
@@ -53,10 +54,11 @@
MercuryVector p = GetPosition();
float a = 0;
- if ( KeyboardInput::IsKeyDown(25) ) a -= dTime*2;
- if ( KeyboardInput::IsKeyDown(39) ) a += dTime*2;
+ if ( KeyboardInput::IsKeyDown(25) ) a += dTime*2;
+ if ( KeyboardInput::IsKeyDown(39) ) a -= dTime*2;
p += m_lookAt * a;
+// p.SetY(0); //lock to ground
SetPosition( p );
TransformNode::Update( dTime );
Modified: Mercury2/src/Camera.h
===================================================================
--- Mercury2/src/Camera.h 2009-05-31 04:56:37 UTC (rev 292)
+++ Mercury2/src/Camera.h 2009-05-31 14:26:36 UTC (rev 293)
@@ -15,6 +15,7 @@
GENRTTI(CameraNode);
private:
MercuryVector m_lookAt;
+ float m_x, m_y;
};
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-05-31 04:57:00
|
Revision: 292
http://hgengine.svn.sourceforge.net/hgengine/?rev=292&view=rev
Author: axlecrusher
Date: 2009-05-31 04:56:37 +0000 (Sun, 31 May 2009)
Log Message:
-----------
free flying camera actualyl works now
Modified Paths:
--------------
Mercury2/src/Camera.cpp
Modified: Mercury2/src/Camera.cpp
===================================================================
--- Mercury2/src/Camera.cpp 2009-05-31 04:28:19 UTC (rev 291)
+++ Mercury2/src/Camera.cpp 2009-05-31 04:56:37 UTC (rev 292)
@@ -18,10 +18,16 @@
MercuryMatrix local;
-// m_lookAt = GetRotation() * MercuryVector(0,0,1);
+ MQuaternion r( GetRotation().normalize() );
+
+ m_lookAt = MercuryVector(0,0,1);
+ m_lookAt = m_lookAt.Rotate( r );
+ m_lookAt.NormalizeSelf();
// m_lookAt.Print();
- AngleMatrix( GetRotation().ToVector()*-1, local);
+ r[MQuaternion::W] *= -1; //reverse angle for camera
+ r.toMatrix4( local );
+
local.Translate( GetPosition()*-1 );
m_globalMatrix = GetParentMatrix() * local;
@@ -33,65 +39,25 @@
{
MouseInput* m = (MouseInput*)data;
-// MercuryVertex r;
-// MQuaternion rot, d(0,0,1,0);
+ MQuaternion qx = MQuaternion::CreateFromAxisAngle(MercuryVector(1,0,0), m->dy/1200.0f);
+ MQuaternion qy = MQuaternion::CreateFromAxisAngle(MercuryVector(0,1,0), m->dx/1200.0f);
- MQuaternion qx = MQuaternion::CreateFromAxisAngle(MercuryVector(1,0,0), m->dy/10.0f);
- MQuaternion qy = MQuaternion::CreateFromAxisAngle(MercuryVector(0,1,0), m->dx/10.0f);
-
MQuaternion rot = GetRotation();
- rot *= (qx * qy).normalize();
-// rot[MQuaternion::W]=0;
-// rot.CreateFromAxisAngle(r,1);
-// rot = GetRotation() * rot;
-// rot = rot.normalize();
- rot.Print();
-// 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();
-// r = r.normalize();
-// r += m_rotation;
-
-// r.ToVertex().Print();
-// r += m_rotation;
-// r[3] = 1;
-// rot.SetEuler( r );
+ rot = rot * qx * qy;
SetRotation(rot);
}
- if (message == INPUTEVENT_KEYBOARD)
- {
- MQuaternion r = GetRotation();
-
- KeyboardInput* k = (KeyboardInput*)data;
- switch(k->key)
- {
- case 25:
- r[MQuaternion::X] += 1;
- break;
- case 39:
- r[MQuaternion::X] -= 1;
- break;
- }
- SetRotation(r);
- }
}
void CameraNode::Update(float dTime)
{
- MercuryVector p;// = GetPosition();
-/*
- if ( KeyboardInput::IsKeyDown(25) ) p[2] -= dTime*2;
- if ( KeyboardInput::IsKeyDown(38) ) p[0] -= dTime*2;
- if ( KeyboardInput::IsKeyDown(39) ) p[2] += dTime*2;
- if ( KeyboardInput::IsKeyDown(40) ) p[0] += dTime*2;
+ MercuryVector p = GetPosition();
+ float a = 0;
- p *= m_lookAt.ToVertex();
- p += GetPosition();
+ if ( KeyboardInput::IsKeyDown(25) ) a -= dTime*2;
+ if ( KeyboardInput::IsKeyDown(39) ) a += dTime*2;
+
+ p += m_lookAt * a;
SetPosition( p );
- */
TransformNode::Update( dTime );
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-05-31 04:28:57
|
Revision: 291
http://hgengine.svn.sourceforge.net/hgengine/?rev=291&view=rev
Author: axlecrusher
Date: 2009-05-31 04:28:19 +0000 (Sun, 31 May 2009)
Log Message:
-----------
still working on the camera
Modified Paths:
--------------
Mercury2/src/Camera.cpp
Mercury2/src/Camera.h
Modified: Mercury2/src/Camera.cpp
===================================================================
--- Mercury2/src/Camera.cpp 2009-05-31 04:27:34 UTC (rev 290)
+++ Mercury2/src/Camera.cpp 2009-05-31 04:28:19 UTC (rev 291)
@@ -18,10 +18,10 @@
MercuryMatrix local;
- m_lookAt = GetRotation() * MQuaternion(1, MercuryVector(0,0,1) ) * GetRotation().reciprocal();
- m_lookAt.Print();
+// m_lookAt = GetRotation() * MercuryVector(0,0,1);
+// m_lookAt.Print();
- AngleMatrix( GetRotation().ToVertex()*-1, local);
+ AngleMatrix( GetRotation().ToVector()*-1, local);
local.Translate( GetPosition()*-1 );
m_globalMatrix = GetParentMatrix() * local;
@@ -36,9 +36,19 @@
// MercuryVertex r;
// MQuaternion rot, d(0,0,1,0);
- MQuaternion r = GetRotation();
- r[MQuaternion::X] += m->dy/30.0f;
- r[MQuaternion::Y] += m->dx/30.0f;
+ MQuaternion qx = MQuaternion::CreateFromAxisAngle(MercuryVector(1,0,0), m->dy/10.0f);
+ MQuaternion qy = MQuaternion::CreateFromAxisAngle(MercuryVector(0,1,0), m->dx/10.0f);
+
+ MQuaternion rot = GetRotation();
+ rot *= (qx * qy).normalize();
+// rot[MQuaternion::W]=0;
+// rot.CreateFromAxisAngle(r,1);
+// rot = GetRotation() * rot;
+// rot = rot.normalize();
+ rot.Print();
+// 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();
@@ -49,7 +59,7 @@
// r += m_rotation;
// r[3] = 1;
// rot.SetEuler( r );
- SetRotation(r);
+ SetRotation(rot);
}
if (message == INPUTEVENT_KEYBOARD)
{
Modified: Mercury2/src/Camera.h
===================================================================
--- Mercury2/src/Camera.h 2009-05-31 04:27:34 UTC (rev 290)
+++ Mercury2/src/Camera.h 2009-05-31 04:28:19 UTC (rev 291)
@@ -14,7 +14,7 @@
GENRTTI(CameraNode);
private:
- MQuaternion m_lookAt;
+ MercuryVector m_lookAt;
};
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-05-31 04:27:46
|
Revision: 290
http://hgengine.svn.sourceforge.net/hgengine/?rev=290&view=rev
Author: axlecrusher
Date: 2009-05-31 04:27:34 +0000 (Sun, 31 May 2009)
Log Message:
-----------
Rotations are defined by quaternions now
Modified Paths:
--------------
Mercury2/src/TransformNode.cpp
Modified: Mercury2/src/TransformNode.cpp
===================================================================
--- Mercury2/src/TransformNode.cpp 2009-05-31 04:26:48 UTC (rev 289)
+++ Mercury2/src/TransformNode.cpp 2009-05-31 04:27:34 UTC (rev 290)
@@ -51,12 +51,18 @@
{
m_tainted = false;
- MercuryMatrix local;
+ MercuryMatrix local, t;
// local.Identity();
- local.Transotale( m_position[0], m_position[1], m_position[2],
- m_rotation[MQuaternion::X], m_rotation[MQuaternion::Y], m_rotation[MQuaternion::Z],
- m_scale[0], m_scale[1], m_scale[2] );
+ local.Translate( m_position );
+ local.Rotate( m_rotation );
+ local.Scale( m_scale );
+// m_rotation.toMatrix4(t);
+// local.Transotale( m_position[0], m_position[1], m_position[2],
+// 0.0f,0.0f,0.0f,
+// m_rotation[MQuaternion::X], m_rotation[MQuaternion::Y], m_rotation[MQuaternion::Z],
+// m_scale[0], m_scale[1], m_scale[2] );
+// local = t * local;
m_globalMatrix = GetParentMatrix() * local;
}
@@ -98,14 +104,14 @@
//only change the values that exist in the XML
if ( !node.Attribute("rotx").empty() )
- rot[MQuaternion::X] = StrToFloat( node.Attribute("rotx") );
+ rot *= MQuaternion::CreateFromAxisAngle(MercuryVector(1,0,0), StrToFloat( node.Attribute("rotx") ));
if ( !node.Attribute("roty").empty() )
- rot[MQuaternion::Y] = StrToFloat( node.Attribute("roty") );
+ rot *= MQuaternion::CreateFromAxisAngle(MercuryVector(0,1,0), StrToFloat( node.Attribute("roty") ));
if ( !node.Attribute("rotz").empty() )
- rot[MQuaternion::Z] = StrToFloat( node.Attribute("rotz") );
-
+ rot *= MQuaternion::CreateFromAxisAngle(MercuryVector(0,0,1), StrToFloat( node.Attribute("rotz") ));
+
if ( !node.Attribute("scalex").empty() )
scale.SetX( StrToFloat( node.Attribute("scalex") ) );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-05-31 04:26:49
|
Revision: 289
http://hgengine.svn.sourceforge.net/hgengine/?rev=289&view=rev
Author: axlecrusher
Date: 2009-05-31 04:26:48 +0000 (Sun, 31 May 2009)
Log Message:
-----------
update
Modified Paths:
--------------
Mercury2/src/MercuryMatrix.h
Modified: Mercury2/src/MercuryMatrix.h
===================================================================
--- Mercury2/src/MercuryMatrix.h 2009-05-31 04:26:04 UTC (rev 288)
+++ Mercury2/src/MercuryMatrix.h 2009-05-31 04:26:48 UTC (rev 289)
@@ -5,9 +5,8 @@
#include "MercuryMath.h"
#include "MercuryUtil.h"
#include <MercuryVertex.h>
+#include <MQuaternion.h>
-class MercuryMatrix;
-
///General Purpose 4x4 row-major matrix
class MercuryMatrix
{
@@ -42,7 +41,12 @@
///Rotate a given amount (fAngle) in degrees around pAxis
void RotateAngAxis( float fAngle, float x, float y, float z );
+
+ void Rotate(const MQuaternion& q);
+
void Scale(float x, float y, float z);
+ inline void Scale(const MercuryVertex& v) { Scale(v[0], v[1], v[2]); }
+
void Transotale( float tX, float tY, float tZ, float rX, float rY, float rZ, float sX, float sY, float sZ );
inline void Transpose() { TransposeMatrix( m_matrix ); }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-05-31 04:26:39
|
Revision: 288
http://hgengine.svn.sourceforge.net/hgengine/?rev=288&view=rev
Author: axlecrusher
Date: 2009-05-31 04:26:04 +0000 (Sun, 31 May 2009)
Log Message:
-----------
make CreatFromAngleAxis static
Modified Paths:
--------------
Mercury2/src/MQuaternion.cpp
Mercury2/src/MQuaternion.h
Modified: Mercury2/src/MQuaternion.cpp
===================================================================
--- Mercury2/src/MQuaternion.cpp 2009-05-31 04:18:08 UTC (rev 287)
+++ Mercury2/src/MQuaternion.cpp 2009-05-31 04:26:04 UTC (rev 288)
@@ -52,8 +52,15 @@
m_wxyz[3] = cx*cy*sz-sx*sy*cz;//q4
}
-void MQuaternion::CreateFromAxisAngle(const MercuryVertex& p, const float radians)
+MQuaternion MQuaternion::CreateFromAxisAngle(const MercuryVertex& p, const float radians)
{
+ MQuaternion q;
+ q.FromAxisAngle(p, radians);
+ return q;
+}
+
+void MQuaternion::FromAxisAngle(const MercuryVertex& p, const float radians)
+{
float sn = SIN(radians/2.0f);
m_wxyz[0] = COS(radians/2.0f);
m_wxyz[1] = sn * p[0];
Modified: Mercury2/src/MQuaternion.h
===================================================================
--- Mercury2/src/MQuaternion.h 2009-05-31 04:18:08 UTC (rev 287)
+++ Mercury2/src/MQuaternion.h 2009-05-31 04:26:04 UTC (rev 288)
@@ -20,7 +20,8 @@
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);
+ 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;
///Access a component of the quaternion with the [] operator
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-05-31 04:18:09
|
Revision: 287
http://hgengine.svn.sourceforge.net/hgengine/?rev=287&view=rev
Author: axlecrusher
Date: 2009-05-31 04:18:08 +0000 (Sun, 31 May 2009)
Log Message:
-----------
rotate by quaternion
Modified Paths:
--------------
Mercury2/src/MercuryMatrix.cpp
Modified: Mercury2/src/MercuryMatrix.cpp
===================================================================
--- Mercury2/src/MercuryMatrix.cpp 2009-05-31 04:13:24 UTC (rev 286)
+++ Mercury2/src/MercuryMatrix.cpp 2009-05-31 04:18:08 UTC (rev 287)
@@ -120,6 +120,13 @@
(*this)[3][3] = 1;
}
+void MercuryMatrix::Rotate(const MQuaternion& q)
+{
+ MercuryMatrix m;
+ q.normalize().toMatrix4( m );
+ *this *= m;
+}
+
void MercuryMatrix::Transotale( float tX, float tY, float tZ, float rX, float rY, float rZ, float sX, float sY, float sZ )
{
//x,y,z must be negated for some reason
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-05-31 04:13:25
|
Revision: 286
http://hgengine.svn.sourceforge.net/hgengine/?rev=286&view=rev
Author: axlecrusher
Date: 2009-05-31 04:13:24 +0000 (Sun, 31 May 2009)
Log Message:
-----------
Move vector rotate out of quaternion into vertex
Modified Paths:
--------------
Mercury2/src/MQuaternion.cpp
Mercury2/src/MQuaternion.h
Mercury2/src/MercuryVertex.cpp
Mercury2/src/MercuryVertex.h
Modified: Mercury2/src/MQuaternion.cpp
===================================================================
--- Mercury2/src/MQuaternion.cpp 2009-05-31 04:04:35 UTC (rev 285)
+++ Mercury2/src/MQuaternion.cpp 2009-05-31 04:13:24 UTC (rev 286)
@@ -245,12 +245,6 @@
printf("%s: %f %f %f %f\n", s.c_str(), m_wxyz[0], m_wxyz[1], m_wxyz[2], m_wxyz[3]);
}
-MercuryVector MQuaternion::operator * (const MercuryVector &rhs) const
-{
- return (*this * MQuaternion(0, rhs) * reciprocal()).ToVector();
-}
-
-
//Returns the Euclidian Inner Product of two MQuaternions (Similar to Vector Dot-Product)
float innerProduct(const MQuaternion & a, const MQuaternion &b)
{
Modified: Mercury2/src/MQuaternion.h
===================================================================
--- Mercury2/src/MQuaternion.h 2009-05-31 04:04:35 UTC (rev 285)
+++ Mercury2/src/MQuaternion.h 2009-05-31 04:13:24 UTC (rev 286)
@@ -61,8 +61,6 @@
MQuaternion& operator *= (const float &rhs);
MQuaternion& operator /= (const float &rhs);
- MercuryVector operator * (const MercuryVector &rhs) const;
-
bool operator==(const MQuaternion &rhs) const;
inline bool operator!=(const MQuaternion &rhs) const { return !(*this == rhs); }
Modified: Mercury2/src/MercuryVertex.cpp
===================================================================
--- Mercury2/src/MercuryVertex.cpp 2009-05-31 04:04:35 UTC (rev 285)
+++ Mercury2/src/MercuryVertex.cpp 2009-05-31 04:13:24 UTC (rev 286)
@@ -1,6 +1,7 @@
#include <MercuryVertex.h>
#include <MercuryUtil.h>
#include <MercuryMath.h>
+#include <MQuaternion.h>
MercuryVertex::MercuryVertex()
{
@@ -115,8 +116,11 @@
printf("%s: %f %f %f %f\n", s.c_str(), (*this)[0], (*this)[1], (*this)[2], (*this)[3]);
}
+MercuryVertex MercuryVertex::Rotate(const MQuaternion& q) const
+{
+ return (q * MQuaternion(0, *this) * q.reciprocal()).ToVector();
+}
-
/****************************************************************************
* Copyright (C) 2009 by Joshua Allen *
* *
Modified: Mercury2/src/MercuryVertex.h
===================================================================
--- Mercury2/src/MercuryVertex.h 2009-05-31 04:04:35 UTC (rev 285)
+++ Mercury2/src/MercuryVertex.h 2009-05-31 04:13:24 UTC (rev 286)
@@ -10,6 +10,8 @@
#define __inline__ inline
#endif
+class MQuaternion;
+
class MercuryVertex
{
public:
@@ -79,6 +81,8 @@
MercuryVertex DotProduct3(const MercuryVertex& rhs1, const MercuryVertex& rhs2, const MercuryVertex& rhs3) const;
void Print(const MString& s = "Vertex") const;
+
+ MercuryVertex Rotate(const MQuaternion& q) const;
// float (*this)[3];
FloatRow m_xyzw;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-05-31 04:04:36
|
Revision: 285
http://hgengine.svn.sourceforge.net/hgengine/?rev=285&view=rev
Author: axlecrusher
Date: 2009-05-31 04:04:35 +0000 (Sun, 31 May 2009)
Log Message:
-----------
updates
Modified Paths:
--------------
Mercury2/src/MQuaternion.cpp
Mercury2/src/MQuaternion.h
Modified: Mercury2/src/MQuaternion.cpp
===================================================================
--- Mercury2/src/MQuaternion.cpp 2009-05-31 01:25:41 UTC (rev 284)
+++ Mercury2/src/MQuaternion.cpp 2009-05-31 04:04:35 UTC (rev 285)
@@ -1,5 +1,6 @@
#include <MQuaternion.h>
#include <MercuryMath.h>
+#include <MercuryMatrix.h>
MQuaternion::MQuaternion()
{
@@ -60,6 +61,24 @@
m_wxyz[3] = sn * p[2];
}
+void MQuaternion::ToAxisAngle(float& angle, float& x, float& y, float& z) const
+{
+ float scale = SQRT(x*x + y*y + z*z);
+
+ //prevent infinite axis
+ if (scale == 0)
+ {
+ x=y=0; z=1;
+ angle = 0;
+ return;
+ }
+
+ angle = 2*acos(m_wxyz[0]);
+ x = m_wxyz[1] / scale;
+ y = m_wxyz[2] / scale;
+ z = m_wxyz[3] / scale;
+}
+
//Returns the magnitude
float MQuaternion::magnitude() const {
return SQRT((m_wxyz[0]*m_wxyz[0])+(m_wxyz[1]*m_wxyz[1])+(m_wxyz[2]*m_wxyz[2])+(m_wxyz[3]*m_wxyz[3]));
@@ -215,7 +234,7 @@
return true;
}
-MercuryVertex MQuaternion::ToVertex() const
+MercuryVertex MQuaternion::ToVector() const
{
MercuryVertex v(m_wxyz[1], m_wxyz[2], m_wxyz[3], m_wxyz[0]);
return v;
@@ -226,7 +245,12 @@
printf("%s: %f %f %f %f\n", s.c_str(), m_wxyz[0], m_wxyz[1], m_wxyz[2], m_wxyz[3]);
}
+MercuryVector MQuaternion::operator * (const MercuryVector &rhs) const
+{
+ return (*this * MQuaternion(0, rhs) * reciprocal()).ToVector();
+}
+
//Returns the Euclidian Inner Product of two MQuaternions (Similar to Vector Dot-Product)
float innerProduct(const MQuaternion & a, const MQuaternion &b)
{
Modified: Mercury2/src/MQuaternion.h
===================================================================
--- Mercury2/src/MQuaternion.h 2009-05-31 01:25:41 UTC (rev 284)
+++ Mercury2/src/MQuaternion.h 2009-05-31 04:04:35 UTC (rev 285)
@@ -2,8 +2,10 @@
#define MQUATERNION_H
#include <MercuryVertex.h>
-#include <MercuryMatrix.h>
+#include <MercuryUtil.h>
+class MercuryMatrix;
+
///Mathematical Quaternion (Used for Rotation)
class MQuaternion {
public:
@@ -19,6 +21,7 @@
///Make the quaternion represent a given angle radians around an axis p
void CreateFromAxisAngle(const MercuryVertex& p, const float radians);
+ void ToAxisAngle(float& angle, float& x, float& y, float& z) const;
///Access a component of the quaternion with the [] operator
float & operator[] ( const WXYZ rhs );
@@ -39,7 +42,7 @@
///Converts Quaternion to complete 4x4 Matrix
void toMatrix4( MercuryMatrix & mat ) const;
///Convert the quaternion to a point.
- MercuryVertex ToVertex() const;
+ MercuryVertex ToVector() const;
/******************************************************
* NOTE: Quaternion multipication is not commutative *
@@ -58,6 +61,8 @@
MQuaternion& operator *= (const float &rhs);
MQuaternion& operator /= (const float &rhs);
+ MercuryVector operator * (const MercuryVector &rhs) const;
+
bool operator==(const MQuaternion &rhs) const;
inline bool operator!=(const MQuaternion &rhs) const { return !(*this == rhs); }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-05-31 01:25:49
|
Revision: 284
http://hgengine.svn.sourceforge.net/hgengine/?rev=284&view=rev
Author: axlecrusher
Date: 2009-05-31 01:25:41 +0000 (Sun, 31 May 2009)
Log Message:
-----------
start zeroed
Modified Paths:
--------------
Mercury2/src/MQuaternion.cpp
Modified: Mercury2/src/MQuaternion.cpp
===================================================================
--- Mercury2/src/MQuaternion.cpp 2009-05-31 01:24:34 UTC (rev 283)
+++ Mercury2/src/MQuaternion.cpp 2009-05-31 01:25:41 UTC (rev 284)
@@ -3,7 +3,7 @@
MQuaternion::MQuaternion()
{
- m_wxyz[0] = 1;
+ m_wxyz[0] = 0;
m_wxyz[1] = 0;
m_wxyz[2] = 0;
m_wxyz[3] = 0;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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.
|
|
From: <axl...@us...> - 2009-05-31 00:54:23
|
Revision: 282
http://hgengine.svn.sourceforge.net/hgengine/?rev=282&view=rev
Author: axlecrusher
Date: 2009-05-31 00:54:15 +0000 (Sun, 31 May 2009)
Log Message:
-----------
updates
Modified Paths:
--------------
Mercury2/src/Camera.cpp
Mercury2/src/Camera.h
Mercury2/src/Viewport.cpp
Modified: Mercury2/src/Camera.cpp
===================================================================
--- Mercury2/src/Camera.cpp 2009-05-31 00:53:17 UTC (rev 281)
+++ Mercury2/src/Camera.cpp 2009-05-31 00:54:15 UTC (rev 282)
@@ -8,6 +8,8 @@
:TransformNode()
{
REGISTER_FOR_MESSAGE( INPUTEVENT_MOUSE );
+
+ REGISTER_FOR_MESSAGE( INPUTEVENT_KEYBOARD );
}
void CameraNode::ComputeMatrix()
@@ -16,8 +18,10 @@
MercuryMatrix local;
-// local.RotateXYZ( m_rotation*-1 );
-// m_rotation.
+ m_lookAt = m_rotation * MQuaternion(0,0,0,1) * m_rotation.reciprocal();
+// m_lookAt.
+ m_lookAt.ToVertex().Print();
+
AngleMatrix( m_rotation.ToVertex()*-1, local);
local.Translate( m_position*-1 );
@@ -30,25 +34,56 @@
{
MouseInput* m = (MouseInput*)data;
+// 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;
+// r = r.normalize();
+// r = r * m_lookAt * r.reciprocal();
+// r = r.normalize();
+// r += m_rotation;
+
+// r.ToVertex().Print();
+// r += m_rotation;
+// r[3] = 1;
+// rot.SetEuler( r );
SetRotation(r);
}
+ if (message == INPUTEVENT_KEYBOARD)
+ {
+ MQuaternion r = m_rotation;
+
+ KeyboardInput* k = (KeyboardInput*)data;
+ switch(k->key)
+ {
+ case 25:
+ r[0] += 1*k->isDown;
+ break;
+ case 39:
+ r[0] -= 1*k->isDown;
+ break;
+ }
+ SetRotation(r);
+ }
}
void CameraNode::Update(float dTime)
{
- MercuryVector p = GetPosition();
-
+ MercuryVector p;// = GetPosition();
+/*
if ( KeyboardInput::IsKeyDown(25) ) p[2] -= dTime*2;
if ( KeyboardInput::IsKeyDown(38) ) p[0] -= dTime*2;
if ( KeyboardInput::IsKeyDown(39) ) p[2] += dTime*2;
if ( KeyboardInput::IsKeyDown(40) ) p[0] += dTime*2;
+
+ p *= m_lookAt.ToVertex();
+ p += GetPosition();
+ SetPosition( p );
+ */
- SetPosition( p );
-
TransformNode::Update( dTime );
}
Modified: Mercury2/src/Camera.h
===================================================================
--- Mercury2/src/Camera.h 2009-05-31 00:53:17 UTC (rev 281)
+++ Mercury2/src/Camera.h 2009-05-31 00:54:15 UTC (rev 282)
@@ -2,6 +2,7 @@
#define CAMERA_H
#include <TransformNode.h>
+#include <MQuaternion.h>
class CameraNode : public TransformNode
{
@@ -13,6 +14,7 @@
GENRTTI(CameraNode);
private:
+ MQuaternion m_lookAt;
};
#endif
Modified: Mercury2/src/Viewport.cpp
===================================================================
--- Mercury2/src/Viewport.cpp 2009-05-31 00:53:17 UTC (rev 281)
+++ Mercury2/src/Viewport.cpp 2009-05-31 00:54:15 UTC (rev 282)
@@ -30,8 +30,8 @@
glMatrixMode(GL_MODELVIEW);
//compute the position of the eye
- EYE = MercuryVertex(0,0,0,1);
- EYE = matrix * EYE;
+// EYE = MercuryVertex(0,0,0,1); //wrong
+// EYE = matrix * EYE;
VIEWMATRIX = matrix;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-05-31 00:53:22
|
Revision: 281
http://hgengine.svn.sourceforge.net/hgengine/?rev=281&view=rev
Author: axlecrusher
Date: 2009-05-31 00:53:17 +0000 (Sun, 31 May 2009)
Log Message:
-----------
W is component 0
Modified Paths:
--------------
Mercury2/src/MQuaternion.cpp
Mercury2/src/MQuaternion.h
Modified: Mercury2/src/MQuaternion.cpp
===================================================================
--- Mercury2/src/MQuaternion.cpp 2009-05-26 03:38:08 UTC (rev 280)
+++ Mercury2/src/MQuaternion.cpp 2009-05-31 00:53:17 UTC (rev 281)
@@ -1,34 +1,36 @@
#include <MQuaternion.h>
#include <MercuryMath.h>
-MQuaternion::MQuaternion(float W, float X, float Y, float Z)
+MQuaternion::MQuaternion()
{
- m_xyzw[0] = X;
- m_xyzw[1] = Y;
- m_xyzw[2] = Z;
- m_xyzw[3] = W;
+ m_wxyz[0] = 0;
+ m_wxyz[1] = 0;
+ m_wxyz[2] = 0;
+ m_wxyz[3] = 0;
}
-MQuaternion::MQuaternion(float* xyzw)
+MQuaternion::MQuaternion(float W, float X, float Y, float Z)
{
- for (uint8_t i = 0; i < 4; ++i)
- m_xyzw[i] = xyzw[i];
+ m_wxyz[0] = W;
+ m_wxyz[1] = X;
+ m_wxyz[2] = Y;
+ m_wxyz[3] = Z;
}
-MQuaternion::MQuaternion(const MercuryVertex& p)
+MQuaternion::MQuaternion(float W, const MercuryVertex& p)
{
- m_xyzw[0] = p.GetX();
- m_xyzw[1] = p.GetY();
- m_xyzw[2] = p.GetZ();
- m_xyzw[3] = 0;
+ m_wxyz[0] = W;
+ m_wxyz[1] = p[0];
+ m_wxyz[2] = p[1];
+ m_wxyz[3] = p[2];
}
float & MQuaternion::operator [] (int i)
{
- return m_xyzw[i];
+ return m_wxyz[i]; //haha we won't even get here.
}
-void MQuaternion::SetEuler(const MercuryVector& angles)
+void MQuaternion::SetEuler(const MercuryVertex& angles)
{
float X = angles[0]/2.0f; //roll
float Y = angles[1]/2.0f; //pitch
@@ -43,24 +45,24 @@
//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
+ m_wxyz[0] = cx*cy*cz+sx*sy*sz;//q1
+ m_wxyz[1] = sx*cy*cz-cx*sy*sz;//q2
+ m_wxyz[2] = cx*sy*cz+sx*cy*sz;//q3
+ m_wxyz[3] = cx*cy*sz-sx*sy*cz;//q4
}
-void MQuaternion::CreateFromAxisAngle(const MercuryVector& p, const float radians)
+void MQuaternion::CreateFromAxisAngle(const MercuryVertex& 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];
+ m_wxyz[0] = COS(radians/2.0f);
+ m_wxyz[1] = sn * p[0];
+ m_wxyz[2] = sn * p[1];
+ m_wxyz[3] = sn * p[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]));
+ return SQRT((m_wxyz[0]*m_wxyz[0])+(m_wxyz[1]*m_wxyz[1])+(m_wxyz[2]*m_wxyz[2])+(m_wxyz[3]*m_wxyz[3]));
}
//Returns the normalized MQuaternion
@@ -70,7 +72,7 @@
//Returns the conjugate MQuaternion
MQuaternion MQuaternion::conjugate() const {
- MQuaternion c(m_xyzw[3],-m_xyzw[0],-m_xyzw[1],-m_xyzw[2]);
+ MQuaternion c(m_wxyz[0],-m_wxyz[1],-m_wxyz[2],-m_wxyz[3]);
return c;
}
@@ -87,15 +89,15 @@
//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];
+ float X = 2*m_wxyz[1]*m_wxyz[1]; //Reduced calulation for speed
+ float Y = 2*m_wxyz[2]*m_wxyz[2];
+ float Z = 2*m_wxyz[3]*m_wxyz[3];
+ float a = 2*m_wxyz[0]*m_wxyz[1];
+ float b = 2*m_wxyz[0]*m_wxyz[2];
+ float c = 2*m_wxyz[0]*m_wxyz[3];
+ float d = 2*m_wxyz[1]*m_wxyz[2];
+ float e = 2*m_wxyz[1]*m_wxyz[3];
+ float f = 2*m_wxyz[2]*m_wxyz[3];
//row major
matrix[0][0] = 1-Y-Z;
@@ -128,132 +130,131 @@
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];
+ for (uint8_t i = 0; i < 4; ++i)
+ result.m_wxyz[i] = m_wxyz[i]+rhs.m_wxyz[i];
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];
+ for (uint8_t i = 0; i < 4; ++i)
+ result.m_wxyz[i] = m_wxyz[i]-rhs.m_wxyz[i];
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]);
+ result.m_wxyz[0] = (m_wxyz[0]*rhs.m_wxyz[0])-(m_wxyz[1]*rhs.m_wxyz[1])-(m_wxyz[2]*rhs.m_wxyz[2])-(m_wxyz[3]*rhs.m_wxyz[3]);
+ result.m_wxyz[1] = (m_wxyz[0]*rhs.m_wxyz[1])+(m_wxyz[1]*rhs.m_wxyz[0])+(m_wxyz[2]*rhs.m_wxyz[3])-(m_wxyz[3]*rhs.m_wxyz[2]);
+ result.m_wxyz[2] = (m_wxyz[0]*rhs.m_wxyz[2])-(m_wxyz[1]*rhs.m_wxyz[3])+(m_wxyz[2]*rhs.m_wxyz[0])+(m_wxyz[3]*rhs.m_wxyz[1]);
+ result.m_wxyz[3] = (m_wxyz[0]*rhs.m_wxyz[3])+(m_wxyz[1]*rhs.m_wxyz[2])-(m_wxyz[2]*rhs.m_wxyz[1])+(m_wxyz[3]*rhs.m_wxyz[0]);
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];
+ for (uint8_t i = 0; i < 4; ++i)
+ m_wxyz[i] = rhs.m_wxyz[i];
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];
+ for (uint8_t i = 0; i < 4; ++i)
+ m_wxyz[i] += rhs.m_wxyz[i];
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];
+ for (uint8_t i = 0; i < 4; ++i)
+ m_wxyz[i] -= rhs.m_wxyz[i];
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]);
+ m_wxyz[0] = (m_wxyz[0]*rhs.m_wxyz[0])-(m_wxyz[1]*rhs.m_wxyz[1])-(m_wxyz[2]*rhs.m_wxyz[2])-(m_wxyz[3]*rhs.m_wxyz[3]);
+ m_wxyz[1] = (m_wxyz[0]*rhs.m_wxyz[1])+(m_wxyz[1]*rhs.m_wxyz[0])+(m_wxyz[2]*rhs.m_wxyz[3])-(m_wxyz[3]*rhs.m_wxyz[2]);
+ m_wxyz[2] = (m_wxyz[0]*rhs.m_wxyz[2])-(m_wxyz[1]*rhs.m_wxyz[3])+(m_wxyz[2]*rhs.m_wxyz[0])+(m_wxyz[3]*rhs.m_wxyz[1]);
+ m_wxyz[3] = (m_wxyz[0]*rhs.m_wxyz[3])+(m_wxyz[1]*rhs.m_wxyz[2])-(m_wxyz[2]*rhs.m_wxyz[1])+(m_wxyz[3]*rhs.m_wxyz[0]);
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;
+ for (uint8_t i = 0; i < 4; ++i)
+ result.m_wxyz[i] = m_wxyz[i]*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;
+ for (uint8_t i = 0; i < 4; ++i)
+ result.m_wxyz[i] = m_wxyz[i]/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;
+MQuaternion& MQuaternion::operator *= (const float &rhs)
+{
+ for (uint8_t i = 0; i < 4; ++i)
+ m_wxyz[i] *= 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;
+MQuaternion& MQuaternion::operator /= (const float &rhs)
+{
+ for (uint8_t i = 0; i < 4; ++i)
+ m_wxyz[i] /= rhs;
return (*this);
}
+bool MQuaternion::operator==(const MQuaternion &rhs) const
+{
+ for (uint8_t i = 0; i < 4; ++i)
+ if (m_wxyz[i] != rhs.m_wxyz[i]) return false;
+ return true;
+}
+
+MercuryVertex MQuaternion::ToVertex() const
+{
+ MercuryVertex v(m_wxyz[1], m_wxyz[2], m_wxyz[3], m_wxyz[0]);
+ return v;
+}
+
+
+
//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]);
+ return (a.m_wxyz[0]*b.m_wxyz[0])+(a.m_wxyz[1]*b.m_wxyz[1])+(a.m_wxyz[2]*b.m_wxyz[2])+(a.m_wxyz[3]*b.m_wxyz[3]);
}
//Returns the Euclidian Outer Product of two MQuaternions
-MercuryVector outerProduct(MQuaternion a,MQuaternion b)
+MercuryVertex 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]);
+ MercuryVertex result;
+ result[0] = (a.m_wxyz[0]*b.m_wxyz[1])-(a.m_wxyz[1]*b.m_wxyz[0])-(a.m_wxyz[2]*b.m_wxyz[3])+(a.m_wxyz[3]*b.m_wxyz[2]);
+ result[1] = (a.m_wxyz[0]*b.m_wxyz[2])+(a.m_wxyz[1]*b.m_wxyz[3])-(a.m_wxyz[2]*b.m_wxyz[0])-(a.m_wxyz[3]*b.m_wxyz[1]);
+ result[2] = (a.m_wxyz[0]*b.m_wxyz[3])-(a.m_wxyz[1]*b.m_wxyz[2])+(a.m_wxyz[2]*b.m_wxyz[1])-(a.m_wxyz[3]*b.m_wxyz[0]);
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]);
+ result.m_wxyz[0] = (a.m_wxyz[0]*b.m_wxyz[0])-(a.m_wxyz[1]*b.m_wxyz[1])-(a.m_wxyz[2]*b.m_wxyz[2])-(a.m_wxyz[3]*b.m_wxyz[3]);
+ result.m_wxyz[1] = (a.m_wxyz[0]*b.m_wxyz[1])+(a.m_wxyz[1]*b.m_wxyz[0]);
+ result.m_wxyz[2] = (a.m_wxyz[0]*b.m_wxyz[2])+(a.m_wxyz[2]*b.m_wxyz[0]);
+ result.m_wxyz[3] = (a.m_wxyz[0]*b.m_wxyz[3])+(a.m_wxyz[3]*b.m_wxyz[0]);
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]);
+MercuryVertex oddProduct(MQuaternion a,MQuaternion b) {
+ MercuryVertex result;
+ result[0] = (a.m_wxyz[2]*b.m_wxyz[3])-(a.m_wxyz[3]*b.m_wxyz[2]);
+ result[1] = (a.m_wxyz[3]*b.m_wxyz[1])-(a.m_wxyz[1]*b.m_wxyz[3]);
+ result[2] = (a.m_wxyz[1]*b.m_wxyz[2])-(a.m_wxyz[2]*b.m_wxyz[1]);
return result;
}
@@ -279,13 +280,6 @@
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
@@ -320,6 +314,7 @@
matrix[3][3] = 1;
}
+
/****************************************************************************
* Copyright (C) 2009 by Joshua Allen, Charles Lohr, Adam Lowman *
* *
Modified: Mercury2/src/MQuaternion.h
===================================================================
--- Mercury2/src/MQuaternion.h 2009-05-26 03:38:08 UTC (rev 280)
+++ Mercury2/src/MQuaternion.h 2009-05-31 00:53:17 UTC (rev 281)
@@ -8,21 +8,20 @@
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);
-
+ MQuaternion();
+ MQuaternion(float W, float X, float Y, float Z);
+ MQuaternion(float W, 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
@@ -38,8 +37,8 @@
///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] ); }
-
+ MercuryVertex ToVertex() const;
+
/******************************************************
* NOTE: Quaternion multipication is not commutative *
* Therefore the / operator could imply for a/b *
@@ -57,9 +56,11 @@
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); }
-
+ bool operator==(const MQuaternion &rhs) const;
+ inline bool operator!=(const MQuaternion &rhs) const { return !(*this == rhs); }
+
+// private:
+ FloatRow m_wxyz;
} M_ALIGN(32);
///Produce a matrix out of a rotation x, then y then z (how Mercury does it)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2009-05-26 03:38:11
|
Revision: 280
http://hgengine.svn.sourceforge.net/hgengine/?rev=280&view=rev
Author: cnlohr
Date: 2009-05-26 03:38:08 +0000 (Tue, 26 May 2009)
Log Message:
-----------
Add a module, since I can't get the Windows build system working yet.
Modified Paths:
--------------
Mercury2/Mercury2.sln
Mercury2/Mercury2.vcproj
Modified: Mercury2/Mercury2.sln
===================================================================
--- Mercury2/Mercury2.sln 2009-05-26 03:26:06 UTC (rev 279)
+++ Mercury2/Mercury2.sln 2009-05-26 03:38:08 UTC (rev 280)
@@ -1,16 +1,26 @@
Microsoft Visual Studio Solution File, Format Version 10.00
-# Visual C++ Express 2008
+# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Mercury2", "Mercury2.vcproj", "{071CC088-86A7-4A9F-9FEE-50BD69132886}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|Win32 = Debug|Win32
+ Release|Any CPU = Release|Any CPU
+ Release|Mixed Platforms = Release|Mixed Platforms
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {071CC088-86A7-4A9F-9FEE-50BD69132886}.Debug|Any CPU.ActiveCfg = Debug|Win32
+ {071CC088-86A7-4A9F-9FEE-50BD69132886}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
+ {071CC088-86A7-4A9F-9FEE-50BD69132886}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{071CC088-86A7-4A9F-9FEE-50BD69132886}.Debug|Win32.ActiveCfg = Debug|Win32
{071CC088-86A7-4A9F-9FEE-50BD69132886}.Debug|Win32.Build.0 = Debug|Win32
+ {071CC088-86A7-4A9F-9FEE-50BD69132886}.Release|Any CPU.ActiveCfg = Release|Win32
+ {071CC088-86A7-4A9F-9FEE-50BD69132886}.Release|Mixed Platforms.ActiveCfg = Release|Win32
+ {071CC088-86A7-4A9F-9FEE-50BD69132886}.Release|Mixed Platforms.Build.0 = Release|Win32
{071CC088-86A7-4A9F-9FEE-50BD69132886}.Release|Win32.ActiveCfg = Release|Win32
{071CC088-86A7-4A9F-9FEE-50BD69132886}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
Modified: Mercury2/Mercury2.vcproj
===================================================================
--- Mercury2/Mercury2.vcproj 2009-05-26 03:26:06 UTC (rev 279)
+++ Mercury2/Mercury2.vcproj 2009-05-26 03:38:08 UTC (rev 280)
@@ -578,6 +578,22 @@
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
+ <Filter
+ Name="Modules"
+ >
+ <File
+ RelativePath=".\modules\BillboardNode.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\modules\BillboardNode.h"
+ >
+ </File>
+ </Filter>
+ <File
+ RelativePath=".\scenegraph.xml"
+ >
+ </File>
</Files>
<Globals>
</Globals>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2009-05-26 03:26:09
|
Revision: 279
http://hgengine.svn.sourceforge.net/hgengine/?rev=279&view=rev
Author: cnlohr
Date: 2009-05-26 03:26:06 +0000 (Tue, 26 May 2009)
Log Message:
-----------
fixup Unicode on Windows
Modified Paths:
--------------
Mercury2/src/ModuleManager.cpp
Modified: Mercury2/src/ModuleManager.cpp
===================================================================
--- Mercury2/src/ModuleManager.cpp 2009-05-26 03:23:41 UTC (rev 278)
+++ Mercury2/src/ModuleManager.cpp 2009-05-26 03:26:06 UTC (rev 279)
@@ -10,7 +10,7 @@
#define RTLD_NOW 0
#define RTLD_GLOBAL 0
-void * dlopen( const char * sFile, int dummy ) { return LoadLibrary( sFile ); }
+void * dlopen( const char * sFile, int dummy ) { return LoadLibrary( (LPCWSTR)sFile ); }
void dlclose( void * handle ) { FreeLibrary( (HMODULE)handle ); }
void * dlsym( void * handle, const char * sym ) { return GetProcAddress( (HMODULE) handle, sym ); }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2009-05-26 03:23:52
|
Revision: 278
http://hgengine.svn.sourceforge.net/hgengine/?rev=278&view=rev
Author: cnlohr
Date: 2009-05-26 03:23:41 +0000 (Tue, 26 May 2009)
Log Message:
-----------
windows project update
Modified Paths:
--------------
Mercury2/Mercury2.vcproj
Modified: Mercury2/Mercury2.vcproj
===================================================================
--- Mercury2/Mercury2.vcproj 2009-05-26 02:51:42 UTC (rev 277)
+++ Mercury2/Mercury2.vcproj 2009-05-26 03:23:41 UTC (rev 278)
@@ -290,6 +290,22 @@
>
</File>
<File
+ RelativePath=".\src\ModuleManager.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\src\ModuleManager.h"
+ >
+ </File>
+ <File
+ RelativePath=".\src\MQuaternion.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\src\MQuaternion.h"
+ >
+ </File>
+ <File
RelativePath=".\src\MSemaphore.cpp"
>
</File>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2009-05-26 02:51:43
|
Revision: 277
http://hgengine.svn.sourceforge.net/hgengine/?rev=277&view=rev
Author: cnlohr
Date: 2009-05-26 02:51:42 +0000 (Tue, 26 May 2009)
Log Message:
-----------
fix up stuff for modules to enable proper building
Modified Paths:
--------------
Mercury2/cnconfigure
Mercury2/src/MercuryNode.h
Modified: Mercury2/cnconfigure
===================================================================
--- Mercury2/cnconfigure 2009-05-26 02:23:47 UTC (rev 276)
+++ Mercury2/cnconfigure 2009-05-26 02:51:42 UTC (rev 277)
@@ -191,7 +191,7 @@
echo "CFLAGS=$CC_BASE $CFLAGS" >> Makefile
echo "LDFLAGS=$LDFLAGS" >> Makefile
echo "">>Makefile
-echo -e "all : \$(PROJ) library" >> Makefile
+echo -e "all : \$(PROJ) library allmodules" >> Makefile
echo -e "\$(PROJ) : \$(OBJ)" >> Makefile
echo -e "\tg++ -o \$@ \$^ \$(LDFLAGS)" >> Makefile
echo -e "help : " >> Makefile
@@ -216,11 +216,14 @@
# echo -e "\t@if \$(CC) \$(CFLAGS) -c -o \$@ \$<; then echo -e \"[\$\\\\\\\\033[32mOK\\\\\\\\033[0m]\"; else echo -e \"[\\\\\\\\033[31mFAIL\\\\\\\\033[0m]\"; fi" >> Makefile
done
+echo "allmodules :" >> Makefile
+echo -ne "\t(cd modules&&make&&cd ..)\n" >> Makefile
echo "clean:" >> Makefile
echo -ne "\trm -f " >> Makefile
for i in $FOLDERS; do
echo -ne "$i/*.o $i/*~ $i/core.* " >>Makefile
done
echo "\$(PROJ) \$(PROJ).so" >> Makefile
+echo -ne "\trm -f modules/*.so modules/*.o modules/*~\n" >>Makefile
Modified: Mercury2/src/MercuryNode.h
===================================================================
--- Mercury2/src/MercuryNode.h 2009-05-26 02:23:47 UTC (rev 276)
+++ Mercury2/src/MercuryNode.h 2009-05-26 02:51:42 UTC (rev 277)
@@ -93,7 +93,7 @@
MercuryNode* FactoryFunct##class() { return new class(); } \
Callback0R<MercuryNode*> factoryclbk##class( FactoryFunct##class ); \
bool GlobalRegisterSuccess##class = NodeFactory::GetInstance().RegisterFactoryCallback(#class, factoryclbk##class); \
- extern "C" { int Install##class() { printf( "Installing "#class ); return NodeFactory::GetInstance().RegisterFactoryCallback(#class, factoryclbk##class); } }
+ extern "C" { int Install##class() { printf( "Installing "#class "\n" ); NodeFactory::GetInstance().RegisterFactoryCallback(#class, factoryclbk##class); return 0; } }
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2009-05-26 02:23:52
|
Revision: 276
http://hgengine.svn.sourceforge.net/hgengine/?rev=276&view=rev
Author: cnlohr
Date: 2009-05-26 02:23:47 +0000 (Tue, 26 May 2009)
Log Message:
-----------
modularize things
Modified Paths:
--------------
Mercury2/adv_set.c
Mercury2/src/Mercury2.cpp
Mercury2/src/MercuryNode.h
Mercury2/src/MercuryUtil.cpp
Mercury2/src/MercuryUtil.h
Added Paths:
-----------
Mercury2/modules/
Mercury2/modules/BillboardNode.cpp
Mercury2/modules/BillboardNode.h
Mercury2/modules/Makefile
Mercury2/modules.xml
Mercury2/src/MercuryHash.h
Mercury2/src/MercuryVector.h
Mercury2/src/ModuleManager.cpp
Mercury2/src/ModuleManager.h
Removed Paths:
-------------
Mercury2/src/BillboardNode.cpp
Mercury2/src/BillboardNode.h
Modified: Mercury2/adv_set.c
===================================================================
--- Mercury2/adv_set.c 2009-05-26 00:28:09 UTC (rev 275)
+++ Mercury2/adv_set.c 2009-05-26 02:23:47 UTC (rev 276)
@@ -11,7 +11,7 @@
src/HGMDLModel.cpp src/MercuryString.cpp src/MercuryCrash.c src/MercuryBacktrace.c \
src/MercuryFile.cpp src/MercuryTimer.cpp src/MercuryMessageManager.cpp src/MercuryVertex.cpp \
src/MercuryPlane.cpp src/BoundingBox.cpp src/Shader.cpp src/RenderGraph.cpp src/Frustum.cpp \
- src/BillboardNode.cpp src/Camera.cpp src/MercuryInput.cpp src/MQuaternion.cpp"
+ src/Camera.cpp src/MercuryInput.cpp src/MQuaternion.cpp src/ModuleManager.cpp"
SOURCES="$SOURCES src/MercuryFileDriverDirect.cpp src/MercuryFileDriverMem.cpp \
src/MercuryFileDriverPacked.cpp src/MercuryFileDriverZipped.cpp"
Added: Mercury2/modules/BillboardNode.cpp
===================================================================
--- Mercury2/modules/BillboardNode.cpp (rev 0)
+++ Mercury2/modules/BillboardNode.cpp 2009-05-26 02:23:47 UTC (rev 276)
@@ -0,0 +1,95 @@
+#include "BillboardNode.h"
+#include <MercuryVertex.h>
+#include <Viewport.h>
+
+REGISTER_NODE_TYPE(BillboardNode);
+
+MercuryMatrix BillboardNode::ManipulateMatrix(const MercuryMatrix& matrix)
+{
+ MercuryMatrix m = RenderableNode::ManipulateMatrix( matrix );
+
+ //Compute the object's center point (position?) in world space
+ MercuryVertex center(0,0,0,1);
+ center = matrix * center;
+
+ MercuryVector objToEye = (EYE - center);
+ MercuryVector objToEyeProj( objToEye );
+
+ //vector from object to eye projected on XZ
+ objToEyeProj[1] = 0; objToEyeProj.NormalizeSelf();
+
+// MercuryVector objLookAt(0,0,1); //origional look vector of object
+// objLookAt = matrix * objLookAt; //convert to world space
+// objLookAt.NormalizeSelf();
+
+// objLookAt.Print();
+
+// MercuryVector up = (objLookAt.CrossProduct( objToEyeProj )).Normalize();
+// up = objLookAt;
+// up.Print();
+
+ MercuryVector up(0,0,1); //we wan't the camera's up
+
+ float angleCos = LOOKAT.DotProduct(objToEyeProj);
+
+ if ((angleCos < 0.99990) && (angleCos > -0.9999))
+ {
+ float f = ACOS(angleCos)*RADDEG;
+ MercuryMatrix mtmp;
+ mtmp.RotateAngAxis(f, up[0], up[1], up[2]);
+ m = m * mtmp;
+ }
+
+ //spherical below
+ objToEye.NormalizeSelf();
+ angleCos = objToEyeProj.DotProduct( objToEye );
+ if ((angleCos < 0.99990) && (angleCos > -0.9999))
+ {
+ printf("%f\n", angleCos);
+ float f = ACOS(angleCos)*RADDEG;
+ MercuryMatrix mtmp;
+ if (objToEye[1] < 0)
+ mtmp.RotateAngAxis(f, 1, 0, 0);
+ else
+ mtmp.RotateAngAxis(f, -1, 0, 0);
+// m.Print();
+ m = m * mtmp;
+// m.Print();
+ printf("********************\n");
+// mtmp.Print();
+ }
+
+ return m;
+}
+
+/****************************************************************************
+ * Copyright (C) 2009 by Joshua Allen *
+ * *
+ * *
+ * 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/modules/BillboardNode.h
===================================================================
--- Mercury2/modules/BillboardNode.h (rev 0)
+++ Mercury2/modules/BillboardNode.h 2009-05-26 02:23:47 UTC (rev 276)
@@ -0,0 +1,47 @@
+#ifndef BILLBOARDNODE_H
+#define BILLBOARDNODE_H
+
+#include <RenderableNode.h>
+
+class BillboardNode : public RenderableNode
+{
+ public:
+ virtual MercuryMatrix ManipulateMatrix(const MercuryMatrix& matrix);
+
+ private:
+};
+
+#endif
+
+
+/****************************************************************************
+ * Copyright (C) 2009 by Joshua Allen *
+ * *
+ * *
+ * 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/modules/Makefile
===================================================================
--- Mercury2/modules/Makefile (rev 0)
+++ Mercury2/modules/Makefile 2009-05-26 02:23:47 UTC (rev 276)
@@ -0,0 +1,12 @@
+CFLAGS=-O2 -g0 -Wall -I/usr/include/libxml2 -DHAVE_CONFIG -DHGENGINE -fno-exceptions -fPIC -I../src -g
+CXXFLAGS=${CFLAGS}
+LDFLAGS=-shared
+
+all : BillboardNode.so
+
+clean :
+ rm -rf *~ *.o *.so
+
+BillboardNode.so : BillboardNode.o
+ g++ -o$@ $^ ${LDFLAGS}
+
Added: Mercury2/modules.xml
===================================================================
--- Mercury2/modules.xml (rev 0)
+++ Mercury2/modules.xml 2009-05-26 02:23:47 UTC (rev 276)
@@ -0,0 +1,3 @@
+<Modules>
+ <Module src="modules/BillboardNode.c" obj="modules/BillboardNode" func="InstallBillboardNode" />
+</Modules>
Deleted: Mercury2/src/BillboardNode.cpp
===================================================================
--- Mercury2/src/BillboardNode.cpp 2009-05-26 00:28:09 UTC (rev 275)
+++ Mercury2/src/BillboardNode.cpp 2009-05-26 02:23:47 UTC (rev 276)
@@ -1,95 +0,0 @@
-#include <BillboardNode.h>
-#include <MercuryVertex.h>
-#include <Viewport.h>
-
-REGISTER_NODE_TYPE(Billboard);
-
-MercuryMatrix Billboard::ManipulateMatrix(const MercuryMatrix& matrix)
-{
- MercuryMatrix m = RenderableNode::ManipulateMatrix( matrix );
-
- //Compute the object's center point (position?) in world space
- MercuryVertex center(0,0,0,1);
- center = matrix * center;
-
- MercuryVector objToEye = (EYE - center);
- MercuryVector objToEyeProj( objToEye );
-
- //vector from object to eye projected on XZ
- objToEyeProj[1] = 0; objToEyeProj.NormalizeSelf();
-
-// MercuryVector objLookAt(0,0,1); //origional look vector of object
-// objLookAt = matrix * objLookAt; //convert to world space
-// objLookAt.NormalizeSelf();
-
-// objLookAt.Print();
-
-// MercuryVector up = (objLookAt.CrossProduct( objToEyeProj )).Normalize();
-// up = objLookAt;
-// up.Print();
-
- MercuryVector up(0,0,1); //we wan't the camera's up
-
- float angleCos = LOOKAT.DotProduct(objToEyeProj);
-
- if ((angleCos < 0.99990) && (angleCos > -0.9999))
- {
- float f = ACOS(angleCos)*RADDEG;
- MercuryMatrix mtmp;
- mtmp.RotateAngAxis(f, up[0], up[1], up[2]);
- m = m * mtmp;
- }
-
- //spherical below
- objToEye.NormalizeSelf();
- angleCos = objToEyeProj.DotProduct( objToEye );
- if ((angleCos < 0.99990) && (angleCos > -0.9999))
- {
- printf("%f\n", angleCos);
- float f = ACOS(angleCos)*RADDEG;
- MercuryMatrix mtmp;
- if (objToEye[1] < 0)
- mtmp.RotateAngAxis(f, 1, 0, 0);
- else
- mtmp.RotateAngAxis(f, -1, 0, 0);
-// m.Print();
- m = m * mtmp;
-// m.Print();
- printf("********************\n");
-// mtmp.Print();
- }
-
- return m;
-}
-
-/****************************************************************************
- * Copyright (C) 2009 by Joshua Allen *
- * *
- * *
- * 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. *
- ***************************************************************************/
Deleted: Mercury2/src/BillboardNode.h
===================================================================
--- Mercury2/src/BillboardNode.h 2009-05-26 00:28:09 UTC (rev 275)
+++ Mercury2/src/BillboardNode.h 2009-05-26 02:23:47 UTC (rev 276)
@@ -1,47 +0,0 @@
-#ifndef BILLBOARDNODE_H
-#define BILLBOARDNODE_H
-
-#include <RenderableNode.h>
-
-class Billboard : public RenderableNode
-{
- public:
- virtual MercuryMatrix ManipulateMatrix(const MercuryMatrix& matrix);
-
- private:
-};
-
-#endif
-
-
-/****************************************************************************
- * Copyright (C) 2009 by Joshua Allen *
- * *
- * *
- * 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/Mercury2.cpp
===================================================================
--- Mercury2/src/Mercury2.cpp 2009-05-26 00:28:09 UTC (rev 275)
+++ Mercury2/src/Mercury2.cpp 2009-05-26 02:23:47 UTC (rev 276)
@@ -16,6 +16,7 @@
#include <RenderGraph.h>
#include <Texture.h>
#include <GLHeaders.h>
+#include <ModuleManager.h>
bool SHOWBOUNDINGVOLUME = false;
@@ -52,13 +53,14 @@
SetupOGLExtensions();
#endif
+ ModuleManager::GetInstance().InitializeAllModules();
+
MercuryNode* root = new MercuryNode();
XMLDocument* doc = XMLDocument::Load("scenegraph.xml");
-
XMLNode r = doc->GetRootNode();
root->LoadFromXML( r );
-
+
SAFE_DELETE(doc);
MercuryTimer timer;
Added: Mercury2/src/MercuryHash.h
===================================================================
--- Mercury2/src/MercuryHash.h (rev 0)
+++ Mercury2/src/MercuryHash.h 2009-05-26 02:23:47 UTC (rev 276)
@@ -0,0 +1,254 @@
+#ifndef MERCURYHASH_H
+#define MERCURYHASH_H
+
+#include "global.h"
+#include <MercuryVector.h>
+
+///Mercury Hash Table for Strings
+template<typename T>
+class MHash
+{
+public:
+ MHash( ) : m_iSize( GetAPrime( m_iPrimest = 1 ) )
+ {
+ m_pTable = new MHashNode<T> * [m_iSize]; ///XXX what? and how does this affect delete?
+ memset( m_pTable, 0, m_iSize * sizeof( MHashNode<T>* ) );
+ m_iCount = 0;
+ }
+
+ MHash( const MHash & rhs )
+ {
+ m_iPrimest = rhs.m_iPrimest;
+ m_iCount = rhs.m_iCount;
+ m_pTable = new MHashNode<T> * [rhs.m_iSize];
+ m_iSize = rhs.m_iSize;
+
+ memset( m_pTable, 0, m_iSize * sizeof( MHashNode<T>* ) );
+
+ for( unsigned i = 0; i < m_iSize; ++i )
+ {
+ MHashNode <T> * TMP = rhs.m_pTable[i];
+ while (TMP)
+ {
+ m_pTable[i] = new MHashNode<T>( m_pTable[i], TMP->Index, TMP->Data );
+ TMP = TMP->Next;
+ }
+ }
+ }
+
+ MHash & operator = ( const MHash & rhs )
+ {
+ m_iPrimest = rhs.m_iPrimest;
+ m_iCount = rhs.m_iCount;
+ m_pTable = new MHashNode<T> * [rhs.m_iSize];
+ m_iSize = rhs.m_iSize;
+
+ memset( m_pTable, 0, m_iSize * sizeof( MHashNode<T>* ) );
+
+ for( unsigned i = 0; i < m_iSize; ++i )
+ {
+ MHashNode <T> * TMP = rhs.m_pTable[i];
+ while (TMP)
+ {
+ m_pTable[i] = new MHashNode<T>( m_pTable[i], TMP->Index, TMP->Data );
+ TMP = TMP->Next;
+ }
+ }
+ return *this;
+ }
+
+ void resize( int iNewSize )
+ {
+ MHashNode <T> ** pOldTable = m_pTable;
+ int iOldSize = m_iSize;
+
+ m_pTable = new MHashNode<T> * [iNewSize];
+ m_iSize = iNewSize;
+ memset( m_pTable, 0, iNewSize * sizeof( MHashNode<T>* ) );
+
+ for( int i = 0; i < iOldSize; ++i )
+ {
+ while (pOldTable[i])
+ {
+ MHashNode <T> * TMP = pOldTable[i];
+ pOldTable[i] = TMP->Next;
+
+ int iNewHash = TMP->Index.hash();
+ MHashNode <T> * TMP2 = m_pTable[iNewHash%m_iSize];
+ m_pTable[iNewHash%m_iSize] = TMP;
+ TMP->Next = TMP2;
+ }
+ }
+
+ //I think a delete[] is OK here because its an allocated array of pointers. No destructors are called
+ SAFE_DELETE_ARRAY(pOldTable);
+ }
+
+ ~MHash()
+ {
+ for( unsigned i = 0; i < m_iSize; ++i )
+ while (m_pTable[i])
+ {
+ MHashNode <T> * TMP = m_pTable[i];
+ m_pTable[i] = TMP->Next;
+ SAFE_DELETE( TMP );
+ }
+ SAFE_DELETE_ARRAY( m_pTable );
+ }
+
+ void clear()
+ {
+ for( unsigned i = 0; i < m_iSize; ++i )
+ {
+ while (m_pTable[i])
+ {
+ MHashNode <T> * TMP = m_pTable[i];
+ m_pTable[i] = TMP->Next;
+ SAFE_DELETE( TMP );
+ }
+ m_pTable[i] = 0;
+ }
+ m_iCount = 0;
+ }
+
+ ///Return reference to data in the index's cell, if no data exists, it is generated
+ T & operator[]( const MString & pIndex )
+ {
+ unsigned int iHash = pIndex.hash();
+ MHashNode<T> * m_pTmp = m_pTable[iHash%m_iSize];
+
+ while( m_pTmp )
+ if( m_pTmp->Index == pIndex )
+ return m_pTmp->Data;
+ else
+ m_pTmp = m_pTmp->Next;
+
+ insert( pIndex, T() );
+
+ m_pTmp = m_pTable[iHash%m_iSize];
+
+ while( m_pTmp )
+ if( m_pTmp->Index == pIndex )
+ return m_pTmp->Data;
+ else
+ m_pTmp = m_pTmp->Next;
+
+ //This should NEVER HAPPEN.
+ assert( "FAIL! Hash insertion failed!" );
+ return m_pNil;
+ }
+
+ ///Insert pData into pIndex's cell
+ void insert( const MString & pIndex, const T & pData )
+ {
+ unsigned int iHash = pIndex.hash();
+ m_pTable[iHash%m_iSize] = new MHashNode<T>( m_pTable[iHash%m_iSize], pIndex, pData );
+
+ if( ++m_iCount > m_iSize + 5 )
+ resize( GetAPrime( ++m_iPrimest ) );
+ }
+
+ ///Get pointer to pIndex's cell, if no data exists, NULL is returned.
+ T * get( const MString & pIndex )
+ {
+ unsigned int iHash = pIndex.hash();
+ MHashNode<T> * m_pTmp = m_pTable[iHash%m_iSize];
+
+ while( m_pTmp )
+ if( m_pTmp->Index == pIndex )
+ return &m_pTmp->Data;
+ else
+ m_pTmp = m_pTmp->Next;
+
+ return 0;
+ }
+
+ bool remove( const MString & pIndex )
+ {
+ unsigned int iHash = pIndex.hash();
+ MHashNode<T> * m_pPrev = 0;
+ MHashNode<T> * m_pTmp = m_pTable[iHash%m_iSize];
+
+ while( m_pTmp )
+ if( m_pTmp->Index == pIndex )
+ {
+ if( m_pPrev )
+ m_pPrev->Next = m_pTmp->Next;
+ else
+ m_pTable[iHash%m_iSize] = m_pTable[iHash%m_iSize]->Next;
+ SAFE_DELETE( m_pTmp );
+ m_iCount--;
+ return true;
+ }
+ else
+ {
+ m_pPrev = m_pTmp;
+ m_pTmp = m_pTmp->Next;
+ }
+
+ return false;
+ }
+
+ void VectorIndicies( MVector < MString > & vOut )
+ {
+ unsigned int i;
+ MHashNode<T> * m_pTmp;
+ for( i = 0; i < m_iSize; i++ )
+ {
+ m_pTmp = m_pTable[i];
+ while( m_pTmp )
+ {
+ vOut.push_back( m_pTmp->Index );
+ m_pTmp = m_pTmp->Next;
+ }
+ }
+ }
+
+private:
+ template<typename TC>
+ struct MHashNode
+ {
+ MHashNode() : Next(0) { }
+ MHashNode( MHashNode<TC> * pA, const MString & pIn, const TC & pD ) : Next( pA ), Index( pIn ), Data( pD ) { }
+
+ MHashNode <TC> * Next;
+ MString Index;
+ TC Data;
+ };
+
+ MHashNode <T> ** m_pTable;
+ T m_pNil;
+ unsigned int m_iSize;
+ unsigned int m_iPrimest;
+ unsigned int m_iCount;
+};
+
+#endif
+
+/*
+ * Copyright (c) 2006-2009 Joshua Allen, Charles Lohr
+ * 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/MercuryNode.h
===================================================================
--- Mercury2/src/MercuryNode.h 2009-05-26 00:28:09 UTC (rev 275)
+++ Mercury2/src/MercuryNode.h 2009-05-26 02:23:47 UTC (rev 276)
@@ -92,8 +92,10 @@
#define REGISTER_NODE_TYPE(class)\
MercuryNode* FactoryFunct##class() { return new class(); } \
Callback0R<MercuryNode*> factoryclbk##class( FactoryFunct##class ); \
- bool GlobalRegisterSuccess##class = NodeFactory::GetInstance().RegisterFactoryCallback(#class, factoryclbk##class);
+ bool GlobalRegisterSuccess##class = NodeFactory::GetInstance().RegisterFactoryCallback(#class, factoryclbk##class); \
+ extern "C" { int Install##class() { printf( "Installing "#class ); return NodeFactory::GetInstance().RegisterFactoryCallback(#class, factoryclbk##class); } }
+
#endif
/***************************************************************************
Modified: Mercury2/src/MercuryUtil.cpp
===================================================================
--- Mercury2/src/MercuryUtil.cpp 2009-05-26 00:28:09 UTC (rev 275)
+++ Mercury2/src/MercuryUtil.cpp 2009-05-26 02:23:47 UTC (rev 276)
@@ -80,26 +80,36 @@
return length;
}
-/***************************************************************************
- * Copyright (C) 2008 by Joshua Allen *
- * *
- * *
- * 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 <ORGANIZATION> 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. *
- ***************************************************************************/
+int GeneralUsePrimes[] = { 3, 13, 37, 73, 131, 229, 337, 821, 2477, 4594, 8941, 14797, 24953, 39041, 60811, 104729 };
+
+int GetAPrime( int ith )
+{
+ return (ith<0)?3:(ith>15)?GeneralUsePrimes[15]:GeneralUsePrimes[ith];
+}
+
+/* Copyright (c) 2009, Joshua Allen and Charles Lohr
+ * 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/MercuryUtil.h
===================================================================
--- Mercury2/src/MercuryUtil.h 2009-05-26 00:28:09 UTC (rev 275)
+++ Mercury2/src/MercuryUtil.h 2009-05-26 02:23:47 UTC (rev 276)
@@ -85,9 +85,20 @@
///The return value is -1 if there was an issue, otherwise it is valid.
long FileToString( const MString & sFileName, char * & data );
+/* These two functions are very different */
+/// nextPow2 will go to the NEXT power of 2 even if x is already a power of 2.
+inline int nextPow2(int x) { int num = 1; while(num <= x) num <<= 1; return num; }
+///makePow2 will make sure the number is a power of 2 at least equal to x.
+inline int makePow2(int x) { int num = 1; while(num < x) num <<= 1; return num; }
+inline bool isPow2(int x) { int num = 1; while(num < x) num<<=1; return num==x; }
+
+///Return a prime number. Note this is NOT sequential. The general(but not guarenteed)
+///pattern is the next prime number that's roughly two times the last.
+int GetAPrime( int ith );
+
#endif
-/* Copyright (c) 2008, Joshua Allen
+/* Copyright (c) 2009, Joshua Allen and Charles Lohr
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
Added: Mercury2/src/MercuryVector.h
===================================================================
--- Mercury2/src/MercuryVector.h (rev 0)
+++ Mercury2/src/MercuryVector.h 2009-05-26 02:23:47 UTC (rev 276)
@@ -0,0 +1,233 @@
+#ifndef _MERCURY_VECTOR_H
+#define _MERCURY_VECTOR_H
+
+#include <string.h>
+
+///Stripped down and fast vector class
+template<typename T>
+class MVector
+{
+ public:
+ MVector()
+ :m_reserved(0), m_size(0), m_data(0)
+ { }
+ ~MVector()
+ {
+ clear();
+ }
+ MVector(const MVector<T>& v)
+ :m_reserved(v.m_reserved), m_size(v.m_size)
+ {
+ m_data = (T*)malloc(sizeof(T)*m_reserved);
+ for (unsigned int i = 0; i < m_size; ++i)
+ {
+ new( &m_data[i] ) T (v.m_data[i]);
+ #if defined( _DEBUG_MEMORY )
+ MercuryAFree( &m_data[i] );
+ #endif
+ }
+ }
+ void push_back(const T& element);
+ inline unsigned int size() const { return m_size; }
+ inline bool empty() const { return m_size == 0; }
+ void resize(unsigned int newSize);
+ void reserve(unsigned int newSize);
+ inline T& operator[](unsigned int x) { return m_data[x]; }
+ inline const T& operator[](unsigned int x) const { return m_data[x]; }
+ inline T& at( unsigned int x ) { return m_data[x]; }
+ inline const T& at( unsigned int x ) const { return m_data[x]; }
+ const MVector<T>& operator=(const MVector<T>& v);
+ void clear();
+ void remove( int iPlace );
+ void insert( int iPlace, const T & data );
+ private:
+ unsigned int m_reserved; //available space
+ unsigned int m_size; //number of valid (constructed) objects
+ T * m_data;
+};
+
+#include "MercuryUtil.h"
+
+template<typename T>
+void MVector<T>::push_back(const T& element)
+{
+ if (m_size >= m_reserved)
+ {
+ if (m_reserved <= 0)
+ {
+ SAFE_FREE( m_data );
+ m_data = (T*)malloc(sizeof(T));
+ m_reserved = 1;
+ }
+ else
+ {
+ int tsize = nextPow2(m_reserved);
+ int size = m_size;
+ reserve(tsize);
+ m_size = size;
+ }
+ }
+
+ new( &m_data[m_size] ) T ( element );
+
+ ++m_size;
+}
+
+template<typename T>
+void MVector<T>::resize(unsigned int newSize)
+{
+ if (newSize == 0)
+ {
+ clear();
+ return;
+ }
+ //Fully reserve space and initalize constructors
+ //Make larger and reserve space
+ if (newSize == m_size)
+ {
+ return;
+ }
+ else if(newSize > m_size)
+ {
+ if (newSize > m_reserved)
+ {
+ m_reserved = newSize;
+ m_data = (T*)realloc(m_data, sizeof(T)*m_reserved);
+ }
+
+ for (unsigned int i = m_size; i < newSize; ++i)
+ {
+ new (&m_data[i]) (T);
+ #if defined( _DEBUG_MEMORY )
+ MercuryAFree( &m_data[i] );
+ #endif
+
+ }
+ }
+ else
+ {
+ //get smaller
+ m_reserved = newSize;
+
+ //destroy data that will be lost
+ for (unsigned int i = m_reserved; i < m_size; ++i)
+ (&m_data[i])->~T();
+
+ m_data = (T*)realloc(m_data, sizeof(T)*m_reserved);
+ }
+ m_size = newSize;
+}
+
+template<typename T>
+void MVector<T>::reserve(unsigned int newSize)
+{
+ if (newSize == 0)
+ {
+ clear();
+ return;
+ }
+ if (newSize == m_reserved)
+ {
+ return;
+ }
+ else if (newSize > m_reserved)
+ {
+ m_reserved = newSize;
+ m_data = (T*)realloc(m_data, sizeof(T)*m_reserved);
+ }
+ else
+ {
+ m_reserved = newSize;
+
+ //destroy data that will be lost
+ for (unsigned int i = m_reserved; i < m_size; ++i)
+ (&m_data[i])->~T();
+
+ m_data = (T*)realloc(m_data, sizeof(T)*m_reserved);
+ m_size = newSize;
+ }
+}
+
+template<typename T>
+void MVector<T>::remove( int iPlace )
+{
+ m_size--;
+ (&m_data[iPlace])->~T();
+ for (unsigned long i = iPlace; i < m_size; ++i)
+ memcpy( &m_data[i], &m_data[i+1], sizeof(T) );
+}
+
+#include <stdio.h>
+#include <new>
+template<typename T>
+void MVector<T>::insert( int iPlace, const T & data )
+{
+ int i;
+ resize( m_size + 1 );
+
+ (&m_data[m_size-1])->~T();
+ for( i = m_size - 1; i > iPlace; i-- )
+ memcpy( &m_data[i], &m_data[i-1], sizeof (T) );
+
+ new ( &m_data[iPlace] ) T( data );
+ #if defined( _DEBUG_MEMORY )
+ MercuryAFree( &m_data[iPlace] );
+ #endif
+
+}
+
+template<typename T>
+void MVector<T>::clear()
+{
+ for (unsigned int i = 0; i < m_size; ++i)
+ (&m_data[i])->~T();
+
+ SAFE_FREE(m_data);
+ m_size = m_reserved = 0;
+}
+template<typename T>
+const MVector<T>& MVector<T>::operator=(const MVector<T>& v)
+{
+ clear();
+ m_reserved = v.m_reserved;
+ m_size = v.m_size;
+ m_data = (T*)malloc(sizeof(T)*m_reserved);
+ for (unsigned int i = 0; i < m_size; ++i)
+ {
+ new( &m_data[i]) T( v.m_data[i] );
+#if defined( _DEBUG_MEMORY )
+ MercuryAFree( &m_data[i] );
+#endif
+ }
+ return *this;
+}
+
+
+#endif
+/*
+ * Copyright (c) 2006-2009 Joshua Allen, Charles Lohr
+ * 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/ModuleManager.cpp
===================================================================
--- Mercury2/src/ModuleManager.cpp (rev 0)
+++ Mercury2/src/ModuleManager.cpp 2009-05-26 02:23:47 UTC (rev 276)
@@ -0,0 +1,125 @@
+#include <ModuleManager.h>
+#include <XMLParser.h>
+
+#ifndef WIN32
+#include <dlfcn.h>
+#else
+#include <windows.h>
+
+//These are only synonyms for the POSIX stuff.
+#define RTLD_NOW 0
+#define RTLD_GLOBAL 0
+
+void * dlopen( const char * sFile, int dummy ) { return LoadLibrary( sFile ); }
+void dlclose( void * handle ) { FreeLibrary( (HMODULE)handle ); }
+void * dlsym( void * handle, const char * sym ) { return GetProcAddress( (HMODULE) handle, sym ); }
+
+#endif
+
+
+extern "C"
+{
+typedef int (*LoaderFunction)();
+};
+
+ModuleManager::ModuleManager()
+{
+}
+
+ModuleManager & ModuleManager::GetInstance()
+{
+ static ModuleManager *instance = NULL;
+ if (!instance)
+ instance = new ModuleManager();
+ return *instance;
+}
+
+void ModuleManager::InitializeAllModules()
+{
+ XMLDocument* doc = XMLDocument::Load("modules.xml");
+ XMLNode r = doc->GetRootNode();
+ for (XMLNode child = r.Child(); child.IsValid(); child = r.NextNode())
+ {
+ if( child.Name() != "Module" )
+ {
+ fprintf( stderr, "Invalid element in modules: %s\n", child.Name().c_str() );
+ }
+#ifdef WIN32
+ MString ModuleName = child.Attribute( "obj" ) + ".dll";
+#else
+ MString ModuleName = child.Attribute( "obj" ) + ".so";
+#endif
+ MString LoadFunct = child.Attribute( "func" );
+ LoadModule( ModuleName, LoadFunct );
+ }
+}
+
+void ModuleManager::UnloadModule( const MString & ModuleName )
+{
+ if( m_hAllHandles[ModuleName] )
+ dlclose( m_hAllHandles[ModuleName] );
+}
+
+bool ModuleManager::LoadModule( const MString & ModuleName, const MString & LoadFunction )
+{
+ if( m_hAllHandles[ModuleName] ) UnloadModule( ModuleName );
+ m_hAllHandles[ModuleName] = dlopen( ModuleName.c_str(), RTLD_NOW | RTLD_GLOBAL );
+
+ if( !m_hAllHandles[ModuleName] )
+ {
+ fprintf( stderr, "Error opening: %s\n", ModuleName.c_str() );
+ return false;
+ }
+
+ //If no load funct, just exit early.
+ if( LoadFunction == "" )
+ return true;
+
+ LoaderFunction T = (LoaderFunction)dlsym( m_hAllHandles[ModuleName], LoadFunction.c_str() );
+ if( !T )
+ {
+ fprintf( stderr, "Error finding: %s() in %s\n", LoadFunction.c_str(), ModuleName.c_str() );
+ return false;
+ }
+
+ int ret = T();
+ if( ret )
+ {
+ fprintf( stderr, "Error executing (Returned error %d): %s() in %s\n", ret, LoadFunction.c_str(), ModuleName.c_str() );
+ return false;
+ }
+
+ return true;
+}
+
+/****************************************************************************
+ * Copyright (C) 2009 by Charles Lohr *
+ * *
+ * *
+ * 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/ModuleManager.h
===================================================================
--- Mercury2/src/ModuleManager.h (rev 0)
+++ Mercury2/src/ModuleManager.h 2009-05-26 02:23:47 UTC (rev 276)
@@ -0,0 +1,59 @@
+#ifndef _MODULE_LOADER_H
+#define _MODULE_LOADER_H
+
+#include <MercuryUtil.h>
+#include <MercuryHash.h>
+
+/* This is the module loader mechanism. This allows for run-time loading of
+ new modules. Eventually, it will allow for run-time re-loading of modules.
+ For now, it uses modules to determine what to load at startup. */
+
+class ModuleManager
+{
+public:
+ ModuleManager();
+ static ModuleManager & GetInstance();
+ void InitializeAllModules();
+
+ bool LoadModule( const MString & ModuleName, const MString & LoadFunction );
+ void UnloadModule( const MString & ModuleName );
+ MHash< void * > m_hAllHandles;
+};
+
+static InstanceCounter<ModuleManager> ModMancounter("ModuleManager");
+
+
+
+/****************************************************************************
+ * Copyright (C) 2009 by Charles Lohr *
+ * *
+ * *
+ * 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. *
+ ***************************************************************************/
+
+#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-05-26 01:14:47
|
Revision: 275
http://hgengine.svn.sourceforge.net/hgengine/?rev=275&view=rev
Author: axlecrusher
Date: 2009-05-26 00:28:09 +0000 (Tue, 26 May 2009)
Log Message:
-----------
capture mouse button
Modified Paths:
--------------
Mercury2/src/MercuryInput.cpp
Mercury2/src/MercuryInput.h
Mercury2/src/X11Window.cpp
Modified: Mercury2/src/MercuryInput.cpp
===================================================================
--- Mercury2/src/MercuryInput.cpp 2009-05-26 00:27:12 UTC (rev 274)
+++ Mercury2/src/MercuryInput.cpp 2009-05-26 00:28:09 UTC (rev 275)
@@ -6,12 +6,20 @@
{
}
-void MouseInput::ProcessMouseInput(int dx, int dy)
+void MouseInput::ProcessMouseInput(int dx, int dy, bool leftButton, bool rightButton, bool centerButton)
{
MouseInput* mi = new MouseInput();
mi->dx = dx;
mi->dy = dy;
+ uint8_t buttonMasks = 0;
+ buttonMasks |= (leftButton << MB_LEFT); //enable if true
+ buttonMasks |= (rightButton << MB_RIGHT); //enable if true
+ buttonMasks |= (centerButton << MB_CENTER); //enable if true
+ mi->buttonMasks = buttonMasks;
+
+ currentButtonMasks = buttonMasks;
+
POST_MESSAGE( INPUTEVENT_MOUSE, mi, 0 );
}
@@ -57,6 +65,7 @@
uint8_t KeyboardInput::m_keyStates[512];
+uint8_t MouseInput::currentButtonMasks;
/****************************************************************************
Modified: Mercury2/src/MercuryInput.h
===================================================================
--- Mercury2/src/MercuryInput.h 2009-05-26 00:27:12 UTC (rev 274)
+++ Mercury2/src/MercuryInput.h 2009-05-26 00:28:09 UTC (rev 275)
@@ -6,18 +6,24 @@
const MString INPUTEVENT_MOUSE = "MouseInputEvent";
const MString INPUTEVENT_KEYBOARD = "KeyboardInputEvent";
+enum MouseButton
+{
+ MB_NONE = 0,
+ MB_LEFT = 1,
+ MB_RIGHT = 2,
+ MB_CENTER = 3
+};
+
class MouseInput : public MessageData
{
public:
- static const uint8_t LEFTBUTTON = 1;
- static const uint8_t RIGHTBUTTON = 2;
- static const uint8_t CENTERBUTTON = 4;
+ static void ProcessMouseInput(int dx, int dy, bool leftButton, bool rightButton, bool centerButton);
- static void ProcessMouseInput(int x, int y);
-
MouseInput();
int32_t dx, dy;
uint8_t buttonMasks;
+ private:
+ static uint8_t currentButtonMasks;
};
class KeyboardInput : public MessageData
Modified: Mercury2/src/X11Window.cpp
===================================================================
--- Mercury2/src/X11Window.cpp 2009-05-26 00:27:12 UTC (rev 274)
+++ Mercury2/src/X11Window.cpp 2009-05-26 00:28:09 UTC (rev 275)
@@ -143,13 +143,10 @@
switch (event.type)
{
case ButtonPress:
- {
- XButtonEvent* e = (XButtonEvent*)&event;
- break;
- }
case ButtonRelease:
{
XButtonEvent* e = (XButtonEvent*)&event;
+ MouseInput::ProcessMouseInput(0, 0, e->button & Button1, e->button & Button3, e->button & Button2);
break;
}
case KeyPress:
@@ -172,11 +169,16 @@
{
XMotionEvent* e = (XMotionEvent*)&event;
int x, y;
+ bool left, right, center;
+ left = e->state & Button1Mask;
+ right = e->state & Button3Mask;
+ center = e->state & Button2Mask;
x = m_width/2 - e->x;
y = m_height/2 - e->y;
if (x!=0 || y!=0) //prevent recursive XWarp
{
- MouseInput::ProcessMouseInput(x, y);
+ MouseInput::ProcessMouseInput(x, y,
+ left, right, center);
XWarpPointer(m_display, None, m_window, 0,0,0,0,m_width/2,m_height/2);
}
break;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-05-26 01:14:36
|
Revision: 274
http://hgengine.svn.sourceforge.net/hgengine/?rev=274&view=rev
Author: axlecrusher
Date: 2009-05-26 00:27:12 +0000 (Tue, 26 May 2009)
Log Message:
-----------
fix bug
Modified Paths:
--------------
Mercury2/src/MQuaternion.cpp
Modified: Mercury2/src/MQuaternion.cpp
===================================================================
--- Mercury2/src/MQuaternion.cpp 2009-05-22 01:31:33 UTC (rev 273)
+++ Mercury2/src/MQuaternion.cpp 2009-05-26 00:27:12 UTC (rev 274)
@@ -3,10 +3,10 @@
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;
+ m_xyzw[0] = X;
+ m_xyzw[1] = Y;
+ m_xyzw[2] = Z;
+ m_xyzw[3] = W;
}
MQuaternion::MQuaternion(float* xyzw)
@@ -25,14 +25,7 @@
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.
+ return m_xyzw[i];
}
void MQuaternion::SetEuler(const MercuryVector& angles)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-05-22 02:09:35
|
Revision: 273
http://hgengine.svn.sourceforge.net/hgengine/?rev=273&view=rev
Author: axlecrusher
Date: 2009-05-22 01:31:33 +0000 (Fri, 22 May 2009)
Log Message:
-----------
remove duplicate
Modified Paths:
--------------
Mercury2/src/TransformNode.cpp
Modified: Mercury2/src/TransformNode.cpp
===================================================================
--- Mercury2/src/TransformNode.cpp 2009-05-22 01:29:34 UTC (rev 272)
+++ Mercury2/src/TransformNode.cpp 2009-05-22 01:31:33 UTC (rev 273)
@@ -68,7 +68,6 @@
while (n)
{
tn = TransformNode::Cast( n );
- tn = TransformNode::Cast( n );
if ( tn ) return tn->GetGlobalMatrix();
n = n->Parent();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-05-22 01:29:36
|
Revision: 272
http://hgengine.svn.sourceforge.net/hgengine/?rev=272&view=rev
Author: axlecrusher
Date: 2009-05-22 01:29:34 +0000 (Fri, 22 May 2009)
Log Message:
-----------
quaternion
Modified Paths:
--------------
Mercury2/adv_set.c
Mercury2/scenegraph.xml
Modified: Mercury2/adv_set.c
===================================================================
--- Mercury2/adv_set.c 2009-05-22 01:28:54 UTC (rev 271)
+++ Mercury2/adv_set.c 2009-05-22 01:29:34 UTC (rev 272)
@@ -11,7 +11,7 @@
src/HGMDLModel.cpp src/MercuryString.cpp src/MercuryCrash.c src/MercuryBacktrace.c \
src/MercuryFile.cpp src/MercuryTimer.cpp src/MercuryMessageManager.cpp src/MercuryVertex.cpp \
src/MercuryPlane.cpp src/BoundingBox.cpp src/Shader.cpp src/RenderGraph.cpp src/Frustum.cpp \
- src/BillboardNode.cpp src/Camera.cpp"
+ src/BillboardNode.cpp src/Camera.cpp src/MercuryInput.cpp src/MQuaternion.cpp"
SOURCES="$SOURCES src/MercuryFileDriverDirect.cpp src/MercuryFileDriverMem.cpp \
src/MercuryFileDriverPacked.cpp src/MercuryFileDriverZipped.cpp"
Modified: Mercury2/scenegraph.xml
===================================================================
--- Mercury2/scenegraph.xml 2009-05-22 01:28:54 UTC (rev 271)
+++ Mercury2/scenegraph.xml 2009-05-22 01:29:34 UTC (rev 272)
@@ -1,7 +1,10 @@
<SceneGraph>
- <node type="cameranode" movx="6" movz="-5.5" movy="3" rotx="-45" roty="90">
+<!-- <node type="cameranode" movx="6" movz="-5.5" movy="3" rotx="-45" roty="90">
<node type="viewport" fov="45" aspect="1.3333" near="0.01" far="100"/>
</node>
+--> <node type="cameranode" movx="0" movz="0" movy="0" rotx="0" roty="0" rotz="0">
+ <node type="viewport" fov="45" aspect="1.3333" near="0.01" far="100"/>
+ </node>
<node type="transformnode" rotx="-90" movz="-10" movx="0" movy="-5">
<node type="renderablenode">
<asset type="texture" file="map.png"/>
@@ -12,7 +15,7 @@
<asset type="texture" file="lamp.png"/>
<node type="transformnode" movz="-5" movx="0" movy="0" name="lamprow" >
<node type="transformnode" rotx="-90" name="lamp">
- <node type="billboard" >
+ <node type="renderablenode" >
<asset type="hgmdlmodel" file="lamp.hgmdl" />
</node>
</node>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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.
|
|
From: Charles L. <cn...@us...> - 2009-05-21 18:10:33
|
Update of /cvsroot/hgengine/Mercury/src In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv21286/src Modified Files: CopperPrimitives.h Log Message: fix up copper some Index: CopperPrimitives.h =================================================================== RCS file: /cvsroot/hgengine/Mercury/src/CopperPrimitives.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** CopperPrimitives.h 8 Feb 2009 21:58:40 -0000 1.10 --- CopperPrimitives.h 21 May 2009 18:10:21 -0000 1.11 *************** *** 32,36 **** public: virtual void Init( CopperWindow * pParent, const MString & sName ); ! virtual bool IsFocusable() { return false; } CLASS_RTTI( CopperCaption, CopperWindow ); --- 32,36 ---- public: virtual void Init( CopperWindow * pParent, const MString & sName ); ! virtual void SetText( const MString & s ) { m_pText.SetText( s ); } virtual bool IsFocusable() { return false; } CLASS_RTTI( CopperCaption, CopperWindow ); *************** *** 47,51 **** virtual void Update( const float fDtime ); virtual bool IsFocusable() { return true; } ! CLASS_RTTI( CopperButton, CopperWindow ); protected: void ToggleDownImage(bool isPressed); --- 47,51 ---- virtual void Update( const float fDtime ); virtual bool IsFocusable() { return true; } ! CLASS_RTTI( CopperButton, CopperCaption ); protected: void ToggleDownImage(bool isPressed); |