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

mms3dmatrixstack.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/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     // new item
00045     MSI *msi = &ms[this->ms_cnt];
00046     this->ms_cnt++;
00047 
00048     // setup item
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             // this base matrix has been already set
00067             return;
00068         }
00069     }
00070 
00071     // set new base matrix
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         // result matrix not generated, do it now
00082         copyMatrix(this->result_matrix, this->base_matrix);
00083 
00084         // generate result
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         // result matrix is now available
00101         this->result_matrix_set = true;
00102     }
00103 
00104     // return result
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 

Generated by doxygen