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