00001 #ifndef __CMATRIX_HPP__
00002 #define __CMATRIX_HPP__
00003
00004 #define MAX_COLUMN_COUNT 4
00005 #define MAX_ROW_COUNT 4
00006
00007
00008 class CMatrix
00009 {
00010 public:
00011 CMatrix()
00012 {
00013 for (int i = 0; i < MAX_COLUMN_COUNT; i++ )
00014 {
00015 ResultMat[i] = 0;
00016
00017 for (int j = 0; j < MAX_ROW_COUNT; j++ )
00018 {
00019 txMat[i][j] = 0;
00020 if (i == j)
00021 {
00022 txMat[i][j] = 1;
00023 }
00024 }
00025 }
00026 }
00027
00028 void SetTranslationMat( GLfloat x, GLfloat y, GLfloat z)
00029 {
00030 txMat[0][3] = x;
00031 txMat[1][3] = y;
00032 txMat[2][3] = z;
00033 }
00034
00035 void SetScalingMat( GLfloat x, GLfloat y, GLfloat z)
00036 {
00037 txMat[0][0] = x;
00038 txMat[1][1] = y;
00039 txMat[2][2] = z;
00040 }
00041
00042 void SetRotationMat(GLfloat theta)
00043 {
00044 GLfloat cos_theta, sin_theta;
00045
00046 cos_theta = cos(theta);
00047 sin_theta = sin(theta);
00048
00049 txMat[0][0] = cos_theta;
00050 txMat[0][2] = sin_theta;
00051 txMat[2][0] = (-1) * sin_theta;
00052 txMat[2][2] = cos_theta;
00053 }
00054
00055 void OperateOnThisPoint(sPoint inPoint, sPoint *outPoint)
00056 {
00057
00058 for (int i = 0; i < MAX_COLUMN_COUNT; i++ )
00059 {
00060 ResultMat[i] = txMat[i][0] * inPoint.x + txMat[i][1] * inPoint.y + txMat[i][2] * inPoint.z + txMat[i][3]*1;
00061 }
00062
00063
00064 outPoint->x = ResultMat[0];
00065 outPoint->y = ResultMat[1];
00066 outPoint->z = ResultMat[2];
00067
00068 }
00069
00070 private:
00071 GLfloat txMat [MAX_ROW_COUNT][MAX_COLUMN_COUNT];
00072 GLfloat ResultMat [MAX_ROW_COUNT];
00073
00074 };
00075
00076 #endif // __CMATRIX_HPP__