minor matrix stuff

This commit is contained in:
aap 2016-02-16 08:40:19 +01:00
parent 290117e9be
commit 5b3370b479
3 changed files with 50 additions and 20 deletions

View File

@ -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)
{

View File

@ -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
{

View File

@ -102,8 +102,6 @@ struct Frame : PluginBase<Frame>
LinkList objectList;
Matrix matrix;
Matrix ltm;
//float32 matrix[16];
//float32 ltm[16];
Frame *child;
Frame *next;
@ -128,13 +126,6 @@ struct Frame : PluginBase<Frame>
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);