KeosMatrix4.h

Go to the documentation of this file.
00001 /*
00002  * This source file is part of KEOS (Free 3D Engine)
00003  * For the latest info, see http://www.keosengine.org/
00004  * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
00005  *
00006  * This program is free software; you can redistribute it and/or modify it under
00007  * the terms of the GNU Lesser General Public License as published by the Free Software
00008  * Foundation; either version 2 of the License, or (at your option) any later
00009  * version.
00010  *
00011  * This program is distributed in the hope that it will be useful, but WITHOUT
00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License along with
00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00017  * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00018  * http://www.gnu.org/copyleft/lesser.txt.
00019  *
00020  */
00021 
00022 #ifndef KEOS_MATRIX4_H
00023 #define KEOS_MATRIX4_H
00024 
00025 #include "KeosPrerequisites.h"
00026 
00027 namespace Keos
00028 {
00029   //-----------------------------------------------------------------------
00033   class CMatrix4
00034   {
00035   public :
00036 
00039     CMatrix4(Real m11 = 1.0f, Real m12 = 0.0f, Real m13 = 0.0f, Real m14 = 0.0f,
00040              Real m21 = 0.0f, Real m22 = 1.0f, Real m23 = 0.0f, Real m24 = 0.0f,
00041              Real m31 = 0.0f, Real m32 = 0.0f, Real m33 = 1.0f, Real m34 = 0.0f,
00042              Real m41 = 0.0f, Real m42 = 0.0f, Real m43 = 0.0f, Real m44 = 1.0f);
00043 
00046     void Identity();
00047 
00051     Real Determinant() const;
00052 
00056     CMatrix4 Transpose() const;
00057 
00061     CMatrix4 Inverse() const;
00062 
00068     void SetTranslation(Real x, Real y, Real z);
00069 
00073     void SetTranslation(const TVector3F& Trans);
00074 
00080     void SetScaling(Real x, Real y, Real z);
00081 
00085     void SetRotationX(Real Angle);
00086 
00090     void SetRotationY(Real Angle);
00091 
00095     void SetRotationZ(Real Angle);
00096 
00101     void SetRotationX(Real Angle, const TVector3F& Center);
00102 
00107     void SetRotationY(Real Angle, const TVector3F& Center);
00108 
00113     void SetRotationZ(Real Angle, const TVector3F& Center);
00114 
00118     TVector3F GetTranslation() const;
00119 
00125     TVector3F Transform(const TVector3F& v, Real w = 1.0f) const;
00126 
00131     TVector4F Transform(const TVector4F& v) const;
00132 
00139     void OrthoOffCenter(Real Left, Real Top, Real Right, Real Bottom);
00140 
00147     void PerspectiveFOV(Real Fov, Real Ratio, Real Near, Real Far);
00148     //void PerspectiveFOV2(Real Fov, Real Ratio, Real Near, Real Far);
00149 
00155     void LookAt(const TVector3F& From, const TVector3F& To, const TVector3F& Up = TVector3F(0, 1, 0));
00156 
00157     // Operators
00158     CMatrix4 operator +() const;
00159     CMatrix4 operator -() const;
00160     CMatrix4 operator +(const CMatrix4& m) const;
00161     CMatrix4 operator -(const CMatrix4& m) const;
00162     const CMatrix4& operator +=(const CMatrix4& m);
00163     const CMatrix4& operator -=(const CMatrix4& m);
00164     CMatrix4 operator *(const CMatrix4& m) const;
00165     const CMatrix4& operator *=(const CMatrix4& m);
00166     const CMatrix4& operator *=(Real t);
00167     const CMatrix4& operator /=(Real t);
00168     bool operator ==(const CMatrix4& m) const;
00169     bool operator !=(const CMatrix4& m) const;
00170 
00176     Real& operator ()(size_t i, size_t j);
00177 
00183     const Real& operator ()(size_t i, size_t j) const;
00184 
00187     operator Real*();
00188 
00191     operator const Real*() const;
00192 
00193     Real a11, a21, a31, a41; // Matrix first line
00194     Real a12, a22, a32, a42; // Matrix second line
00195     Real a13, a23, a33, a43; // Matrix third line
00196     Real a14, a24, a34, a44; // Matrix fourth line
00197   };
00198 
00199   // Globals functions
00200   CMatrix4      operator * (const CMatrix4& m, Real t);
00201   CMatrix4      operator * (Real t, const CMatrix4& m);
00202   CMatrix4      operator / (const CMatrix4& m, Real t);
00203   std::istream& operator >>(std::istream& Stream, CMatrix4& Mat);
00204   std::ostream& operator <<(std::ostream& Stream, const CMatrix4& Mat);
00205 
00206 
00207   //=======================================================================
00208   // CMatrix4 inline functions
00209   //=======================================================================
00210 
00211   //-----------------------------------------------------------------------
00212   inline CMatrix4::CMatrix4(Real m11, Real m12, Real m13, Real m14,
00213                             Real m21, Real m22, Real m23, Real m24,
00214                             Real m31, Real m32, Real m33, Real m34,
00215                             Real m41, Real m42, Real m43, Real m44) :
00216       a11(m11), a12(m12), a13(m13), a14(m14),
00217       a21(m21), a22(m22), a23(m23), a24(m24),
00218       a31(m31), a32(m32), a33(m33), a34(m34),
00219       a41(m41), a42(m42), a43(m43), a44(m44)
00220   {}
00221 
00222   //-----------------------------------------------------------------------
00223   inline void CMatrix4::Identity()
00224   {
00225     a11 = 1.0f;
00226     a12 = 0.0f;
00227     a13 = 0.0f;
00228     a14 = 0.0f;
00229     a21 = 0.0f;
00230     a22 = 1.0f;
00231     a23 = 0.0f;
00232     a24 = 0.0f;
00233     a31 = 0.0f;
00234     a32 = 0.0f;
00235     a33 = 1.0f;
00236     a34 = 0.0f;
00237     a41 = 0.0f;
00238     a42 = 0.0f;
00239     a43 = 0.0f;
00240     a44 = 1.0f;
00241   }
00242 
00243   //-----------------------------------------------------------------------
00244   inline Real CMatrix4::Determinant() const
00245   {
00246     Real A = a22 * (a33 * a44 - a43 * a34) - a32 * (a23 * a44 - a43 * a24) + a42 * (a23 * a34 - a33 * a24);
00247     Real B = a12 * (a33 * a44 - a43 * a34) - a32 * (a13 * a44 - a43 * a14) + a42 * (a13 * a34 - a33 * a14);
00248     Real C = a12 * (a23 * a44 - a43 * a24) - a22 * (a13 * a44 - a43 * a14) + a42 * (a13 * a24 - a23 * a14);
00249     Real D = a12 * (a23 * a34 - a33 * a24) - a22 * (a13 * a34 - a33 * a14) + a32 * (a13 * a24 - a23 * a14);
00250 
00251     return a11 * A - a21 * B + a31 * C - a41 * D;
00252   }
00253 
00254   //-----------------------------------------------------------------------
00255   inline CMatrix4 CMatrix4::Transpose() const
00256   {
00257     return CMatrix4(a11, a21, a31, a41,
00258                     a12, a22, a32, a42,
00259                     a13, a23, a33, a43,
00260                     a14, a24, a34, a44);
00261   }
00262 
00263   //-----------------------------------------------------------------------
00264   inline CMatrix4 CMatrix4::Inverse() const
00265   {
00266     CMatrix4 Ret;
00267     Real Det = Determinant();
00268 
00269     if (std::fabs(Det) > std::numeric_limits<Real>::epsilon())
00270     {
00271       Ret.a11 =  (a22 * (a33 * a44 - a34 * a43) - a32 * (a23 * a44 - a43 * a24) + a42 * (a23 * a34 - a33 *  a24)) / Det;
00272       Ret.a12 = -(a12 * (a33 * a44 - a43 * a34) - a32 * (a13 * a44 - a43 * a14) + a42 * (a13 * a34 - a33 *  a14)) / Det;
00273       Ret.a13 =  (a12 * (a23 * a44 - a43 * a24) - a22 * (a13 * a44 - a43 * a14) + a42 * (a13 * a24 - a23 *  a14)) / Det;
00274       Ret.a14 = -(a12 * (a23 * a34 - a33 * a24) - a22 * (a13 * a34 - a33 * a14) + a32 * (a13 * a24 - a23 *  a14)) / Det;
00275 
00276       Ret.a21 = -(a21 * (a33 * a44 - a34 * a43) - a23 * (a31 * a44 - a34 * a41) + a24 * (a31 * a43 - a33 *  a41)) / Det;
00277       Ret.a22 =  (a11 * (a33 * a44 - a34 * a43) - a13 * (a31 * a44 - a34 * a41) + a14 * (a31 * a43 - a33 *  a41)) / Det;
00278       Ret.a23 = -(a11 * (a23 * a44 - a24 * a43) - a13 * (a21 * a44 - a24 * a41) + a14 * (a21 * a43 - a23 *  a41)) / Det;
00279       Ret.a24 =  (a11 * (a23 * a34 - a24 * a33) - a13 * (a21 * a34 - a24 * a31) + a14 * (a21 * a33 - a23 *  a31)) / Det;
00280 
00281       Ret.a31 =  (a21 * (a32 * a44 - a34 * a42) - a22 * (a31 * a44 - a34 * a41) + a24 * (a31 * a42 - a32 *  a41)) / Det;
00282       Ret.a32 = -(a11 * (a32 * a44 - a34 * a42) - a12 * (a31 * a44 - a34 * a41) + a14 * (a31 * a42 - a32 *  a41)) / Det;
00283       Ret.a33 =  (a11 * (a22 * a44 - a24 * a42) - a12 * (a21 * a44 - a24 * a41) + a14 * (a21 * a42 - a22 *  a41)) / Det;
00284       Ret.a34 = -(a11 * (a22 * a34 - a24 * a32) - a12 * (a21 * a34 - a24 * a31) + a14 * (a21 * a32 - a22 *  a31)) / Det;
00285 
00286       Ret.a41 = -(a21 * (a32 * a43 - a33 * a42) - a22 * (a31 * a43 - a33 * a41) + a23 * (a31 * a42 - a32 *  a41)) / Det;
00287       Ret.a42 =  (a11 * (a32 * a43 - a33 * a42) - a12 * (a31 * a43 - a33 * a41) + a13 * (a31 * a42 - a32 *  a41)) / Det;
00288       Ret.a43 = -(a11 * (a22 * a43 - a23 * a42) - a12 * (a21 * a43 - a23 * a41) + a13 * (a21 * a42 - a22 *  a41)) / Det;
00289       Ret.a44 =  (a11 * (a22 * a33 - a23 * a32) - a12 * (a21 * a33 - a23 * a31) + a13 * (a21 * a32 - a22 *  a31)) / Det;
00290     }
00291 
00292     return Ret;
00293   }
00294 
00295   //-----------------------------------------------------------------------
00296   inline void CMatrix4::SetTranslation(Real x, Real y, Real z)
00297   {
00298     a11 = 1.0f;
00299     a12 = 0.0f;
00300     a13 = 0.0f;
00301     a14 = x;
00302     a21 = 0.0f;
00303     a22 = 1.0f;
00304     a23 = 0.0f;
00305     a24 = y;
00306     a31 = 0.0f;
00307     a32 = 0.0f;
00308     a33 = 1.0f;
00309     a34 = z;
00310     a41 = 0.0f;
00311     a42 = 0.0f;
00312     a43 = 0.0f;
00313     a44 = 1.0f;
00314   }
00315 
00316   //-----------------------------------------------------------------------
00317   inline void CMatrix4::SetTranslation(const TVector3F& Trans)
00318   {
00319     SetTranslation(Trans.x, Trans.y, Trans.z);
00320   }
00321 
00322   //-----------------------------------------------------------------------
00323   inline void CMatrix4::SetScaling(Real x, Real y, Real z)
00324   {
00325     a11 = x;
00326     a12 = 0.0f;
00327     a13 = 0.0f;
00328     a14 = 0.0f;
00329     a21 = 0.0f;
00330     a22 = y;
00331     a23 = 0.0f;
00332     a24 = 0.0f;
00333     a31 = 0.0f;
00334     a32 = 0.0f;
00335     a33 = z;
00336     a34 = 0.0f;
00337     a41 = 0.0f;
00338     a42 = 0.0f;
00339     a43 = 0.0f;
00340     a44 = 1.0f;
00341   }
00342 
00343   //-----------------------------------------------------------------------
00344   inline void CMatrix4::SetRotationX(Real Angle)
00345   {
00346     Real Cos = std::cos(Angle);
00347     Real Sin = std::sin(Angle);
00348 
00349     a11 = 1.0f;
00350     a12 = 0.0f;
00351     a13 = 0.0f;
00352     a14 = 0.0f;
00353     a21 = 0.0f;
00354     a22 = Cos;
00355     a23 = Sin;
00356     a24 = 0.0f;
00357     a31 = 0.0f;
00358     a32 = -Sin;
00359     a33 = Cos;
00360     a34 = 0.0f;
00361     a41 = 0.0f;
00362     a42 = 0.0f;
00363     a43 = 0.0f;
00364     a44 = 1.0f;
00365   }
00366 
00367   //-----------------------------------------------------------------------
00368   inline void CMatrix4::SetRotationY(Real Angle)
00369   {
00370     Real Cos = std::cos(Angle);
00371     Real Sin = std::sin(Angle);
00372 
00373     a11 = Cos;
00374     a12 = 0.0f;
00375     a13 = -Sin;
00376     a14 = 0.0f;
00377     a21 = 0.0f;
00378     a22 = 1.0f;
00379     a23 = 0.0f;
00380     a24 = 0.0f;
00381     a31 = Sin;
00382     a32 = 0.0f;
00383     a33 = Cos;
00384     a34 = 0.0f;
00385     a41 = 0.0f;
00386     a42 = 0.0f;
00387     a43 = 0.0f;
00388     a44 = 1.0f;
00389   }
00390 
00391   //-----------------------------------------------------------------------
00392   inline void CMatrix4::SetRotationZ(Real Angle)
00393   {
00394     Real Cos = std::cos(Angle);
00395     Real Sin = std::sin(Angle);
00396 
00397     a11 = Cos;
00398     a12 = Sin;
00399     a13 = 0.0f;
00400     a14 = 0.0f;
00401     a21 = -Sin;
00402     a22 = Cos;
00403     a23 = 0.0f;
00404     a24 = 0.0f;
00405     a31 = 0.0f;
00406     a32 = 0.0f;
00407     a33 = 1.0f;
00408     a34 = 0.0f;
00409     a41 = 0.0f;
00410     a42 = 0.0f;
00411     a43 = 0.0f;
00412     a44 = 1.0f;
00413   }
00414 
00415   //-----------------------------------------------------------------------
00416   inline void CMatrix4::SetRotationX(Real Angle, const TVector3F& Center)
00417   {
00418     CMatrix4 Tr1, Tr2, Rot;
00419 
00420     Tr1.SetTranslation(Center.x, Center.y, Center.z);
00421     Tr2.SetTranslation(-Center.x, -Center.y, -Center.z);
00422     Rot.SetRotationX(Angle);
00423 
00424     *this = Tr1 * Rot * Tr2;
00425   }
00426 
00427   //-----------------------------------------------------------------------
00428   inline void CMatrix4::SetRotationY(Real Angle, const TVector3F& Center)
00429   {
00430     CMatrix4 Tr1, Tr2, Rot;
00431 
00432     Tr1.SetTranslation(Center.x, Center.y, Center.z);
00433     Tr2.SetTranslation(-Center.x, -Center.y, -Center.z);
00434     Rot.SetRotationY(Angle);
00435 
00436     *this = Tr1 * Rot * Tr2;
00437   }
00438 
00439   //-----------------------------------------------------------------------
00440   inline void CMatrix4::SetRotationZ(Real Angle, const TVector3F& Center)
00441   {
00442     CMatrix4 Tr1, Tr2, Rot;
00443 
00444     Tr1.SetTranslation(Center.x, Center.y, Center.z);
00445     Tr2.SetTranslation(-Center.x, -Center.y, -Center.z);
00446     Rot.SetRotationZ(Angle);
00447 
00448     *this = Tr1 * Rot * Tr2;
00449   }
00450 
00451   //-----------------------------------------------------------------------
00452   inline TVector3F CMatrix4::GetTranslation() const
00453   {
00454     return TVector3F(a14, a24, a34);
00455   }
00456 
00457   //-----------------------------------------------------------------------
00458   inline TVector3F CMatrix4::Transform(const TVector3F& v, Real w) const
00459   {
00460     return TVector3F(v.x * a11 + v.y * a21 + v.z * a31 + w * a41,
00461                      v.x * a12 + v.y * a22 + v.z * a32 + w * a42,
00462                      v.x * a13 + v.y * a23 + v.z * a33 + w * a43);
00463   }
00464 
00465   //-----------------------------------------------------------------------
00466   inline TVector4F CMatrix4::Transform(const TVector4F& v) const
00467   {
00468     return TVector4F(v.x * a11 + v.y * a21 + v.z * a31 + v.w * a41,
00469                      v.x * a12 + v.y * a22 + v.z * a32 + v.w * a42,
00470                      v.x * a13 + v.y * a23 + v.z * a33 + v.w * a43,
00471                      v.x * a14 + v.y * a24 + v.z * a34 + v.w * a44);
00472   }
00473 
00474   //-----------------------------------------------------------------------
00475   inline void CMatrix4::OrthoOffCenter(Real Left, Real Top, Real Right, Real Bottom)
00476   {
00477     a11 = 2 / (Right - Left);
00478     a12 = 0.0f;
00479     a13 = 0.0f;
00480     a14 = (Left + Right) / (Left - Right);
00481     a21 = 0.0f;
00482     a22 = 2 / (Top - Bottom);
00483     a23 = 0.0f;
00484     a24 = (Bottom + Top) / (Bottom - Top);
00485     a31 = 0.0f;
00486     a32 = 0.0f;
00487     a33 = 1.0f;
00488     a34 = 0.0f;
00489     a41 = 0.0f;
00490     a42 = 0.0f;
00491     a43 = 0.0f;
00492     a44 = 1.0f;
00493   }
00494 
00495   //-----------------------------------------------------------------------
00496   inline void CMatrix4::PerspectiveFOV(Real Fov, Real Ratio, Real Near, Real Far)
00497   {
00498     Real YScale = 1.0f / std::tan(Fov / 2);
00499     Real XScale = YScale / Ratio;
00500     Real Coeff  = Far / (Far - Near);
00501 
00502     a11 = XScale;
00503     a12 = 0.0f;
00504     a13 = 0.0f;
00505     a14 = 0.0f;
00506     a21 = 0.0f;
00507     a22 = YScale;
00508     a23 = 0.0f;
00509     a24 = 0.0f;
00510     a31 = 0.0f;
00511     a32 = 0.0f;
00512     a33 = Coeff;
00513     a34 = Near * -Coeff;
00514     a41 = 0.0f;
00515     a42 = 0.0f;
00516     a43 = 1.0f;
00517     a44 = 0.0f;
00518   }
00519 
00520   /*inline void CMatrix4::PerspectiveFOV(Real Fov, Real Ratio, Real Near, Real Far)
00521      {
00522    Real h = std::cos(Fov/2) / std::sin(Fov/2);
00523          Real w = h / Ratio;
00524          Real zn  = Near;
00525    Real zf  = Far;
00526 
00527          a11 = 2*zn/w; a21 = 0.0f;   a31 = 0.0f;    a41 = 0.0f;
00528          a12 = 0.0f;   a22 = 2*zn/h; a32 = 0.0f;    a42 = 0.0f;
00529          a13 = 0.0f;   a23 = 0.0f;   a33 = zf/(zf-zn);  a43 = 1.0f;
00530          a14 = 0.0f;   a24 = 0.0f;   a34 = zn*zf/(zn-zf); a44 = 0.0f;
00531      }*/
00532 
00533   //-----------------------------------------------------------------------
00534   inline void CMatrix4::LookAt(const TVector3F& From, const TVector3F& To, const TVector3F& Up)
00535   {
00536     // TODO : gérer le cas où (To - From) et Up sont colinéaires
00537 
00538     TVector3F ZAxis = To - From;
00539     ZAxis.Normalize();
00540     TVector3F XAxis = VectorCross(Up, ZAxis);
00541     XAxis.Normalize();
00542     TVector3F YAxis = VectorCross(ZAxis, XAxis);
00543 
00544     a11 = XAxis.x;
00545     a12 = XAxis.y;
00546     a13 = XAxis.z;
00547     a14 = -VectorDot(XAxis, From);
00548     a21 = YAxis.x;
00549     a22 = YAxis.y;
00550     a23 = YAxis.z;
00551     a24 = -VectorDot(YAxis, From);
00552     a31 = ZAxis.x;
00553     a32 = ZAxis.y;
00554     a33 = ZAxis.z;
00555     a34 = -VectorDot(ZAxis, From);
00556     a41 = 0.0f;
00557     a42 = 0.0f;
00558     a43 = 0.0f;
00559     a44 = 1.0f;
00560   }
00561 
00562   //-----------------------------------------------------------------------
00563   inline CMatrix4 CMatrix4::operator +() const
00564   {
00565     return *this;
00566   }
00567 
00568   //-----------------------------------------------------------------------
00569   inline CMatrix4 CMatrix4::operator -() const
00570   {
00571     return CMatrix4(-a11, -a12, -a13, -a14,
00572                     -a21, -a22, -a23, -a24,
00573                     -a31, -a32, -a33, -a34,
00574                     -a41, -a42, -a43, -a44);
00575   }
00576 
00577   //-----------------------------------------------------------------------
00578   inline CMatrix4 CMatrix4::operator +(const CMatrix4& m) const
00579   {
00580     return CMatrix4(a11 + m.a11, a12 + m.a12, a13 + m.a13, a14 + m.a14,
00581                     a21 + m.a21, a22 + m.a22, a23 + m.a23, a24 + m.a24,
00582                     a31 + m.a31, a32 + m.a32, a33 + m.a33, a34 + m.a34,
00583                     a41 + m.a41, a42 + m.a42, a43 + m.a43, a44 + m.a44);
00584   }
00585 
00586   //-----------------------------------------------------------------------
00587   inline CMatrix4 CMatrix4::operator -(const CMatrix4& m) const
00588   {
00589     return CMatrix4(a11 - m.a11, a12 - m.a12, a13 - m.a13, a14 - m.a14,
00590                     a21 - m.a21, a22 - m.a22, a23 - m.a23, a24 - m.a24,
00591                     a31 - m.a31, a32 - m.a32, a33 - m.a33, a34 - m.a34,
00592                     a41 - m.a41, a42 - m.a42, a43 - m.a43, a44 - m.a44);
00593   }
00594 
00595   //-----------------------------------------------------------------------
00596   inline const CMatrix4& CMatrix4::operator +=(const CMatrix4& m)
00597   {
00598     a11 += m.a11;
00599     a12 += m.a12;
00600     a13 += m.a13;
00601     a14 += m.a14;
00602     a21 += m.a21;
00603     a22 += m.a22;
00604     a23 += m.a23;
00605     a24 += m.a24;
00606     a31 += m.a31;
00607     a32 += m.a32;
00608     a33 += m.a33;
00609     a34 += m.a34;
00610     a41 += m.a41;
00611     a42 += m.a42;
00612     a43 += m.a43;
00613     a44 += m.a44;
00614 
00615     return *this;
00616   }
00617 
00618   //-----------------------------------------------------------------------
00619   inline const CMatrix4& CMatrix4::operator -=(const CMatrix4& m)
00620   {
00621     a11 -= m.a11;
00622     a12 -= m.a12;
00623     a13 -= m.a13;
00624     a14 -= m.a14;
00625     a21 -= m.a21;
00626     a22 -= m.a22;
00627     a23 -= m.a23;
00628     a24 -= m.a24;
00629     a31 -= m.a31;
00630     a32 -= m.a32;
00631     a33 -= m.a33;
00632     a34 -= m.a34;
00633     a41 -= m.a41;
00634     a42 -= m.a42;
00635     a43 -= m.a43;
00636     a44 -= m.a44;
00637 
00638     return *this;
00639   }
00640 
00641   //-----------------------------------------------------------------------
00642   inline CMatrix4 CMatrix4::operator *(const CMatrix4& m) const
00643   {
00644     return CMatrix4(a11 * m.a11 + a21 * m.a12 + a31 * m.a13 + a41 * m.a14,
00645                     a12 * m.a11 + a22 * m.a12 + a32 * m.a13 + a42 * m.a14,
00646                     a13 * m.a11 + a23 * m.a12 + a33 * m.a13 + a43 * m.a14,
00647                     a14 * m.a11 + a24 * m.a12 + a34 * m.a13 + a44 * m.a14,
00648 
00649                     a11 * m.a21 + a21 * m.a22 + a31 * m.a23 + a41 * m.a24,
00650                     a12 * m.a21 + a22 * m.a22 + a32 * m.a23 + a42 * m.a24,
00651                     a13 * m.a21 + a23 * m.a22 + a33 * m.a23 + a43 * m.a24,
00652                     a14 * m.a21 + a24 * m.a22 + a34 * m.a23 + a44 * m.a24,
00653 
00654                     a11 * m.a31 + a21 * m.a32 + a31 * m.a33 + a41 * m.a34,
00655                     a12 * m.a31 + a22 * m.a32 + a32 * m.a33 + a42 * m.a34,
00656                     a13 * m.a31 + a23 * m.a32 + a33 * m.a33 + a43 * m.a34,
00657                     a14 * m.a31 + a24 * m.a32 + a34 * m.a33 + a44 * m.a34,
00658 
00659                     a11 * m.a41 + a21 * m.a42 + a31 * m.a43 + a41 * m.a44,
00660                     a12 * m.a41 + a22 * m.a42 + a32 * m.a43 + a42 * m.a44,
00661                     a13 * m.a41 + a23 * m.a42 + a33 * m.a43 + a43 * m.a44,
00662                     a14 * m.a41 + a24 * m.a42 + a34 * m.a43 + a44 * m.a44);
00663   }
00664 
00665   //-----------------------------------------------------------------------
00666   inline const CMatrix4& CMatrix4::operator *=(const CMatrix4& m)
00667   {
00668     *this = *this * m;
00669 
00670     return *this;
00671   }
00672 
00673   //-----------------------------------------------------------------------
00674   inline const CMatrix4& CMatrix4::operator *=(Real t)
00675   {
00676     a11 *= t;
00677     a12 *= t;
00678     a13 *= t;
00679     a14 *= t;
00680     a21 *= t;
00681     a22 *= t;
00682     a23 *= t;
00683     a24 *= t;
00684     a31 *= t;
00685     a32 *= t;
00686     a33 *= t;
00687     a34 *= t;
00688     a41 *= t;
00689     a42 *= t;
00690     a43 *= t;
00691     a44 *= t;
00692 
00693     return *this;
00694   }
00695 
00696   //-----------------------------------------------------------------------
00697   inline const CMatrix4& CMatrix4::operator /=(Real t)
00698   {
00699     a11 /= t;
00700     a12 /= t;
00701     a13 /= t;
00702     a14 /= t;
00703     a21 /= t;
00704     a22 /= t;
00705     a23 /= t;
00706     a24 /= t;
00707     a31 /= t;
00708     a32 /= t;
00709     a33 /= t;
00710     a34 /= t;
00711     a41 /= t;
00712     a42 /= t;
00713     a43 /= t;
00714     a44 /= t;
00715 
00716     return *this;
00717   }
00718 
00719   //-----------------------------------------------------------------------
00720   inline bool CMatrix4::operator ==(const CMatrix4& m) const
00721   {
00722     return ((std::fabs(a11 - m.a11) < std::numeric_limits<Real>::epsilon()) && (std::fabs(a12 - m.a12) < std::numeric_limits<Real>::epsilon()) &&
00723             (std::fabs(a13 - m.a13) < std::numeric_limits<Real>::epsilon()) && (std::fabs(a14 - m.a14) < std::numeric_limits<Real>::epsilon()) &&
00724             (std::fabs(a21 - m.a21) < std::numeric_limits<Real>::epsilon()) && (std::fabs(a22 - m.a22) < std::numeric_limits<Real>::epsilon()) &&
00725             (std::fabs(a23 - m.a23) < std::numeric_limits<Real>::epsilon()) && (std::fabs(a24 - m.a24) < std::numeric_limits<Real>::epsilon()) &&
00726             (std::fabs(a31 - m.a31) < std::numeric_limits<Real>::epsilon()) && (std::fabs(a32 - m.a32) < std::numeric_limits<Real>::epsilon()) &&
00727             (std::fabs(a33 - m.a33) < std::numeric_limits<Real>::epsilon()) && (std::fabs(a34 - m.a34) < std::numeric_limits<Real>::epsilon()) &&
00728             (std::fabs(a41 - m.a41) < std::numeric_limits<Real>::epsilon()) && (std::fabs(a42 - m.a42) < std::numeric_limits<Real>::epsilon()) &&
00729             (std::fabs(a43 - m.a43) < std::numeric_limits<Real>::epsilon()) && (std::fabs(a44 - m.a44) < std::numeric_limits<Real>::epsilon()));
00730   }
00731 
00732   //-----------------------------------------------------------------------
00733   inline bool CMatrix4::operator !=(const CMatrix4& m) const
00734   {
00735     return !(*this == m);
00736   }
00737 
00738   //-----------------------------------------------------------------------
00739   inline Real& CMatrix4::operator ()(size_t i, size_t j)
00740   {
00741     return operator Real*()[i + 4 * j];
00742   }
00743 
00744   //-----------------------------------------------------------------------
00745   inline const Real& CMatrix4::operator ()(size_t i, size_t j) const
00746   {
00747     return operator ()(i, j);
00748   }
00749 
00750   //-----------------------------------------------------------------------
00751   inline CMatrix4::operator const Real*() const
00752   {
00753     return &a11;
00754   }
00755 
00756   //-----------------------------------------------------------------------
00757   inline CMatrix4::operator Real*()
00758   {
00759     return &a11;
00760   }
00761 
00762   //-----------------------------------------------------------------------
00763   inline CMatrix4 operator *(const CMatrix4& m, Real t)
00764   {
00765     return CMatrix4(m.a11 * t, m.a12 * t, m.a13 * t, m.a14 * t,
00766                     m.a21 * t, m.a22 * t, m.a23 * t, m.a24 * t,
00767                     m.a31 * t, m.a32 * t, m.a33 * t, m.a34 * t,
00768                     m.a41 * t, m.a42 * t, m.a43 * t, m.a44 * t);
00769   }
00770 
00771   //-----------------------------------------------------------------------
00772   inline CMatrix4 operator *(Real t, const CMatrix4& m)
00773   {
00774     return m * t;
00775   }
00776 
00777   //-----------------------------------------------------------------------
00778   inline CMatrix4 operator /(const CMatrix4& m, Real t)
00779   {
00780     return CMatrix4(m.a11 / t, m.a12 / t, m.a13 / t, m.a14 / t,
00781                     m.a21 / t, m.a22 / t, m.a23 / t, m.a24 / t,
00782                     m.a31 / t, m.a32 / t, m.a33 / t, m.a34 / t,
00783                     m.a41 / t, m.a42 / t, m.a43 / t, m.a44 / t);
00784   }
00785 
00786   //-----------------------------------------------------------------------
00787   inline std::istream& operator >>(std::istream& Stream, CMatrix4& Mat)
00788   {
00789     Stream >> Mat.a11 >> Mat.a12 >> Mat.a13 >> Mat.a14;
00790     Stream >> Mat.a21 >> Mat.a22 >> Mat.a23 >> Mat.a24;
00791     Stream >> Mat.a31 >> Mat.a32 >> Mat.a33 >> Mat.a34;
00792     Stream >> Mat.a41 >> Mat.a42 >> Mat.a43 >> Mat.a44;
00793 
00794     return Stream;
00795   }
00796 
00797   //-----------------------------------------------------------------------
00798   inline std::ostream& operator <<(std::ostream& Stream, const CMatrix4& Mat)
00799   {
00800     Stream << Mat.a11 << " " << Mat.a12 << " " << Mat.a13 << " " << Mat.a14 << std::endl;
00801     Stream << Mat.a21 << " " << Mat.a22 << " " << Mat.a23 << " " << Mat.a24 << std::endl;
00802     Stream << Mat.a31 << " " << Mat.a32 << " " << Mat.a33 << " " << Mat.a34 << std::endl;
00803     Stream << Mat.a41 << " " << Mat.a42 << " " << Mat.a43 << " " << Mat.a44 << std::endl;
00804 
00805     return Stream;
00806   }
00807 
00808 } // namespace Keos
00809 
00810 #endif // KEOS_MATRIX4_H

Generated on Fri Mar 9 14:29:02 2007 for Keos by  doxygen 1.5.1-p1