Blender V2.61 - r43446

MT_Transform.cpp

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 /*
00034 
00035   MOTTO - 3D Motion Toolkit 
00036   Copyright (C) 2000  Gino van den Bergen <gino@acm.org>
00037 
00038   This library is free software; you can redistribute it and/or
00039   modify it under the terms of the GNU Library General Public
00040   License as published by the Free Software Foundation; either
00041   version 2 of the License, or (at your option) any later version.
00042 
00043   This library is distributed in the hope that it will be useful,
00044   but WITHOUT ANY WARRANTY; without even the implied warranty of
00045   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00046   Library General Public License for more details.
00047 
00048   You should have received a copy of the GNU Library General Public
00049   License along with this library; if not, write to the Free
00050   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00051 
00052 */
00053 
00054 #include "MT_Transform.h"
00055 
00056 void MT_Transform::setValue(const float *m) {
00057     m_basis.setValue(m);
00058     m_origin.setValue(&m[12]);
00059     m_type = AFFINE;
00060 }
00061 
00062 void MT_Transform::setValue(const double *m) {
00063     m_basis.setValue(m);
00064     m_origin.setValue(&m[12]);
00065     m_type = AFFINE;
00066 }
00067 
00068 void MT_Transform::getValue(float *m) const {
00069     m_basis.getValue(m);
00070     m_origin.getValue(&m[12]);
00071     m[15] = 1.0;
00072 }
00073 
00074 void MT_Transform::getValue(double *m) const {
00075     m_basis.getValue(m);
00076     m_origin.getValue(&m[12]);
00077     m[15] = 1.0;
00078 }
00079 
00080 MT_Transform& MT_Transform::operator*=(const MT_Transform& t) {
00081     m_origin += m_basis * t.m_origin;
00082     m_basis *= t.m_basis;
00083     m_type |= t.m_type; 
00084     return *this;
00085 }
00086 
00087 void MT_Transform::translate(const MT_Vector3& v) { 
00088     m_origin += m_basis * v; 
00089     m_type |= TRANSLATION;
00090 }
00091 
00092 void MT_Transform::rotate(const MT_Quaternion& q) { 
00093     m_basis *= MT_Matrix3x3(q); 
00094     m_type |= ROTATION; 
00095 }
00096 
00097 void MT_Transform::scale(MT_Scalar x, MT_Scalar y, MT_Scalar z) { 
00098     m_basis.scale(x, y, z);  
00099     m_type |= SCALING;
00100 }
00101 
00102 void MT_Transform::setIdentity() {
00103     m_basis.setIdentity();
00104     m_origin.setValue(MT_Scalar(0.0), MT_Scalar(0.0), MT_Scalar(0.0));
00105     m_type = IDENTITY;
00106 }
00107 
00108 void MT_Transform::invert(const MT_Transform& t) {
00109     m_basis = t.m_type & SCALING ? 
00110         t.m_basis.inverse() : 
00111         t.m_basis.transposed();
00112     m_origin.setValue(-MT_dot(m_basis[0], t.m_origin), 
00113                       -MT_dot(m_basis[1], t.m_origin), 
00114                       -MT_dot(m_basis[2], t.m_origin));  
00115     m_type = t.m_type;
00116 }
00117 
00118 void MT_Transform::mult(const MT_Transform& t1, const MT_Transform& t2) {
00119     m_basis = t1.m_basis * t2.m_basis;
00120     m_origin = t1(t2.m_origin);
00121     m_type = t1.m_type | t2.m_type;
00122 }
00123 
00124 void MT_Transform::multInverseLeft(const MT_Transform& t1, const MT_Transform& t2) {
00125     MT_Vector3 v = t2.m_origin - t1.m_origin;
00126     if (t1.m_type & SCALING) {
00127         MT_Matrix3x3 inv = t1.m_basis.inverse();
00128         m_basis = inv * t2.m_basis;
00129         m_origin = inv * v;
00130     }
00131     else {
00132         m_basis = MT_multTransposeLeft(t1.m_basis, t2.m_basis);
00133         m_origin = v * t1.m_basis;
00134     }
00135     m_type = t1.m_type | t2.m_type;
00136 }
00137 
00138 
00139