Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGMatrix.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #ifndef _OSGMATRIX_H_
00040 #define _OSGMATRIX_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044 
00045 #include <OSGVector.h>
00046 
00047 OSG_BEGIN_NAMESPACE
00048 
00049 #if defined(OSG_MICROSOFT_COMPILER_HACKS) || defined(__sun)
00050 static const UInt32 JacobiRank = 3;
00051 #endif
00052 
00053 template <class ValueTypeT> class QuaternionBase;
00054 
00063 template<class ValueTypeT>
00064 class TransformationMatrix
00065 {
00066     /*==========================  PUBLIC  =================================*/
00067 
00068   public:
00069 
00070     /*---------------------------------------------------------------------*/
00074     typedef                 ValueTypeT                ValueType;
00075     typedef VectorInterface<ValueTypeT, 
00076                             VecStorage4<ValueTypeT> > VectorType;
00077 
00078     typedef QuaternionBase <ValueType>                QuaternionType;
00079 
00080     typedef VectorInterface<ValueTypeT, 
00081                             VecStorage3<ValueTypeT> > VectorType3f;
00082 
00083     typedef PointInterface<ValueTypeT, 
00084                            VecStorage3<ValueTypeT>  > PointType3f;
00085 
00087     /*---------------------------------------------------------------------*/
00091     static const TransformationMatrix &identity(void);
00092 
00094     /*---------------------------------------------------------------------*/
00098     TransformationMatrix(void);
00099     TransformationMatrix(const TransformationMatrix &source );
00100 
00101     TransformationMatrix(const VectorType3f         &vector1,
00102                          const VectorType3f         &vector2,
00103                          const VectorType3f         &vector3);    
00104 
00105     TransformationMatrix(const VectorType3f         &vector1,
00106                          const VectorType3f         &vector2,
00107                          const VectorType3f         &vector3,
00108                          const VectorType3f         &vector4);    
00109 
00110     TransformationMatrix(const ValueTypeT            rVal00,
00111                          const ValueTypeT            rVal10,
00112                          const ValueTypeT            rVal20,
00113                          const ValueTypeT            rVal30,
00114                          
00115                          const ValueTypeT            rVal01,
00116                          const ValueTypeT            rVal11,
00117                          const ValueTypeT            rVal21,
00118                          const ValueTypeT            rVal31,
00119                          
00120                          const ValueTypeT            rVal02,
00121                          const ValueTypeT            rVal12,
00122                          const ValueTypeT            rVal22,
00123                          const ValueTypeT            rVal32,
00124                          
00125                          const ValueTypeT            rVal03,
00126                          const ValueTypeT            rVal13,
00127                          const ValueTypeT            rVal23,
00128                          const ValueTypeT            rVal33);
00129  
00131     /*---------------------------------------------------------------------*/
00135     ~TransformationMatrix(void); 
00136 
00138     /*---------------------------------------------------------------------*/
00142     void setIdentity       (void                                           );
00143 
00144     void setValue          (const TransformationMatrix &mat                );
00145 
00146     void setValue          (const VectorType3f         &vector1,
00147                             const VectorType3f         &vector2,
00148                             const VectorType3f         &vector3            );
00149 
00150     void setValue          (const VectorType3f         &vector1,
00151                             const VectorType3f         &vector2,
00152                             const VectorType3f         &vector3,
00153                             const VectorType3f         &vector4            );
00154 
00155     void setValue          (const ValueTypeT            rVal00,
00156                             const ValueTypeT            rVal10,
00157                             const ValueTypeT            rVal20,
00158                             const ValueTypeT            rVal30,
00159                             
00160                             const ValueTypeT            rVal01,
00161                             const ValueTypeT            rVal11,
00162                             const ValueTypeT            rVal21,
00163                             const ValueTypeT            rVal31,
00164                             
00165                             const ValueTypeT            rVal02,
00166                             const ValueTypeT            rVal12,
00167                             const ValueTypeT            rVal22,
00168                             const ValueTypeT            rVal32,
00169                             
00170                             const ValueTypeT            rVal03,
00171                             const ValueTypeT            rVal13,
00172                             const ValueTypeT            rVal23,
00173                             const ValueTypeT            rVal33             );
00174 
00175     void setValueTransposed(const ValueTypeT            rVal00,
00176                             const ValueTypeT            rVal01,
00177                             const ValueTypeT            rVal02,
00178                             const ValueTypeT            rVal03,
00179                             
00180                             const ValueTypeT            rVal10,
00181                             const ValueTypeT            rVal11,
00182                             const ValueTypeT            rVal12,
00183                             const ValueTypeT            rVal13,
00184                             
00185                             const ValueTypeT            rVal20,
00186                             const ValueTypeT            rVal21,
00187                             const ValueTypeT            rVal22,
00188                             const ValueTypeT            rVal23,
00189                             
00190                             const ValueTypeT            rVal30,
00191                             const ValueTypeT            rVal31,
00192                             const ValueTypeT            rVal32,
00193                             const ValueTypeT            rVal33             );
00194 
00195     void setValue          (const ValueTypeT           *pMat,
00196                                   bool                  bTransposed = true );
00197 
00198     void setValue          (const VectorType           *pMat               );
00199 
00200 #ifndef WIN32
00201     void setValue          (const VectorType3f         *pMat               );
00202 #endif
00203 
00204     void setValue           (const Char8               *string,
00205                                    bool                 bTransposed = true );
00206 
00208     /*---------------------------------------------------------------------*/
00212           ValueTypeT *getValues(void);
00213     const ValueTypeT *getValues(void) const;
00214     
00216     /*---------------------------------------------------------------------*/
00220     void setScale    (const ValueTypeT      s               );
00221 
00222     void setScale    (const ValueTypeT      sx,
00223                       const ValueTypeT      sy, 
00224                       const ValueTypeT      sz              );
00225 
00226     void setScale    (const VectorType3f   &s               );
00227 
00228 
00229     void setTranslate(const ValueTypeT      tx,
00230                       const ValueTypeT      ty,
00231                       const ValueTypeT      tz              );
00232 
00233     void setTranslate(const VectorType3f   &t               );
00234 
00235     void setTranslate(const PointType3f    &t               );
00236 
00237 
00238     void setRotate   (const QuaternionType &q               );
00239 
00240 
00241     void setTransform(const VectorType3f   &t               );
00242 
00243     void setTransform(const QuaternionType &r               );
00244 
00245     void setTransform(const VectorType3f   &t, 
00246                       const QuaternionType &r               );
00247 
00248     void setTransform(const VectorType3f   &t, 
00249                       const QuaternionType &r,
00250                       const VectorType3f   &s               );
00251 
00252     void setTransform(const VectorType3f   &t, 
00253                       const QuaternionType &r,
00254                       const VectorType3f   &s, 
00255                       const QuaternionType &so              );
00256 
00257     void setTransform(const VectorType3f   &translation,
00258                       const QuaternionType &rotation,
00259                       const VectorType3f   &scaleFactor,
00260                       const QuaternionType &scaleOrientation,
00261                       const VectorType3f   &center          );
00262 
00264     /*---------------------------------------------------------------------*/
00268     void getTransform(      VectorType3f         &translation, 
00269                             QuaternionType       &rotation,
00270                             VectorType3f         &scaleFactor, 
00271                             QuaternionType       &scaleOrientation,
00272                       const VectorType3f         &center) const;
00273 
00274     void getTransform(      VectorType3f         &translation, 
00275                             QuaternionType       &rotation,
00276                             VectorType3f         &scaleFactor, 
00277                             QuaternionType       &scaleOrientation) const;
00278 
00279     bool factor      (      TransformationMatrix &r, 
00280                             VectorType3f         &s, 
00281                             TransformationMatrix &u,
00282                             VectorType3f         &t, 
00283                             TransformationMatrix &proj) const;
00284     
00286     /*---------------------------------------------------------------------*/
00290     void multMatrixPnt    (const PointType3f  &src, 
00291                                  PointType3f  &dst) const;
00292     void multMatrixPnt    (      PointType3f  &pnt) const;
00293     void multFullMatrixPnt(const PointType3f  &src, 
00294                                  PointType3f  &dst) const;
00295     void multFullMatrixPnt(      PointType3f  &pnt) const;
00296 
00297     void multMatrixVec    (const VectorType3f &src, 
00298                                  VectorType3f &dst) const;
00299     void multMatrixVec    (      VectorType3f &vec) const;
00300 
00301     void mult             (const PointType3f  &src, 
00302                                  PointType3f  &dst) const;
00303     void mult             (      PointType3f  &vec) const;
00304     void mult             (const VectorType3f &src, 
00305                                  VectorType3f &dst) const;
00306     void mult             (      VectorType3f &vec) const;
00307 
00308 
00309     void multPntMatrix    (const PointType3f  &src, 
00310                                  PointType3f  &dst) const;
00311     void multPntMatrix    (      PointType3f  &pnt) const;
00312     void multPntFullMatrix(const PointType3f  &src, 
00313                                  PointType3f  &dst) const;
00314     void multPntFullMatrix(      PointType3f  &pnt) const;
00315 
00316     void multVecMatrix    (const VectorType3f &src, 
00317                                  VectorType3f &dst) const;
00318     void multVecMatrix    (      VectorType3f &vec) const;
00319 
00320 
00322     /*---------------------------------------------------------------------*/
00326     bool       equals       (const TransformationMatrix &matrix, 
00327                              const ValueType             tol   ) const;
00328 
00329     ValueTypeT det3         (      void                        ) const;
00330     ValueTypeT det          (      void                        ) const;
00331 
00332     bool       inverse      (      TransformationMatrix &result) const;
00333     bool       invert       (      void                        );
00334     bool       invertFrom   (const TransformationMatrix &matrix);
00335 
00336     bool       inverse3     (      TransformationMatrix &result) const;
00337     bool       invert3      (      void                        );
00338     bool       invertFrom3  (const TransformationMatrix &matrix);
00339 
00340     bool       transposed   (      TransformationMatrix &result) const;
00341     bool       transpose    (      void                        );
00342     bool       transposeFrom(const TransformationMatrix &matrix);
00343 
00344     void       mult         (const TransformationMatrix &matrix);
00345     void       multLeft     (const TransformationMatrix &matrix);
00346     
00347     void       add          (const TransformationMatrix &matrix);
00348     void       scale        (      ValueTypeT            s     );
00349     void       addScaled    (const TransformationMatrix &matrix, 
00350                                    ValueTypeT            s     );
00351     void       negate       (      void                        );
00352     
00353     ValueTypeT norm1        (      void                        ) const;
00354     ValueTypeT norm2        (      void                        ) const;
00355     ValueTypeT normInfinity (      void                        ) const;
00356     
00357     bool       sqrt         (      TransformationMatrix &result) const;
00358     bool       sqrtOf       (const TransformationMatrix &matrix);
00359     bool       sqrt         (      void                        );
00360     
00361     bool       log          (      TransformationMatrix &result) const;
00362     bool       logOf        (const TransformationMatrix &matrix);
00363     
00364     bool       exp          (      TransformationMatrix &result) const;
00365     bool       expOf        (const TransformationMatrix &matrix);
00366 
00368     /*---------------------------------------------------------------------*/
00372           VectorType &operator [](UInt32 uiIndex);
00373     const VectorType &operator [](UInt32 uiIndex) const;
00374 
00376     /*---------------------------------------------------------------------*/
00380     TransformationMatrix &operator =(const TransformationMatrix &source);
00381 
00383     /*---------------------------------------------------------------------*/
00387     bool operator == (const TransformationMatrix &other) const;
00388     bool operator != (const TransformationMatrix &other) const;
00389 
00391     /*=========================  PROTECTED  ===============================*/
00392 
00393   protected:
00394 
00395     /*---------------------------------------------------------------------*/
00399     VectorType _matrix[4];
00400 
00402     /*---------------------------------------------------------------------*/
00406     ValueTypeT rowMulCol4(const TransformationMatrix &gRowMat, 
00407                                 UInt32                iRow, 
00408                           const TransformationMatrix &gColMat, 
00409                                 UInt32                iColumn) const;
00410 
00411     ValueTypeT det2      (const ValueTypeT            a1, 
00412                           const ValueTypeT            a2,
00413                           const ValueTypeT            b1, 
00414                           const ValueTypeT            b2     ) const;
00415     ValueTypeT det3      (const ValueTypeT            a1, 
00416                           const ValueTypeT            a2, 
00417                           const ValueTypeT            a3,
00418                           const ValueTypeT            b1, 
00419                           const ValueTypeT            b2, 
00420                           const ValueTypeT            b3,
00421                           const ValueTypeT            c1, 
00422                           const ValueTypeT            c2, 
00423                           const ValueTypeT            c3     ) const;
00424 
00425 #ifdef __sgi
00426 #pragma set woff 1424
00427 #endif
00428 
00429 #if !defined(OSG_MICROSOFT_COMPILER_HACKS) && !defined(__sun)
00430     static const UInt32 JacobiRank = 3;
00431 #endif
00432 
00433     bool jacobi(ValueTypeT    evalues [JacobiRank],
00434                 VectorType3f  evectors[JacobiRank],
00435                 Int32        &rots);
00436 
00437 #ifdef __sgi
00438 #pragma reset woff 1424
00439 #endif
00440     
00442     /*==========================  PRIVATE  ================================*/
00443 
00444   private:
00445 
00446     static TransformationMatrix _identityMatrix;
00447 };
00448 
00454 typedef TransformationMatrix<Real32> Matrix;
00455 
00461 typedef TransformationMatrix<Real32> Matrix4f;
00462 
00468 typedef TransformationMatrix<Real64> Matrix4d;
00469 
00470 template<class ValueTypeT> 
00471 std::ostream &operator <<(      std::ostream                     &os,
00472                           const TransformationMatrix<ValueTypeT> &obj);
00473 
00474 OSG_END_NAMESPACE
00475 
00476 #include <OSGMatrix.inl>
00477 
00478 #endif /* _OSGMATRIX_H_ */
00479 
00480 

Generated on Thu Aug 25 04:07:39 2005 for OpenSG by  doxygen 1.4.3