|
From: <axl...@us...> - 2009-10-11 03:33:13
|
Revision: 560
http://hgengine.svn.sourceforge.net/hgengine/?rev=560&view=rev
Author: axlecrusher
Date: 2009-10-11 03:33:05 +0000 (Sun, 11 Oct 2009)
Log Message:
-----------
add vector * matrix multiply
Modified Paths:
--------------
Mercury2/src/MercuryVertex.cpp
Mercury2/src/MercuryVertex.h
Modified: Mercury2/src/MercuryVertex.cpp
===================================================================
--- Mercury2/src/MercuryVertex.cpp 2009-10-11 03:32:30 UTC (rev 559)
+++ Mercury2/src/MercuryVertex.cpp 2009-10-11 03:33:05 UTC (rev 560)
@@ -4,6 +4,8 @@
#include <MQuaternion.h>
#include <MercuryLog.h>
+#include <MercuryMatrix.h>
+
MercuryVertex::MercuryVertex()
{
(*this)[0] = (*this)[1] = (*this)[2] = (*this)[3] = 0;
@@ -119,6 +121,27 @@
return dp;
}
+MercuryVertex MercuryVertex::operator*(const MercuryMatrix& m) const
+{
+ MercuryVertex r;
+ MercuryVertex v1(m[0][0], m[1][0], m[2][0], m[3][0]);
+ MercuryVertex v2(m[0][1], m[1][1], m[2][1], m[3][1]);
+ MercuryVertex v3(m[0][2], m[1][2], m[2][2], m[3][2]);
+ MercuryVertex v4(m[0][3], m[1][4], m[1][4], m[1][4]);
+
+ r[0] = ((*this)*v1).AddComponents();
+ r[1] = ((*this)*v2).AddComponents();
+ r[2] = ((*this)*v3).AddComponents();
+ r[3] = ((*this)*v4).AddComponents();
+
+ return r;
+}
+
+float MercuryVertex::AddComponents() const
+{
+ return GetX() + GetY() + GetZ() + GetW();
+}
+
void MercuryVertex::Print(const MString& s) const
{
LOG.Write(ssprintf("%s: %f %f %f %f", s.c_str(), (*this)[0], (*this)[1], (*this)[2], (*this)[3]));
Modified: Mercury2/src/MercuryVertex.h
===================================================================
--- Mercury2/src/MercuryVertex.h 2009-10-11 03:32:30 UTC (rev 559)
+++ Mercury2/src/MercuryVertex.h 2009-10-11 03:33:05 UTC (rev 560)
@@ -11,6 +11,7 @@
#endif
class MQuaternion;
+class MercuryMatrix;
class MercuryVertex
{
@@ -32,9 +33,11 @@
inline float GetX() const { return (*this)[0]; }
inline float GetY() const { return (*this)[1]; }
inline float GetZ() const { return (*this)[2]; }
+ inline float GetW() const { return (*this)[3]; }
inline void SetX(const float ix) { (*this)[0] = ix; }
inline void SetY(const float iy) { (*this)[1] = iy; }
inline void SetZ(const float iz) { (*this)[2] = iz; }
+ inline void SetW(const float iw) { (*this)[3] = iw; }
inline void Zero() { (*this)[0] = 0; (*this)[1] = 0; (*this)[2] = 0; }
@@ -59,6 +62,9 @@
inline MercuryVertex operator * (const MercuryVertex& p) const { MercuryVertex r(*this); r*=p; return r; }
inline MercuryVertex operator / (const MercuryVertex& p) const { MercuryVertex r(*this); r/=p; return r; }
+ MercuryVertex operator*(const MercuryMatrix& m) const;
+
+
inline MercuryVertex& operator += ( const MercuryVertex& other ) { (*this)[0]+=other[0]; (*this)[1]+=other[1]; (*this)[2]+=other[2]; return *this; }
inline MercuryVertex& operator -= ( const MercuryVertex& other ) { (*this)[0]-=other[0]; (*this)[1]-=other[1]; (*this)[2]-=other[2]; return *this; }
inline MercuryVertex& operator *= ( float f ) { (*this)[0]*=f; (*this)[1]*=f; (*this)[2]*=f; return *this; }
@@ -85,6 +91,8 @@
MercuryVertex Rotate(const MQuaternion& q) const;
+ float AddComponents() const;
+
static MercuryVertex CreateFromString(const MString& s);
// float (*this)[3];
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|