OgreMatrix4.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2012 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 #ifndef __Matrix4__
00029 #define __Matrix4__
00030 
00031 // Precompiler options
00032 #include "OgrePrerequisites.h"
00033 
00034 #include "OgreVector3.h"
00035 #include "OgreMatrix3.h"
00036 #include "OgreVector4.h"
00037 #include "OgrePlane.h"
00038 namespace Ogre
00039 {
00078     class _OgreExport Matrix4
00079     {
00080     protected:
00082         union {
00083             Real m[4][4];
00084             Real _m[16];
00085         };
00086     public:
00091         inline Matrix4()
00092         {
00093         }
00094 
00095         inline Matrix4(
00096             Real m00, Real m01, Real m02, Real m03,
00097             Real m10, Real m11, Real m12, Real m13,
00098             Real m20, Real m21, Real m22, Real m23,
00099             Real m30, Real m31, Real m32, Real m33 )
00100         {
00101             m[0][0] = m00;
00102             m[0][1] = m01;
00103             m[0][2] = m02;
00104             m[0][3] = m03;
00105             m[1][0] = m10;
00106             m[1][1] = m11;
00107             m[1][2] = m12;
00108             m[1][3] = m13;
00109             m[2][0] = m20;
00110             m[2][1] = m21;
00111             m[2][2] = m22;
00112             m[2][3] = m23;
00113             m[3][0] = m30;
00114             m[3][1] = m31;
00115             m[3][2] = m32;
00116             m[3][3] = m33;
00117         }
00118 
00122         inline Matrix4(const Matrix3& m3x3)
00123         {
00124           operator=(IDENTITY);
00125           operator=(m3x3);
00126         }
00127 
00131         inline Matrix4(const Quaternion& rot)
00132         {
00133           Matrix3 m3x3;
00134           rot.ToRotationMatrix(m3x3);
00135           operator=(IDENTITY);
00136           operator=(m3x3);
00137         }
00138         
00139 
00142         inline void swap(Matrix4& other)
00143         {
00144             std::swap(m[0][0], other.m[0][0]);
00145             std::swap(m[0][1], other.m[0][1]);
00146             std::swap(m[0][2], other.m[0][2]);
00147             std::swap(m[0][3], other.m[0][3]);
00148             std::swap(m[1][0], other.m[1][0]);
00149             std::swap(m[1][1], other.m[1][1]);
00150             std::swap(m[1][2], other.m[1][2]);
00151             std::swap(m[1][3], other.m[1][3]);
00152             std::swap(m[2][0], other.m[2][0]);
00153             std::swap(m[2][1], other.m[2][1]);
00154             std::swap(m[2][2], other.m[2][2]);
00155             std::swap(m[2][3], other.m[2][3]);
00156             std::swap(m[3][0], other.m[3][0]);
00157             std::swap(m[3][1], other.m[3][1]);
00158             std::swap(m[3][2], other.m[3][2]);
00159             std::swap(m[3][3], other.m[3][3]);
00160         }
00161 
00162         inline Real* operator [] ( size_t iRow )
00163         {
00164             assert( iRow < 4 );
00165             return m[iRow];
00166         }
00167 
00168         inline const Real *operator [] ( size_t iRow ) const
00169         {
00170             assert( iRow < 4 );
00171             return m[iRow];
00172         }
00173 
00174         inline Matrix4 concatenate(const Matrix4 &m2) const
00175         {
00176             Matrix4 r;
00177             r.m[0][0] = m[0][0] * m2.m[0][0] + m[0][1] * m2.m[1][0] + m[0][2] * m2.m[2][0] + m[0][3] * m2.m[3][0];
00178             r.m[0][1] = m[0][0] * m2.m[0][1] + m[0][1] * m2.m[1][1] + m[0][2] * m2.m[2][1] + m[0][3] * m2.m[3][1];
00179             r.m[0][2] = m[0][0] * m2.m[0][2] + m[0][1] * m2.m[1][2] + m[0][2] * m2.m[2][2] + m[0][3] * m2.m[3][2];
00180             r.m[0][3] = m[0][0] * m2.m[0][3] + m[0][1] * m2.m[1][3] + m[0][2] * m2.m[2][3] + m[0][3] * m2.m[3][3];
00181 
00182             r.m[1][0] = m[1][0] * m2.m[0][0] + m[1][1] * m2.m[1][0] + m[1][2] * m2.m[2][0] + m[1][3] * m2.m[3][0];
00183             r.m[1][1] = m[1][0] * m2.m[0][1] + m[1][1] * m2.m[1][1] + m[1][2] * m2.m[2][1] + m[1][3] * m2.m[3][1];
00184             r.m[1][2] = m[1][0] * m2.m[0][2] + m[1][1] * m2.m[1][2] + m[1][2] * m2.m[2][2] + m[1][3] * m2.m[3][2];
00185             r.m[1][3] = m[1][0] * m2.m[0][3] + m[1][1] * m2.m[1][3] + m[1][2] * m2.m[2][3] + m[1][3] * m2.m[3][3];
00186 
00187             r.m[2][0] = m[2][0] * m2.m[0][0] + m[2][1] * m2.m[1][0] + m[2][2] * m2.m[2][0] + m[2][3] * m2.m[3][0];
00188             r.m[2][1] = m[2][0] * m2.m[0][1] + m[2][1] * m2.m[1][1] + m[2][2] * m2.m[2][1] + m[2][3] * m2.m[3][1];
00189             r.m[2][2] = m[2][0] * m2.m[0][2] + m[2][1] * m2.m[1][2] + m[2][2] * m2.m[2][2] + m[2][3] * m2.m[3][2];
00190             r.m[2][3] = m[2][0] * m2.m[0][3] + m[2][1] * m2.m[1][3] + m[2][2] * m2.m[2][3] + m[2][3] * m2.m[3][3];
00191 
00192             r.m[3][0] = m[3][0] * m2.m[0][0] + m[3][1] * m2.m[1][0] + m[3][2] * m2.m[2][0] + m[3][3] * m2.m[3][0];
00193             r.m[3][1] = m[3][0] * m2.m[0][1] + m[3][1] * m2.m[1][1] + m[3][2] * m2.m[2][1] + m[3][3] * m2.m[3][1];
00194             r.m[3][2] = m[3][0] * m2.m[0][2] + m[3][1] * m2.m[1][2] + m[3][2] * m2.m[2][2] + m[3][3] * m2.m[3][2];
00195             r.m[3][3] = m[3][0] * m2.m[0][3] + m[3][1] * m2.m[1][3] + m[3][2] * m2.m[2][3] + m[3][3] * m2.m[3][3];
00196 
00197             return r;
00198         }
00199 
00202         inline Matrix4 operator * ( const Matrix4 &m2 ) const
00203         {
00204             return concatenate( m2 );
00205         }
00206 
00216         inline Vector3 operator * ( const Vector3 &v ) const
00217         {
00218             Vector3 r;
00219 
00220             Real fInvW = 1.0f / ( m[3][0] * v.x + m[3][1] * v.y + m[3][2] * v.z + m[3][3] );
00221 
00222             r.x = ( m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3] ) * fInvW;
00223             r.y = ( m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3] ) * fInvW;
00224             r.z = ( m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3] ) * fInvW;
00225 
00226             return r;
00227         }
00228         inline Vector4 operator * (const Vector4& v) const
00229         {
00230             return Vector4(
00231                 m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3] * v.w, 
00232                 m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3] * v.w,
00233                 m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3] * v.w,
00234                 m[3][0] * v.x + m[3][1] * v.y + m[3][2] * v.z + m[3][3] * v.w
00235                 );
00236         }
00237         inline Plane operator * (const Plane& p) const
00238         {
00239             Plane ret;
00240             Matrix4 invTrans = inverse().transpose();
00241             Vector4 v4( p.normal.x, p.normal.y, p.normal.z, p.d );
00242             v4 = invTrans * v4;
00243             ret.normal.x = v4.x; 
00244             ret.normal.y = v4.y; 
00245             ret.normal.z = v4.z;
00246             ret.d = v4.w / ret.normal.normalise();
00247 
00248             return ret;
00249         }
00250 
00251 
00254         inline Matrix4 operator + ( const Matrix4 &m2 ) const
00255         {
00256             Matrix4 r;
00257 
00258             r.m[0][0] = m[0][0] + m2.m[0][0];
00259             r.m[0][1] = m[0][1] + m2.m[0][1];
00260             r.m[0][2] = m[0][2] + m2.m[0][2];
00261             r.m[0][3] = m[0][3] + m2.m[0][3];
00262 
00263             r.m[1][0] = m[1][0] + m2.m[1][0];
00264             r.m[1][1] = m[1][1] + m2.m[1][1];
00265             r.m[1][2] = m[1][2] + m2.m[1][2];
00266             r.m[1][3] = m[1][3] + m2.m[1][3];
00267 
00268             r.m[2][0] = m[2][0] + m2.m[2][0];
00269             r.m[2][1] = m[2][1] + m2.m[2][1];
00270             r.m[2][2] = m[2][2] + m2.m[2][2];
00271             r.m[2][3] = m[2][3] + m2.m[2][3];
00272 
00273             r.m[3][0] = m[3][0] + m2.m[3][0];
00274             r.m[3][1] = m[3][1] + m2.m[3][1];
00275             r.m[3][2] = m[3][2] + m2.m[3][2];
00276             r.m[3][3] = m[3][3] + m2.m[3][3];
00277 
00278             return r;
00279         }
00280 
00283         inline Matrix4 operator - ( const Matrix4 &m2 ) const
00284         {
00285             Matrix4 r;
00286             r.m[0][0] = m[0][0] - m2.m[0][0];
00287             r.m[0][1] = m[0][1] - m2.m[0][1];
00288             r.m[0][2] = m[0][2] - m2.m[0][2];
00289             r.m[0][3] = m[0][3] - m2.m[0][3];
00290 
00291             r.m[1][0] = m[1][0] - m2.m[1][0];
00292             r.m[1][1] = m[1][1] - m2.m[1][1];
00293             r.m[1][2] = m[1][2] - m2.m[1][2];
00294             r.m[1][3] = m[1][3] - m2.m[1][3];
00295 
00296             r.m[2][0] = m[2][0] - m2.m[2][0];
00297             r.m[2][1] = m[2][1] - m2.m[2][1];
00298             r.m[2][2] = m[2][2] - m2.m[2][2];
00299             r.m[2][3] = m[2][3] - m2.m[2][3];
00300 
00301             r.m[3][0] = m[3][0] - m2.m[3][0];
00302             r.m[3][1] = m[3][1] - m2.m[3][1];
00303             r.m[3][2] = m[3][2] - m2.m[3][2];
00304             r.m[3][3] = m[3][3] - m2.m[3][3];
00305 
00306             return r;
00307         }
00308 
00311         inline bool operator == ( const Matrix4& m2 ) const
00312         {
00313             if( 
00314                 m[0][0] != m2.m[0][0] || m[0][1] != m2.m[0][1] || m[0][2] != m2.m[0][2] || m[0][3] != m2.m[0][3] ||
00315                 m[1][0] != m2.m[1][0] || m[1][1] != m2.m[1][1] || m[1][2] != m2.m[1][2] || m[1][3] != m2.m[1][3] ||
00316                 m[2][0] != m2.m[2][0] || m[2][1] != m2.m[2][1] || m[2][2] != m2.m[2][2] || m[2][3] != m2.m[2][3] ||
00317                 m[3][0] != m2.m[3][0] || m[3][1] != m2.m[3][1] || m[3][2] != m2.m[3][2] || m[3][3] != m2.m[3][3] )
00318                 return false;
00319             return true;
00320         }
00321 
00324         inline bool operator != ( const Matrix4& m2 ) const
00325         {
00326             if( 
00327                 m[0][0] != m2.m[0][0] || m[0][1] != m2.m[0][1] || m[0][2] != m2.m[0][2] || m[0][3] != m2.m[0][3] ||
00328                 m[1][0] != m2.m[1][0] || m[1][1] != m2.m[1][1] || m[1][2] != m2.m[1][2] || m[1][3] != m2.m[1][3] ||
00329                 m[2][0] != m2.m[2][0] || m[2][1] != m2.m[2][1] || m[2][2] != m2.m[2][2] || m[2][3] != m2.m[2][3] ||
00330                 m[3][0] != m2.m[3][0] || m[3][1] != m2.m[3][1] || m[3][2] != m2.m[3][2] || m[3][3] != m2.m[3][3] )
00331                 return true;
00332             return false;
00333         }
00334 
00337         inline void operator = ( const Matrix3& mat3 )
00338         {
00339             m[0][0] = mat3.m[0][0]; m[0][1] = mat3.m[0][1]; m[0][2] = mat3.m[0][2];
00340             m[1][0] = mat3.m[1][0]; m[1][1] = mat3.m[1][1]; m[1][2] = mat3.m[1][2];
00341             m[2][0] = mat3.m[2][0]; m[2][1] = mat3.m[2][1]; m[2][2] = mat3.m[2][2];
00342         }
00343 
00344         inline Matrix4 transpose(void) const
00345         {
00346             return Matrix4(m[0][0], m[1][0], m[2][0], m[3][0],
00347                            m[0][1], m[1][1], m[2][1], m[3][1],
00348                            m[0][2], m[1][2], m[2][2], m[3][2],
00349                            m[0][3], m[1][3], m[2][3], m[3][3]);
00350         }
00351 
00352         /*
00353         -----------------------------------------------------------------------
00354         Translation Transformation
00355         -----------------------------------------------------------------------
00356         */
00359         inline void setTrans( const Vector3& v )
00360         {
00361             m[0][3] = v.x;
00362             m[1][3] = v.y;
00363             m[2][3] = v.z;
00364         }
00365 
00368         inline Vector3 getTrans() const
00369         {
00370           return Vector3(m[0][3], m[1][3], m[2][3]);
00371         }
00372         
00373 
00376         inline void makeTrans( const Vector3& v )
00377         {
00378             m[0][0] = 1.0; m[0][1] = 0.0; m[0][2] = 0.0; m[0][3] = v.x;
00379             m[1][0] = 0.0; m[1][1] = 1.0; m[1][2] = 0.0; m[1][3] = v.y;
00380             m[2][0] = 0.0; m[2][1] = 0.0; m[2][2] = 1.0; m[2][3] = v.z;
00381             m[3][0] = 0.0; m[3][1] = 0.0; m[3][2] = 0.0; m[3][3] = 1.0;
00382         }
00383 
00384         inline void makeTrans( Real tx, Real ty, Real tz )
00385         {
00386             m[0][0] = 1.0; m[0][1] = 0.0; m[0][2] = 0.0; m[0][3] = tx;
00387             m[1][0] = 0.0; m[1][1] = 1.0; m[1][2] = 0.0; m[1][3] = ty;
00388             m[2][0] = 0.0; m[2][1] = 0.0; m[2][2] = 1.0; m[2][3] = tz;
00389             m[3][0] = 0.0; m[3][1] = 0.0; m[3][2] = 0.0; m[3][3] = 1.0;
00390         }
00391 
00394         inline static Matrix4 getTrans( const Vector3& v )
00395         {
00396             Matrix4 r;
00397 
00398             r.m[0][0] = 1.0; r.m[0][1] = 0.0; r.m[0][2] = 0.0; r.m[0][3] = v.x;
00399             r.m[1][0] = 0.0; r.m[1][1] = 1.0; r.m[1][2] = 0.0; r.m[1][3] = v.y;
00400             r.m[2][0] = 0.0; r.m[2][1] = 0.0; r.m[2][2] = 1.0; r.m[2][3] = v.z;
00401             r.m[3][0] = 0.0; r.m[3][1] = 0.0; r.m[3][2] = 0.0; r.m[3][3] = 1.0;
00402 
00403             return r;
00404         }
00405 
00408         inline static Matrix4 getTrans( Real t_x, Real t_y, Real t_z )
00409         {
00410             Matrix4 r;
00411 
00412             r.m[0][0] = 1.0; r.m[0][1] = 0.0; r.m[0][2] = 0.0; r.m[0][3] = t_x;
00413             r.m[1][0] = 0.0; r.m[1][1] = 1.0; r.m[1][2] = 0.0; r.m[1][3] = t_y;
00414             r.m[2][0] = 0.0; r.m[2][1] = 0.0; r.m[2][2] = 1.0; r.m[2][3] = t_z;
00415             r.m[3][0] = 0.0; r.m[3][1] = 0.0; r.m[3][2] = 0.0; r.m[3][3] = 1.0;
00416 
00417             return r;
00418         }
00419 
00420         /*
00421         -----------------------------------------------------------------------
00422         Scale Transformation
00423         -----------------------------------------------------------------------
00424         */
00427         inline void setScale( const Vector3& v )
00428         {
00429             m[0][0] = v.x;
00430             m[1][1] = v.y;
00431             m[2][2] = v.z;
00432         }
00433 
00436         inline static Matrix4 getScale( const Vector3& v )
00437         {
00438             Matrix4 r;
00439             r.m[0][0] = v.x; r.m[0][1] = 0.0; r.m[0][2] = 0.0; r.m[0][3] = 0.0;
00440             r.m[1][0] = 0.0; r.m[1][1] = v.y; r.m[1][2] = 0.0; r.m[1][3] = 0.0;
00441             r.m[2][0] = 0.0; r.m[2][1] = 0.0; r.m[2][2] = v.z; r.m[2][3] = 0.0;
00442             r.m[3][0] = 0.0; r.m[3][1] = 0.0; r.m[3][2] = 0.0; r.m[3][3] = 1.0;
00443 
00444             return r;
00445         }
00446 
00449         inline static Matrix4 getScale( Real s_x, Real s_y, Real s_z )
00450         {
00451             Matrix4 r;
00452             r.m[0][0] = s_x; r.m[0][1] = 0.0; r.m[0][2] = 0.0; r.m[0][3] = 0.0;
00453             r.m[1][0] = 0.0; r.m[1][1] = s_y; r.m[1][2] = 0.0; r.m[1][3] = 0.0;
00454             r.m[2][0] = 0.0; r.m[2][1] = 0.0; r.m[2][2] = s_z; r.m[2][3] = 0.0;
00455             r.m[3][0] = 0.0; r.m[3][1] = 0.0; r.m[3][2] = 0.0; r.m[3][3] = 1.0;
00456 
00457             return r;
00458         }
00459 
00463         inline void extract3x3Matrix(Matrix3& m3x3) const
00464         {
00465             m3x3.m[0][0] = m[0][0];
00466             m3x3.m[0][1] = m[0][1];
00467             m3x3.m[0][2] = m[0][2];
00468             m3x3.m[1][0] = m[1][0];
00469             m3x3.m[1][1] = m[1][1];
00470             m3x3.m[1][2] = m[1][2];
00471             m3x3.m[2][0] = m[2][0];
00472             m3x3.m[2][1] = m[2][1];
00473             m3x3.m[2][2] = m[2][2];
00474 
00475         }
00476 
00478         inline bool hasScale() const
00479         {
00480             // check magnitude of column vectors (==local axes)
00481             Real t = m[0][0] * m[0][0] + m[1][0] * m[1][0] + m[2][0] * m[2][0];
00482             if (!Math::RealEqual(t, 1.0, (Real)1e-04))
00483                 return true;
00484             t = m[0][1] * m[0][1] + m[1][1] * m[1][1] + m[2][1] * m[2][1];
00485             if (!Math::RealEqual(t, 1.0, (Real)1e-04))
00486                 return true;
00487             t = m[0][2] * m[0][2] + m[1][2] * m[1][2] + m[2][2] * m[2][2];
00488             if (!Math::RealEqual(t, 1.0, (Real)1e-04))
00489                 return true;
00490 
00491             return false;
00492         }
00493 
00495         inline bool hasNegativeScale() const
00496         {
00497             return determinant() < 0;
00498         }
00499 
00502         inline Quaternion extractQuaternion() const
00503         {
00504           Matrix3 m3x3;
00505           extract3x3Matrix(m3x3);
00506           return Quaternion(m3x3);
00507         }
00508 
00509     static const Matrix4 ZERO;
00510     static const Matrix4 ZEROAFFINE;
00511     static const Matrix4 IDENTITY;
00514         static const Matrix4 CLIPSPACE2DTOIMAGESPACE;
00515 
00516         inline Matrix4 operator*(Real scalar) const
00517         {
00518             return Matrix4(
00519                 scalar*m[0][0], scalar*m[0][1], scalar*m[0][2], scalar*m[0][3],
00520                 scalar*m[1][0], scalar*m[1][1], scalar*m[1][2], scalar*m[1][3],
00521                 scalar*m[2][0], scalar*m[2][1], scalar*m[2][2], scalar*m[2][3],
00522                 scalar*m[3][0], scalar*m[3][1], scalar*m[3][2], scalar*m[3][3]);
00523         }
00524 
00527         inline _OgreExport friend std::ostream& operator <<
00528             ( std::ostream& o, const Matrix4& mat )
00529         {
00530             o << "Matrix4(";
00531             for (size_t i = 0; i < 4; ++i)
00532             {
00533                 o << " row" << (unsigned)i << "{";
00534                 for(size_t j = 0; j < 4; ++j)
00535                 {
00536                     o << mat[i][j] << " ";
00537                 }
00538                 o << "}";
00539             }
00540             o << ")";
00541             return o;
00542         }
00543         
00544         Matrix4 adjoint() const;
00545         Real determinant() const;
00546         Matrix4 inverse() const;
00547 
00554         void makeTransform(const Vector3& position, const Vector3& scale, const Quaternion& orientation);
00555 
00561         void makeInverseTransform(const Vector3& position, const Vector3& scale, const Quaternion& orientation);
00562 
00565         void decomposition(Vector3& position, Vector3& scale, Quaternion& orientation) const;
00566 
00572         inline bool isAffine(void) const
00573         {
00574             return m[3][0] == 0 && m[3][1] == 0 && m[3][2] == 0 && m[3][3] == 1;
00575         }
00576 
00581         Matrix4 inverseAffine(void) const;
00582 
00587         inline Matrix4 concatenateAffine(const Matrix4 &m2) const
00588         {
00589             assert(isAffine() && m2.isAffine());
00590 
00591             return Matrix4(
00592                 m[0][0] * m2.m[0][0] + m[0][1] * m2.m[1][0] + m[0][2] * m2.m[2][0],
00593                 m[0][0] * m2.m[0][1] + m[0][1] * m2.m[1][1] + m[0][2] * m2.m[2][1],
00594                 m[0][0] * m2.m[0][2] + m[0][1] * m2.m[1][2] + m[0][2] * m2.m[2][2],
00595                 m[0][0] * m2.m[0][3] + m[0][1] * m2.m[1][3] + m[0][2] * m2.m[2][3] + m[0][3],
00596 
00597                 m[1][0] * m2.m[0][0] + m[1][1] * m2.m[1][0] + m[1][2] * m2.m[2][0],
00598                 m[1][0] * m2.m[0][1] + m[1][1] * m2.m[1][1] + m[1][2] * m2.m[2][1],
00599                 m[1][0] * m2.m[0][2] + m[1][1] * m2.m[1][2] + m[1][2] * m2.m[2][2],
00600                 m[1][0] * m2.m[0][3] + m[1][1] * m2.m[1][3] + m[1][2] * m2.m[2][3] + m[1][3],
00601 
00602                 m[2][0] * m2.m[0][0] + m[2][1] * m2.m[1][0] + m[2][2] * m2.m[2][0],
00603                 m[2][0] * m2.m[0][1] + m[2][1] * m2.m[1][1] + m[2][2] * m2.m[2][1],
00604                 m[2][0] * m2.m[0][2] + m[2][1] * m2.m[1][2] + m[2][2] * m2.m[2][2],
00605                 m[2][0] * m2.m[0][3] + m[2][1] * m2.m[1][3] + m[2][2] * m2.m[2][3] + m[2][3],
00606 
00607                 0, 0, 0, 1);
00608         }
00609 
00617         inline Vector3 transformAffine(const Vector3& v) const
00618         {
00619             assert(isAffine());
00620 
00621             return Vector3(
00622                     m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3], 
00623                     m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3],
00624                     m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3]);
00625         }
00626 
00631         inline Vector4 transformAffine(const Vector4& v) const
00632         {
00633             assert(isAffine());
00634 
00635             return Vector4(
00636                 m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3] * v.w, 
00637                 m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3] * v.w,
00638                 m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3] * v.w,
00639                 v.w);
00640         }
00641     };
00642 
00643     /* Removed from Vector4 and made a non-member here because otherwise
00644        OgreMatrix4.h and OgreVector4.h have to try to include and inline each 
00645        other, which frankly doesn't work ;)
00646    */
00647     inline Vector4 operator * (const Vector4& v, const Matrix4& mat)
00648     {
00649         return Vector4(
00650             v.x*mat[0][0] + v.y*mat[1][0] + v.z*mat[2][0] + v.w*mat[3][0],
00651             v.x*mat[0][1] + v.y*mat[1][1] + v.z*mat[2][1] + v.w*mat[3][1],
00652             v.x*mat[0][2] + v.y*mat[1][2] + v.z*mat[2][2] + v.w*mat[3][2],
00653             v.x*mat[0][3] + v.y*mat[1][3] + v.z*mat[2][3] + v.w*mat[3][3]
00654             );
00655     }
00659 }
00660 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:24 2012