📄 matrix.h
字号:
#ifndef _MATRIX_H_
#define _MATRIX_H_
#include "Define.h"
#include "..\System\IMath.h"
#include "Vector.h"
#include "..\System\Sysdef.h"
// Matrix calculations using integers
enum AXIS
{
X=0x01,
Y=0x02,
Z=0x03,
};
class CMatrix44
{
inline static int INDEX(int i,int j) {return (i + j*3);} // cannot be changed due to union with Vector4s vectors
public:
// typedef Vector4s::Type Type;
typedef short Type;
//==============================================================//
// add for 3d intereface of the bowling 3d
//==============================================================//
CMatrix44();
CMatrix44(const CMatrix44 *src);
void Identity() ;
inline Vector4s Transform(const Vector4s &Src) const
{
Vector4s dest;
dest.x = (((Src.x*m[INDEX(0,0)] + Src.y*m[INDEX(0,1)]) + Src.z*m[INDEX(0,2)] ) >> COS_SIN_SHIFT) + m[INDEX(0,3)];
dest.y = (((Src.x*m[INDEX(1,0)] + Src.y*m[INDEX(1,1)]) + Src.z*m[INDEX(1,2)] ) >> COS_SIN_SHIFT) + m[INDEX(1,3)];
dest.z = (((Src.x*m[INDEX(2,0)] + Src.y*m[INDEX(2,1)]) + Src.z*m[INDEX(2,2)] ) >> COS_SIN_SHIFT) + m[INDEX(2,3)];
return dest;
};
inline Vector4s TransformNormal(const Vector4s &Src) const
{
Vector4s dest;
dest.x = (Src.x*m[INDEX(0,0)] + Src.y*m[INDEX(0,1)] + Src.z*m[INDEX(0,2)]) >> COS_SIN_SHIFT;
dest.y = (Src.x*m[INDEX(1,0)] + Src.y*m[INDEX(1,1)] + Src.z*m[INDEX(1,2)]) >> COS_SIN_SHIFT;
dest.z = (Src.x*m[INDEX(2,0)] + Src.y*m[INDEX(2,1)] + Src.z*m[INDEX(2,2)]) >> COS_SIN_SHIFT;
return dest;
};
inline Vertex Transform(const Vertex &Src) const
{
//!!!note: we havn't transform normal here
Vertex dest = Src;
dest.x = (short)((((Src.x*m[INDEX(0,0)] + Src.y*m[INDEX(0,1)]) + Src.z*m[INDEX(0,2)] ) >> COS_SIN_SHIFT) + m[INDEX(0,3)]);
dest.y = (short)((((Src.x*m[INDEX(1,0)] + Src.y*m[INDEX(1,1)]) + Src.z*m[INDEX(1,2)] ) >> COS_SIN_SHIFT) + m[INDEX(1,3)]);
dest.z = (short)((((Src.x*m[INDEX(2,0)] + Src.y*m[INDEX(2,1)]) + Src.z*m[INDEX(2,2)] ) >> COS_SIN_SHIFT) + m[INDEX(2,3)]);
return dest;
};
inline void Transform(const Vertex &Src, Vector4s *v) const
{
v->x = (((Src.x*m[INDEX(0,0)] + Src.y*m[INDEX(0,1)]) + Src.z*m[INDEX(0,2)] ) >> COS_SIN_SHIFT) + m[INDEX(0,3)];
v->y = (((Src.x*m[INDEX(1,0)] + Src.y*m[INDEX(1,1)]) + Src.z*m[INDEX(1,2)] ) >> COS_SIN_SHIFT) + m[INDEX(1,3)];
v->z = (((Src.x*m[INDEX(2,0)] + Src.y*m[INDEX(2,1)]) + Src.z*m[INDEX(2,2)] ) >> COS_SIN_SHIFT) + m[INDEX(2,3)];
};
void PostMultiply(const CMatrix44 *mat);
void PostTranslate(int x, int y, int z);
void PostRotation(AXIS axis, int angle);
void LookAt(const Vector4s &eye, const Vector4s &dir, const Vector4s &up);
void LookAt(const int* eye, const int* dir);
void Inverse();
void LoadIdentity(void);
void DefScale(int Scale);
void Scale(int Ratio);
void DefTranslate(Type x, Type y, Type z);
/* void Translate(Type x, Type y, Type z);
void Translate(const Vector4s *v){Translate(v->x,v->y,v->z);}
void Translate(const Vector4s& v){Translate(v.x,v.y,v.z);}
*/
void Transpose();
void DefRotateX(int a);
void DefRotateY(int a);
void DefRotateZ(int a);
void RotateX(int a);
void RotateY(int a);
void RotateZ(int a);
void GetProduct(const CMatrix44 *M1, const CMatrix44 *M2);
void InvRotateVector(const Vector4s *Src, Vector4s *Dest);
const Vector4s *getPos(void) const { return (Vector4s *)&m[9]; }; // allow to access to position datas
const Vector4s *getDir(void) const { return (Vector4s *)&m[6]; }; // dir = z vector
const Vector4s *getUp(void) const { return (Vector4s *)&m[3]; }; // up = y vector
const Vector4s *getRight(void) const { return (Vector4s *)&m[0]; }; // left = x vector (if look on -z)
inline Type get(int i,int j) const {return m[ INDEX(i,j) ];}
inline Type& set(int i,int j) {return m[ INDEX(i,j) ];}
// bool operator==(const CMatrix44&) const;
// CMatrix44 & operator=(const CMatrix44 & src);
public:
void Test();
Type m[12];
};
/*
// ---------------------------------------------------------------------------
// matrix stack (like on opengl)
// ---------------------------------------------------------------------------
class CMatrixStack
{
public:
CMatrixStack(int size = 8);
~CMatrixStack();
CMatrix44& PushMatrix(void);
void PopMatrix(void);
const CMatrix44& CurrentMatrix()const{return *m_currentMatrix;}
CMatrix44& ResetStack();
private:
CMatrix44* m_stack;
CMatrix44* m_currentMatrix;
const int m_maxStackSize;
};
*/
#endif // _MATRIX_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -