|
Blender
V2.59
|
00001 /* 00002 * $Id: MT_Transform.h 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 MoTo - 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 #ifndef MT_TRANSFORM_H 00056 #define MT_TRANSFORM_H 00057 00058 #include "MT_Point3.h" 00059 #include "MT_Matrix3x3.h" 00060 00061 class MT_Transform { 00062 public: 00063 MT_Transform() {} 00064 MT_Transform(const float *m) { setValue(m); } 00065 MT_Transform(const double *m) { setValue(m); } 00066 MT_Transform(const MT_Point3& p, const MT_Quaternion& q) 00067 : m_type(IDENTITY) 00068 { 00069 setOrigin(p); 00070 setRotation(q); 00071 } 00072 00073 MT_Transform(const MT_Point3& p, const MT_Matrix3x3& m) 00074 : m_type(IDENTITY) 00075 { 00076 setOrigin(p); 00077 setBasis(m); 00078 } 00079 00080 static MT_Transform Identity() 00081 { 00082 MT_Transform t; 00083 t.setIdentity(); 00084 return t; 00085 } 00086 00087 00088 MT_Point3 operator()(const MT_Point3& p) const { 00089 return MT_Point3(MT_dot(m_basis[0], p) + m_origin[0], 00090 MT_dot(m_basis[1], p) + m_origin[1], 00091 MT_dot(m_basis[2], p) + m_origin[2]); 00092 } 00093 00094 MT_Vector3 operator()(const MT_Vector3& p) const { 00095 return MT_Vector3(MT_dot(m_basis[0], p) + m_origin[0], 00096 MT_dot(m_basis[1], p) + m_origin[1], 00097 MT_dot(m_basis[2], p) + m_origin[2]); 00098 } 00099 00100 MT_Point3 operator*(const MT_Point3& p) const { 00101 return (*this)(p); 00102 } 00103 00104 MT_Vector3 operator*(const MT_Vector3& p) const { 00105 return (*this)(p); 00106 } 00107 00108 00109 MT_Matrix3x3& getBasis() { return m_basis; } 00110 const MT_Matrix3x3& getBasis() const { return m_basis; } 00111 MT_Point3& getOrigin() { return m_origin; } 00112 const MT_Point3& getOrigin() const { return m_origin; } 00113 MT_Quaternion getRotation() const { return m_basis.getRotation(); } 00114 00115 void setValue(const float *m); 00116 void setValue(const double *m); 00117 00118 void setOrigin(const MT_Point3& origin) { 00119 m_origin = origin; 00120 m_type |= TRANSLATION; 00121 } 00122 00123 void setBasis(const MT_Matrix3x3& basis) { 00124 m_basis = basis; 00125 m_type |= LINEAR; 00126 } 00127 00128 void setRotation(const MT_Quaternion& q) { 00129 m_basis.setRotation(q); 00130 m_type &= ~SCALING; 00131 m_type |= ROTATION; 00132 } 00133 00134 void getValue(float *m) const; 00135 void getValue(double *m) const; 00136 00137 void setIdentity(); 00138 00139 MT_Transform& operator*=(const MT_Transform& t); 00140 00146 void translate(const MT_Vector3& v); 00147 void rotate(const MT_Quaternion& q); 00148 void scale(MT_Scalar x, MT_Scalar y, MT_Scalar z); 00149 00150 void invert(const MT_Transform& t); 00151 void mult(const MT_Transform& t1, const MT_Transform& t2); 00152 void multInverseLeft(const MT_Transform& t1, const MT_Transform& t2); 00153 00154 private: 00155 enum { 00156 IDENTITY = 0x00, 00157 TRANSLATION = 0x01, 00158 ROTATION = 0x02, 00159 RIGID = TRANSLATION | ROTATION, 00160 SCALING = 0x04, 00161 LINEAR = ROTATION | SCALING, 00162 AFFINE = TRANSLATION | LINEAR 00163 }; 00164 00165 MT_Transform(const MT_Matrix3x3& basis, const MT_Point3& origin, 00166 unsigned int type) { 00167 setValue(basis, origin, type); 00168 } 00169 00170 void setValue(const MT_Matrix3x3& basis, const MT_Point3& origin, 00171 unsigned int type) { 00172 m_basis = basis; 00173 m_origin = origin; 00174 m_type = type; 00175 } 00176 00177 friend MT_Transform operator*(const MT_Transform& t1, const MT_Transform& t2); 00178 00179 MT_Matrix3x3 m_basis; 00180 MT_Point3 m_origin; 00181 unsigned int m_type; 00182 }; 00183 00184 inline MT_Transform operator*(const MT_Transform& t1, const MT_Transform& t2) { 00185 return MT_Transform(t1.m_basis * t2.m_basis, 00186 t1(t2.m_origin), 00187 t1.m_type | t2.m_type); 00188 } 00189 00190 #endif 00191