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/mms3dobject.h"
00034 #include "mmsgui/3d/mms3dscene.h"
00035
00036 MMS3DObject::MMS3DObject(MMS3DScene *scene) {
00037 this->scene = scene;
00038
00039
00040
00041 this->obj_id = this->scene->newObject(this);
00042
00043 this->parent = NULL;
00044
00045
00046 MMSMatrix base_matrix;
00047 if (this->scene->getResultMatrix(base_matrix))
00048 this->matrixStack.setBaseMatrix(base_matrix);
00049 }
00050
00051 MMS3DObject::MMS3DObject(MMS3DScene *scene, int material, int texture) {
00052 this->scene = scene;
00053
00054
00055 this->obj_id = this->scene->newObject(this);
00056 if (this->obj_id >= 0) {
00057
00058 MMS3D_OBJECT *obj = this->scene->getObject(this->obj_id);
00059
00060
00061 obj->material = material;
00062 obj->texture = texture;
00063 }
00064
00065 this->parent = NULL;
00066
00067
00068 MMSMatrix base_matrix;
00069 if (this->scene->getResultMatrix(base_matrix))
00070 this->matrixStack.setBaseMatrix(base_matrix);
00071 }
00072
00073 bool MMS3DObject::addObject(MMS3DObject *object) {
00074 if (!object) return false;
00075 if (object->obj_id >= 0) {
00076 MMS3D_OBJECT *obj = object->scene->getObject(object->obj_id);
00077 if (this->obj_id >= 0) {
00078 MMS3D_OBJECT *tobj = this->scene->getObject(this->obj_id);
00079 obj->parent = tobj;
00080 }
00081 }
00082
00083 object->parent = this;
00084
00085
00086 MMSMatrix base_matrix;
00087 if (object->parent->getResultMatrix(base_matrix))
00088 object->matrixStack.setBaseMatrix(base_matrix);
00089
00090
00091 this->children.push_back(object);
00092 return true;
00093 }
00094
00095 bool MMS3DObject::show() {
00096 if (this->obj_id >= 0) {
00097 MMS3D_OBJECT *obj = this->scene->getObject(this->obj_id);
00098 obj->shown = true;
00099 return true;
00100 }
00101
00102 return false;
00103 }
00104
00105 bool MMS3DObject::hide() {
00106 if (this->obj_id >= 0) {
00107 MMS3D_OBJECT *obj = this->scene->getObject(this->obj_id);
00108 obj->shown = false;
00109 return true;
00110 }
00111
00112 return false;
00113 }
00114
00115 bool MMS3DObject::cullFace(bool cullface) {
00116 if (this->obj_id >= 0) {
00117 MMS3D_OBJECT *obj = this->scene->getObject(this->obj_id);
00118 obj->cullface = cullface;
00119 return true;
00120 }
00121
00122 return false;
00123 }
00124
00125
00126 void MMS3DObject::setBaseMatrix(MMSMatrix matrix) {
00127 this->matrixStack.setBaseMatrix(matrix);
00128 }
00129
00130 bool MMS3DObject::getResultMatrix(MMSMatrix result) {
00131 if (!this->matrixStack.getResultMatrix(result))
00132 return false;
00133
00134
00135 if (this->obj_id >= 0) {
00136 MMS3D_OBJECT *obj = this->scene->getObject(this->obj_id);
00137 copyMatrix(obj->matrix, result);
00138 }
00139
00140 return true;
00141 }
00142
00143 bool MMS3DObject::genMatrices() {
00144
00145 MMSMatrix base_matrix;
00146 if (!getResultMatrix(base_matrix)) return false;
00147
00148
00149 for (int i = 0; i < this->children.size(); i++) {
00150
00151 this->children.at(i)->setBaseMatrix(base_matrix);
00152
00153
00154 this->children.at(i)->genMatrices();
00155 }
00156
00157 return true;
00158 }
00159
00160
00161 void MMS3DObject::reset() {
00162 this->matrixStack.clear();
00163 }
00164
00165 bool MMS3DObject::scale(float sx, float sy, float sz) {
00166 return this->matrixStack.scale(sx, sy, sz);
00167 }
00168
00169 bool MMS3DObject::translate(float tx, float ty, float tz) {
00170 return this->matrixStack.translate(tx, ty, tz);
00171 }
00172
00173 bool MMS3DObject::rotate(float angle, float x, float y, float z) {
00174 return this->matrixStack.rotate(angle, x, y, z);
00175 }
00176
00177