Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

mms3dscene.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,             *
00003  *                           Matthias Hardt, Guido Madaus                  *
00004  *                                                                         *
00005  *   Copyright (C) 2007-2008 BerLinux Solutions GbR                        *
00006  *                           Stefan Schwarzer & Guido Madaus               *
00007  *                                                                         *
00008  *   Copyright (C) 2009-2013 BerLinux Solutions GmbH                       *
00009  *                                                                         *
00010  *   Authors:                                                              *
00011  *      Stefan Schwarzer   <stefan.schwarzer@diskohq.org>,                 *
00012  *      Matthias Hardt     <matthias.hardt@diskohq.org>,                   *
00013  *      Jens Schneider     <jens.schneider@diskohq.org>,                   *
00014  *      Guido Madaus       <guido.madaus@diskohq.org>,                     *
00015  *      Patrick Helterhoff <patrick.helterhoff@diskohq.org>,               *
00016  *      René Bählkow       <rene.baehlkow@diskohq.org>                     *
00017  *                                                                         *
00018  *   This library is free software; you can redistribute it and/or         *
00019  *   modify it under the terms of the GNU Lesser General Public            *
00020  *   License version 2.1 as published by the Free Software Foundation.     *
00021  *                                                                         *
00022  *   This library is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00025  *   Lesser General Public License for more details.                       *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU Lesser General Public      *
00028  *   License along with this library; if not, write to the                 *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
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         // no more space
00044         return OBJ_NOTSET;
00045     }
00046 
00047     // get new object
00048     this->objects[this->objects_cnt] = &this->objbuf[this->objects_cnt];
00049 
00050     // reset it
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     // add to children
00061     this->children.push_back(object);
00062 
00063     // return index
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     // get result matrix of scene used as base matrix for objects
00112     MMSMatrix base_matrix;
00113     if (!getResultMatrix(base_matrix)) return false;
00114 
00115     // though the flat list of scene objects
00116     for (int i = 0; i < this->children.size(); i++) {
00117         // ignore objects which are children of objects
00118         if (this->children.at(i)->parent) continue;
00119 
00120         // set the base matrix of the object
00121         this->children.at(i)->setBaseMatrix(base_matrix);
00122 
00123         // generate the matrices for the object and it's children
00124         this->children.at(i)->genMatrices();
00125     }
00126 
00127     return true;
00128 }
00129 
00130 
00131 

Generated by doxygen