00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "mmsgui/3d/mms3dmatrixstack.h"
00034
00035 MMS3DMatrixStack::MMS3DMatrixStack() {
00036 clear();
00037 this->base_matrix_set = false;
00038 this->result_matrix_set = false;
00039 }
00040
00041 bool MMS3DMatrixStack::add(MOP mop, float p0, float p1, float p2, float p3) {
00042 if (this->ms_cnt >= MS_SIZE) return false;
00043
00044
00045 MSI *msi = &ms[this->ms_cnt];
00046 this->ms_cnt++;
00047
00048
00049 msi->mop = mop;
00050 msi->params[0] = p0;
00051 msi->params[1] = p1;
00052 msi->params[2] = p2;
00053 msi->params[3] = p3;
00054
00055 return true;
00056 }
00057
00058 void MMS3DMatrixStack::clear() {
00059 this->ms_cnt = 0;
00060 this->result_matrix_set = false;
00061 }
00062
00063 void MMS3DMatrixStack::setBaseMatrix(MMSMatrix base_matrix) {
00064 if (this->base_matrix_set) {
00065 if (equalMatrix(this->base_matrix, base_matrix)) {
00066
00067 return;
00068 }
00069 }
00070
00071
00072 copyMatrix(this->base_matrix, base_matrix);
00073 this->base_matrix_set = true;
00074 this->result_matrix_set = false;
00075 }
00076
00077 bool MMS3DMatrixStack::getResultMatrix(MMSMatrix result_matrix) {
00078 if (!this->base_matrix_set) return false;
00079
00080 if (!this->result_matrix_set) {
00081
00082 copyMatrix(this->result_matrix, this->base_matrix);
00083
00084
00085 for (int i = this->ms_cnt - 1; i >= 0; i--) {
00086 MSI *msi = &ms[i];
00087 switch (msi->mop) {
00088 case MOP_SCALE:
00089 scaleMatrix(this->result_matrix, msi->params[0], msi->params[1], msi->params[2]);
00090 break;
00091 case MOP_TRANSLATE:
00092 translateMatrix(this->result_matrix, msi->params[0], msi->params[1], msi->params[2]);
00093 break;
00094 case MOP_ROTATE:
00095 rotateMatrix(this->result_matrix, msi->params[0], msi->params[1], msi->params[2], msi->params[3]);
00096 break;
00097 }
00098 }
00099
00100
00101 this->result_matrix_set = true;
00102 }
00103
00104
00105 copyMatrix(result_matrix, this->result_matrix);
00106
00107 return true;
00108 }
00109
00110 bool MMS3DMatrixStack::scale(float sx, float sy, float sz) {
00111 if (sx == 1.0f && sy == 1.0f && sz == 1.0f) return true;
00112 this->result_matrix_set = false;
00113 return add(MOP_SCALE, sx, sy, sz, 0);
00114 }
00115
00116 bool MMS3DMatrixStack::translate(float tx, float ty, float tz) {
00117 if (tx == 0.0f && ty == 0.0f && tz == 0.0f) return true;
00118 this->result_matrix_set = false;
00119 return add(MOP_TRANSLATE, tx, ty, tz, 0);
00120 }
00121
00122 bool MMS3DMatrixStack::rotate(float angle, float x, float y, float z) {
00123 if (angle == 0.0f) return true;
00124 this->result_matrix_set = false;
00125 return add(MOP_ROTATE, angle, x, y, z);
00126 }
00127
00128
00129