GLMatrixT.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 8521 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2010-02-10 15:57:35 +0100 (Mi, 10. Feb 2010) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 //=============================================================================
00046 //
00047 //  CLASS GLMatrixT
00048 //
00049 //=============================================================================
00050 
00051 
00052 #ifndef ACG_GLMATRIX_HH
00053 #define ACG_GLMATRIX_HH
00054 
00055 
00056 //== INCLUDES =================================================================
00057 
00058 
00059 #include "Matrix4x4T.hh"
00060 #include "../Config/ACGDefines.hh"
00061 #include <math.h>
00062 
00063 
00064 namespace ACG {
00065 
00066               
00067 //== CLASS DEFINITION =========================================================
00068 
00069 
00072 enum MultiplyFrom { MULT_FROM_RIGHT, MULT_FROM_LEFT };
00073 
00074 
00075 
00077 template <class Scalar>
00078 class GLMatrixT : public Matrix4x4T<Scalar>
00079 {
00080 public:
00081    
00082   typedef VectorT<Scalar, 3> Vec3;
00083 
00084 
00086   GLMatrixT() {}
00087  
00089   template <class OtherScalar>
00090   inline GLMatrixT(const GLMatrixT<OtherScalar> _rhs) 
00091     : Matrix4x4T<Scalar>(_rhs)
00092   {}
00093 
00096   inline GLMatrixT(const Scalar _array[16]) : Matrix4x4T<Scalar>(_array) {}
00097 
00099   ~GLMatrixT() {}
00100 
00101 
00103   template<typename otherScalar>
00104   inline GLMatrixT<Scalar>& operator=(const GLMatrixT<otherScalar>& _rhs)
00105   { Matrix4x4T<Scalar>::operator=(_rhs); return *this; }
00106 
00108   template<typename otherScalar>
00109   inline GLMatrixT<Scalar>& operator=(const Matrix4x4T<otherScalar>& _rhs)
00110   { Matrix4x4T<Scalar>::operator=(_rhs); return *this; }
00111 
00112 
00113       
00115   inline void scale( Scalar _x, Scalar _y, Scalar _z, 
00116                      MultiplyFrom _mult_from = MULT_FROM_RIGHT );
00118   inline void scale( const Vec3& _v,
00119                      MultiplyFrom _mult_from = MULT_FROM_RIGHT ) {
00120     scale(_v[0], _v[1], _v[2], _mult_from);
00121   }
00122 
00123 
00125   inline void translate( Scalar _x, Scalar _y, Scalar _z,
00126                          MultiplyFrom _mult_from = MULT_FROM_RIGHT );
00128   inline void translate( const Vec3& _v,
00129                          MultiplyFrom _mult_from = MULT_FROM_RIGHT ) {
00130     translate(_v[0], _v[1], _v[2], _mult_from);
00131   }
00132 
00133 
00136   void rotate( Scalar angle, Scalar x, Scalar y, Scalar z,
00137                MultiplyFrom _mult_from = MULT_FROM_RIGHT );
00140   void rotate( Scalar _angle, const Vec3& _axis,
00141                MultiplyFrom _mult_from = MULT_FROM_RIGHT ) {
00142     rotate(_angle, _axis[0], _axis[1], _axis[2], _mult_from);
00143   }
00144 
00145 
00146 
00148   inline void rotateX( Scalar _angle,
00149                        MultiplyFrom _mult_from = MULT_FROM_RIGHT ) {
00150     rotateXYZ( X, _angle, _mult_from );
00151   }
00152 
00154   inline void rotateY( Scalar _angle,
00155                        MultiplyFrom _mult_from = MULT_FROM_RIGHT ) {
00156     rotateXYZ( Y, _angle, _mult_from );
00157   }
00158 
00160   inline void rotateZ( Scalar _angle,
00161                        MultiplyFrom _mult_from = MULT_FROM_RIGHT ) {
00162     rotateXYZ( Z, _angle, _mult_from );
00163   }
00164 
00165 
00166 
00167 
00171   void lookAt(const Vec3& eye,
00172               const Vec3& center,
00173               const Vec3& up);
00174 
00176   void inverse_lookAt(const Vec3& eye,
00177                       const Vec3& center,
00178                       const Vec3& up);
00179 
00180 
00182   void perspective(Scalar fovY, Scalar aspect, 
00183                    Scalar near_plane, Scalar far_plane);
00184 
00186   void inverse_perspective(Scalar fovY, Scalar aspect,
00187                            Scalar near_plane,Scalar far_plane);
00188 
00190   void frustum(Scalar left, Scalar right,
00191                Scalar bottom, Scalar top,
00192                Scalar near_plane, Scalar far_plane);
00193 
00195   void inverse_frustum(Scalar left,Scalar right,
00196                        Scalar bottom, Scalar top,
00197                        Scalar near_plane, Scalar far_plane);
00198 
00200   void ortho(Scalar left, Scalar right,
00201              Scalar bottom, Scalar top,
00202              Scalar near_plane, Scalar far_plane);
00203 
00205   void inverse_ortho(Scalar left, Scalar right,
00206                      Scalar bottom, Scalar top,
00207                      Scalar near_plane, Scalar far_plane);
00208 
00209 
00210 
00211 
00212   //----------------------------------------------------- overloaded operators 
00213 
00214   GLMatrixT& operator+= ( const Matrix4x4T<Scalar>& _rhs) {
00215     Matrix4x4T<Scalar>::operator+=(_rhs); return *this;
00216   }
00217   GLMatrixT& operator-= ( const Matrix4x4T<Scalar>& _rhs) {
00218     Matrix4x4T<Scalar>::operator-=(_rhs); return *this;
00219   }
00220   GLMatrixT& operator*= ( const Matrix4x4T<Scalar>& _rhs) {
00221     Matrix4x4T<Scalar>::operator*=(_rhs); return *this;
00222   }
00223   GLMatrixT& leftMult(const Matrix4x4T<Scalar>& _rhs) {
00224     Matrix4x4T<Scalar>::leftMult(_rhs); return *this;
00225   }
00226 
00227   GLMatrixT operator+ (const Matrix4x4T<Scalar>& _rhs) const {
00228     return GLMatrixT<Scalar>(*this) += _rhs;
00229   }    
00230   GLMatrixT operator- (const Matrix4x4T<Scalar>& _rhs) const {
00231     return GLMatrixT<Scalar>(*this) -= _rhs;
00232   }
00233   GLMatrixT operator*(const Matrix4x4T<Scalar>& _rhs) const {
00234     return GLMatrixT<Scalar>(*this) *= _rhs;
00235   }
00236 
00237   template <typename T>
00238   inline VectorT<T,4> operator*(const VectorT<T,4>& _v) const {
00239     return Matrix4x4T<Scalar>::operator*(_v);
00240   }
00241 
00242 
00243 
00244 private:
00245 
00246   enum Axis { X, Y, Z };
00247   void rotateXYZ( Axis _axis, Scalar _angle, MultiplyFrom _mult_from );
00248 };
00249 
00250 
00251 
00252 
00253 //=============================================================================
00254 
00255 
00257 typedef GLMatrixT<float>  GLMatrixf;
00259 typedef GLMatrixT<double> GLMatrixd;
00260 
00261 
00262 //=============================================================================
00263 } // namespace ACG
00264 //=============================================================================
00265 #if defined(INCLUDE_TEMPLATES) && !defined(ACG_GLMATRIX_C)
00266 #define ACG_GLMATRIX_TEMPLATES
00267 #include "GLMatrixT.cc"
00268 #endif
00269 //=============================================================================
00270 #endif // ACG_GLMATRIX_HH defined
00271 //=============================================================================
00272 

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .