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/mms3dscene.h"
00034 #include <string.h>
00035
00036 MMS3DScene::MMS3DScene() {
00037 this->objects_cnt = 0;
00038 this->objects[this->objects_cnt] = NULL;
00039 }
00040
00041 int MMS3DScene::newObject(MMS3DObject *object) {
00042 if (this->objects_cnt >= OBJ_SIZE) {
00043
00044 return OBJ_NOTSET;
00045 }
00046
00047
00048 this->objects[this->objects_cnt] = &this->objbuf[this->objects_cnt];
00049
00050
00051 memset(this->objects[this->objects_cnt], 0, sizeof(MMS3D_OBJECT));
00052 this->objects[this->objects_cnt]->parent = NULL;
00053 this->objects[this->objects_cnt]->vertices = -1;
00054 this->objects[this->objects_cnt]->normals = -1;
00055 this->objects[this->objects_cnt]->texcoords= -1;
00056 this->objects[this->objects_cnt]->indices = -1;
00057 this->objects[this->objects_cnt]->material = -1;
00058 this->objects[this->objects_cnt]->texture = -1;
00059
00060
00061 this->children.push_back(object);
00062
00063
00064 this->objects_cnt++;
00065 this->objects[this->objects_cnt] = NULL;
00066 return this->objects_cnt - 1;
00067 }
00068
00069 MMS3D_OBJECT *MMS3DScene::getObject(int object) {
00070 return this->objects[object];
00071 }
00072
00073 bool MMS3DScene::getResultMatrix(MMSMatrix result) {
00074 return this->matrixStack.getResultMatrix(result);
00075 }
00076
00077 bool MMS3DScene::setPrimitives(string id, MMS_VERTEX_ARRAY *vertices, MMS_VERTEX_ARRAY *normals,
00078 MMS_VERTEX_ARRAY *texcoords, MMS_INDEX_ARRAY *indices) {
00079 return mms3dpm.setPrimitives(id, vertices, normals, texcoords, indices);
00080 }
00081
00082 void MMS3DScene::getMeshArrays(MMS_VERTEX_ARRAY ***varrays, MMS_INDEX_ARRAY ***iarrays) {
00083 mms3dpm.getArrays(varrays, iarrays);
00084 }
00085
00086 void MMS3DScene::getObjects(MMS3D_OBJECT ***objects) {
00087 *objects = this->objects;
00088 }
00089
00090 void MMS3DScene::setBaseMatrix(MMSMatrix matrix) {
00091 this->matrixStack.setBaseMatrix(matrix);
00092 }
00093
00094 void MMS3DScene::reset() {
00095 this->matrixStack.clear();
00096 }
00097
00098 bool MMS3DScene::scale(float sx, float sy, float sz) {
00099 return this->matrixStack.scale(sx, sy, sz);
00100 }
00101
00102 bool MMS3DScene::translate(float tx, float ty, float tz) {
00103 return this->matrixStack.translate(tx, ty, tz);
00104 }
00105
00106 bool MMS3DScene::rotate(float angle, float x, float y, float z) {
00107 return this->matrixStack.rotate(angle, x, y, z);
00108 }
00109
00110 bool MMS3DScene::genMatrices() {
00111
00112 MMSMatrix base_matrix;
00113 if (!getResultMatrix(base_matrix)) return false;
00114
00115
00116 for (int i = 0; i < this->children.size(); i++) {
00117
00118 if (this->children.at(i)->parent) continue;
00119
00120
00121 this->children.at(i)->setBaseMatrix(base_matrix);
00122
00123
00124 this->children.at(i)->genMatrices();
00125 }
00126
00127 return true;
00128 }
00129
00130
00131