Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

VrmlMatrix.h

00001 //
00002 // OpenVRML
00003 //
00004 // Copyright (C) 2001  S. K. Bose
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License, or (at your option) any later version.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 
00021 # ifndef OPENVRML_VRMLMATRIX_H
00022 #   define OPENVRML_VRMLMATRIX_H
00023 
00024 #   include <assert.h>
00025 #   include <stddef.h>
00026 #   include <iostream>
00027 #   include <iosfwd>
00028 #   include "common.h"
00029 
00030 namespace OpenVRML {
00031 
00032     class VrmlMatrix;
00033 
00034     std::ostream & OPENVRML_SCOPE operator<<(std::ostream & out,
00035                                              const VrmlMatrix & mat);
00036     bool OPENVRML_SCOPE operator==(const VrmlMatrix & lhs,
00037                                    const VrmlMatrix & rhs) throw ();
00038     bool OPENVRML_SCOPE operator!=(const VrmlMatrix & lhs,
00039                                    const VrmlMatrix & rhs) throw ();
00040 
00041     class SFVec3f;
00042     class SFRotation;
00043 
00044     class OPENVRML_SCOPE VrmlMatrix {
00045         float matrix[4][4];
00046 
00047     public:
00048         VrmlMatrix() throw ();
00049         VrmlMatrix(float f11, float f12, float f13, float f14,
00050                    float f21, float f22, float f23, float f24,
00051                    float f31, float f32, float f33, float f34,
00052                    float f41, float f42, float f43, float f44) throw ();
00053         explicit VrmlMatrix(const float m[4][4]) throw ();
00054 
00055         // use compiler-defined operator= and copy constructor.
00056 
00057         float (&operator[](size_t index) throw ())[4];
00058         const float (&operator[](size_t index) const throw ())[4];
00059         const float (&get() const throw ())[4][4];
00060 
00061         void setRotate(const float axisAngle[4]) throw ();
00062         void setRotate(const SFRotation & axisAngle) throw ();
00063         void setScale(float s) throw ();
00064         void setScale(const float s[3]) throw ();
00065         void setScale(const SFVec3f & s) throw ();
00066         void setTranslate(const float t[3]) throw ();
00067         void setTranslate(const SFVec3f & t) throw ();
00068 
00069         void setTransform(const SFVec3f & translation,
00070                           const SFRotation & rotation,
00071                           const SFVec3f & scale,
00072                           const SFRotation & scaleOrientation,
00073                           const SFVec3f & center) throw ();
00074         void getTransform(SFVec3f & translation,
00075                           SFRotation & rotation,
00076                           SFVec3f & scale) const throw ();
00077         void getTransform(SFVec3f & translation,
00078                           SFRotation & rotation,
00079                           SFVec3f & scale,
00080                           SFVec3f & shear) const throw ();
00081 
00082         const VrmlMatrix affine_inverse() const throw ();
00083         const VrmlMatrix transpose() const throw ();
00084 
00085         const VrmlMatrix multLeft(const VrmlMatrix & mat) const throw ();
00086         const VrmlMatrix multRight(const VrmlMatrix & mat) const throw ();
00087 
00088         void multMatrixVec(const SFVec3f &src, SFVec3f &dst) const throw ();
00089         void multMatrixVec(const float src[3], float dst[3]) const throw ();
00090         void multVecMatrix(const SFVec3f &src, SFVec3f &dst) const throw ();
00091         void multVecMatrix(const float src[3], float dst[3]) const throw ();
00092 
00093         float det3(int r1, int r2, int r3, int c1, int c2, int c3) const
00094             throw ();
00095         float det4() const throw ();
00096     };
00097 
00098     inline bool operator!=(const VrmlMatrix & lhs, const VrmlMatrix & rhs)
00099         throw ()
00100     {
00101         return !(lhs == rhs);
00102     }
00103 
00104     inline float (&VrmlMatrix::operator[](size_t index) throw ())[4]
00105     {
00106         assert(index < 4);
00107         return this->matrix[index];
00108     }
00109 
00110     inline const float (&VrmlMatrix::operator[](size_t index) const throw ())[4]
00111     {
00112         assert(index < 4);
00113         return this->matrix[index];
00114     }
00115 
00116     inline const float (&VrmlMatrix::get() const throw ())[4][4]
00117     {
00118         return this->matrix;
00119     }
00120 }
00121 
00122 #endif // OPENVRML_VRMLMATRIX_H