diff --git a/src/rwbase.cpp b/src/rwbase.cpp
index b2684b8..5226a22 100644
--- a/src/rwbase.cpp
+++ b/src/rwbase.cpp
@@ -31,7 +31,12 @@ int32 build = 0xFFFF;
#endif
char *debugFile = NULL;
-static Matrix identMat;
+static Matrix identMat = {
+ { 1.0f, 0.0f, 0.0f}, 0.0f,
+ { 0.0f, 1.0f, 0.0f}, 0.0f,
+ { 0.0f, 0.0f, 1.0f}, 0.0f,
+ { 0.0f, 0.0f, 0.0f}, 1.0f
+};
void
initialize(void)
@@ -52,15 +57,6 @@ initialize(void)
d3d9::makeDefaultPipeline();
Frame::dirtyList.init();
-
- identMat.right.set(1.0f, 0.0f, 0.0f);
- identMat.rightw = 0.0f;
- identMat.up.set(0.0f, 1.0f, 0.0f);
- identMat.upw = 0.0f;
- identMat.at.set(0.0f, 0.0f, 1.0f);
- identMat.atw = 0.0f;
- identMat.pos.set(0.0f, 0.0f, 0.0f);
- identMat.posw = 1.0f;
}
Quat
@@ -86,6 +82,32 @@ Matrix::setIdentity(void)
*this = identMat;
}
+V3d
+Matrix::transPoint(const V3d &p)
+{
+ V3d res = this->pos;
+ res = add(res, scale(this->right, p.x));
+ res = add(res, scale(this->up, p.y));
+ res = add(res, scale(this->at, p.z));
+ return res;
+}
+
+V3d
+Matrix::transVec(const V3d &v)
+{
+ V3d res;
+ res = scale(this->right, v.x);
+ res = add(res, scale(this->up, v.y));
+ res = add(res, scale(this->at, v.z));
+ return res;
+}
+
+bool32
+Matrix::isIdentity(void)
+{
+ return matrixIsIdentity((float32*)this);
+}
+
void
Matrix::mult(Matrix *m1, Matrix *m2, Matrix *m3)
{
@@ -98,6 +120,18 @@ Matrix::invert(Matrix *m1, Matrix *m2)
matrixInvert((float32*)m1, (float32*)m2);
}
+void
+Matrix::transpose(Matrix *m1, Matrix *m2)
+{
+ matrixTranspose((float32*)m1, (float32*)m2);
+}
+
+bool32
+equal(const Matrix &m1, const Matrix &m2)
+{
+ return matrixEqual((float32*)&m1, (float32*)&m2);
+}
+
void
matrixIdentity(float32 *mat)
{
diff --git a/src/rwbase.h b/src/rwbase.h
index 2d7ce78..ff9ba3f 100644
--- a/src/rwbase.h
+++ b/src/rwbase.h
@@ -82,6 +82,7 @@ inline float32 length(const V3d &v) { return sqrt(v.x*v.x + v.y*v.y + v.z*v.z);
inline V3d normalize(const V3d &v) { return scale(v, 1.0f/length(v)); }
inline V3d setlength(const V3d &v, float32 l) { return scale(v, l/length(v)); }
V3d cross(const V3d &a, const V3d &b);
+inline float32 dot(const V3d &a, const V3d &b) { return a.x*b.x + a.y*b.y + a.z*b.z; }
struct Quat
{
@@ -104,7 +105,6 @@ inline float32 length(const Quat &q) { return sqrt(q.w*q.w + q.x*q.x + q.y*q.y +
inline Quat normalize(const Quat &q) { return scale(q, 1.0f/length(q)); }
inline Quat conj(const Quat &q) { return Quat(q.w, -q.x, -q.y, -q.z); }
Quat mult(const Quat &q, const Quat &p);
-
inline V3d rotate(const V3d &v, const Quat &q) { return mult(mult(q, Quat(v)), conj(q)).vec(); }
struct Matrix
@@ -119,9 +119,13 @@ struct Matrix
float32 posw;
void setIdentity(void);
+ V3d transPoint(const V3d &p);
+ V3d transVec(const V3d &v);
+ bool32 isIdentity(void);
// not very pretty :/
static void mult(Matrix *m1, Matrix *m2, Matrix *m3);
static void invert(Matrix *m1, Matrix *m2);
+ static void transpose(Matrix *m1, Matrix *m2);
};
void matrixIdentity(float32 *mat);
@@ -132,6 +136,7 @@ void vecTrans(float32 *out, float32 *mat, float32 *vec);
void matrixTranspose(float32 *out, float32 *in);
void matrixInvert(float32 *out, float32 *in);
void matrixPrint(float32 *mat);
+bool32 equal(const Matrix &m1, const Matrix &m2);
class Stream
{
diff --git a/src/rwobjects.h b/src/rwobjects.h
index dd278bf..4b0236f 100644
--- a/src/rwobjects.h
+++ b/src/rwobjects.h
@@ -102,8 +102,6 @@ struct Frame : PluginBase
LinkList objectList;
Matrix matrix;
Matrix ltm;
- //float32 matrix[16];
- //float32 ltm[16];
Frame *child;
Frame *next;
@@ -128,13 +126,6 @@ struct Frame : PluginBase
void setHierarchyRoot(Frame *root);
Frame *cloneAndLink(Frame *clonedroot);
void purgeClone(void);
-
- // private flags:
- // #define rwFRAMEPRIVATEHIERARCHYSYNCLTM 0x01
- // #define rwFRAMEPRIVATEHIERARCHYSYNCOBJ 0x02
- // #define rwFRAMEPRIVATESUBTREESYNCLTM 0x04
- // #define rwFRAMEPRIVATESUBTREESYNCOBJ 0x08
- // #define rwFRAMEPRIVATESTATIC 0x10
};
Frame **makeFrameList(Frame *frame, Frame **flist);