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

mms3dobject.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/mms3dobject.h"
00034 #include "mmsgui/3d/mms3dscene.h"
00035 
00036 MMS3DObject::MMS3DObject(MMS3DScene *scene) {
00037     this->scene = scene;
00038 
00039     // put new object into scene
00040     // note: this object will not be drawn but can have children
00041     this->obj_id = this->scene->newObject(this);
00042 
00043     this->parent = NULL;
00044 
00045     // set the base matrix of the object
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     // put new object into scene
00055     this->obj_id = this->scene->newObject(this);
00056     if (this->obj_id >= 0) {
00057         // get access to it
00058         MMS3D_OBJECT *obj = this->scene->getObject(this->obj_id);
00059 
00060         // set material and texture indices to object structure
00061         obj->material = material;
00062         obj->texture = texture;
00063     }
00064 
00065     this->parent = NULL;
00066 
00067     // set the base matrix of the object
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     // set the base matrix of the object
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     // store the result matrix into object's attribute
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     // get result matrix of object used as base matrix for children
00145     MMSMatrix base_matrix;
00146     if (!getResultMatrix(base_matrix)) return false;
00147 
00148     // through children
00149     for (int i = 0; i < this->children.size(); i++) {
00150         // set the base matrix of the object
00151         this->children.at(i)->setBaseMatrix(base_matrix);
00152 
00153         // generate the matrices for the object and it's children
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 

Generated by doxygen