H3DTypeOperators.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API 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
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
00022 //
00023 //
00028 //
00030 
00031 #ifndef __H3DTYPEOPERATORS_H__
00032 #define __H3DTYPEOPERATORS_H__
00033 
00034 #include "Vec2f.h"
00035 #include "Vec2d.h"
00036 #include "Vec3f.h"
00037 #include "Vec3d.h"
00038 #include "Vec4f.h"
00039 #include "Vec4d.h"
00040 #include "Rotation.h"
00041 #include "Matrix3f.h"
00042 #include "Matrix3d.h"
00043 #include "Matrix4f.h"
00044 #include "Matrix4d.h"
00045 #include "Quaternion.h"
00046 
00047 namespace H3D {
00049 
00057   namespace ArithmeticTypes {
00058                                 
00062     inline Vec3f operator*( const Matrix3f &m, const Vec3f &v ) {
00063       return Vec3f( m[0][0]*v.x + m[0][1]*v.y + m[0][2]*v.z,
00064                     m[1][0]*v.x + m[1][1]*v.y + m[1][2]*v.z,
00065                     m[2][0]*v.x + m[2][1]*v.y + m[2][2]*v.z );
00066     }
00067 
00068 
00072     inline Vec3d operator*( const Matrix3f &m, const Vec3d &v ) {
00073       return Vec3d( m[0][0]*v.x + m[0][1]*v.y + m[0][2]*v.z,
00074                     m[1][0]*v.x + m[1][1]*v.y + m[1][2]*v.z,
00075                     m[2][0]*v.x + m[2][1]*v.y + m[2][2]*v.z );
00076     }
00077 
00081     inline Vec3d operator*( const Matrix3d &m, const Vec3d &v ) {
00082       return Vec3d( m[0][0]*v.x + m[0][1]*v.y + m[0][2]*v.z,
00083                     m[1][0]*v.x + m[1][1]*v.y + m[1][2]*v.z,
00084                     m[2][0]*v.x + m[2][1]*v.y + m[2][2]*v.z );
00085     }
00086 
00087 
00092     inline Vec3f operator*( const Rotation &r, const Vec3f &v ) {
00093       return (Matrix3f)r * v;
00094     }
00095 
00096 
00100     inline Vec3d operator*( const Rotation &r, const Vec3d &v ) {
00101       return (Matrix3f)r * v;
00102     }
00103 
00108     inline Vec3f operator*( const Quaternion &r, const Vec3f &v ) {
00109       return (Matrix3f)r * v;
00110     }
00111 
00115     inline Vec3d operator*( const Quaternion &r, const Vec3d &v ) {
00116       return (Matrix3f)r * v;
00117     }
00118                 
00122     inline Vec4f operator*( const Matrix4f &m, const Vec4f &v ) {
00123       return Vec4f( 
00124                    m[0][0]*v.x + m[0][1]*v.y + m[0][2]*v.z + m[0][3]*v.w,
00125                    m[1][0]*v.x + m[1][1]*v.y + m[1][2]*v.z + m[1][3]*v.w,
00126                    m[2][0]*v.x + m[2][1]*v.y + m[2][2]*v.z + m[2][3]*v.w,
00127                    m[3][0]*v.x + m[3][1]*v.y + m[3][2]*v.z + m[3][3]*v.w );
00128     }
00129                                 
00133     inline Vec4d operator*( const Matrix4f &m, const Vec4d &v ) {
00134       return Vec4d( 
00135                    m[0][0]*v.x + m[0][1]*v.y + m[0][2]*v.z + m[0][3]*v.w,
00136                    m[1][0]*v.x + m[1][1]*v.y + m[1][2]*v.z + m[1][3]*v.w,
00137                    m[2][0]*v.x + m[2][1]*v.y + m[2][2]*v.z + m[2][3]*v.w,
00138                    m[3][0]*v.x + m[3][1]*v.y + m[3][2]*v.z + m[3][3]*v.w );
00139     }
00140 
00144     inline Vec4d operator*( const Matrix4d &m, const Vec4d &v ) {
00145       return Vec4d( 
00146                    m[0][0]*v.x + m[0][1]*v.y + m[0][2]*v.z + m[0][3]*v.w,
00147                    m[1][0]*v.x + m[1][1]*v.y + m[1][2]*v.z + m[1][3]*v.w,
00148                    m[2][0]*v.x + m[2][1]*v.y + m[2][2]*v.z + m[2][3]*v.w,
00149                    m[3][0]*v.x + m[3][1]*v.y + m[3][2]*v.z + m[3][3]*v.w );
00150     }
00151 
00156     inline Vec3f operator*( const Matrix4f &m, const Vec3f &v ) {
00157       return Vec3f( m[0][0]*v.x + m[0][1]*v.y + m[0][2]*v.z + m[0][3],
00158                     m[1][0]*v.x + m[1][1]*v.y + m[1][2]*v.z + m[1][3],
00159                     m[2][0]*v.x + m[2][1]*v.y + m[2][2]*v.z + m[2][3] ) *
00160         ( 1 / ( m[3][0]*v.x + m[3][1]*v.y + m[3][2]*v.z + m[3][3] ) );
00161     }
00162 
00167     inline Vec3d operator*( const Matrix4f &m, const Vec3d &v ) {
00168       return Vec3d( m[0][0]*v.x + m[0][1]*v.y + m[0][2]*v.z + m[0][3],
00169                     m[1][0]*v.x + m[1][1]*v.y + m[1][2]*v.z + m[1][3],
00170                     m[2][0]*v.x + m[2][1]*v.y + m[2][2]*v.z + m[2][3] ) *
00171         ( 1 / ( m[3][0]*v.x + m[3][1]*v.y + m[3][2]*v.z + m[3][3] ) );
00172     }
00173 
00178     inline Vec3d operator*( const Matrix4d &m, const Vec3d &v ) {
00179       return Vec3d( m[0][0]*v.x + m[0][1]*v.y + m[0][2]*v.z + m[0][3],
00180                     m[1][0]*v.x + m[1][1]*v.y + m[1][2]*v.z + m[1][3],
00181                     m[2][0]*v.x + m[2][1]*v.y + m[2][2]*v.z + m[2][3] ) *
00182         ( 1 / ( m[3][0]*v.x + m[3][1]*v.y + m[3][2]*v.z + m[3][3] ) );
00183     }
00184 
00185   }
00186 }
00187 
00188 
00189 #endif

Generated on Thu Aug 24 12:38:33 2006 for H3D API by  doxygen 1.4.5