Vec4d.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 //
00027 //
00029 
00030 #ifndef __VEC4D_H__
00031 #define __VEC4D_H__
00032 
00033 #include "H3DApi.h"
00034 #include "H3DBasicTypes.h"
00035 #include "H3DTemplateOperators.h"
00036 #include "Vec4f.h"
00037 #include "Exception.h"
00038 
00039 namespace H3D {
00040   namespace ArithmeticTypes {
00044     struct H3DAPI_API Vec4d {
00046       Vec4d(): x(0), y(0), z(0), w(1){}
00047       
00049       Vec4d( H3DDouble _x,
00050              H3DDouble _y,
00051              H3DDouble _z,
00052              H3DDouble _w = 1 ) : x(_x), y(_y), z(_z), w(_w) {}
00053       
00055       Vec4d( const Vec4f &v ): x( v.x ), y( v.y ), z( v.z ), w( v.w ) {}
00056 
00062       inline H3DDouble &operator[]( int i ) { 
00063         if( i == 0 ) return x;
00064         if( i == 1 ) return y;
00065         if( i == 2 ) return z;
00066         if( i == 3 ) return w;
00067         
00068         throw Exception::H3DAPIException( "Invalid index", 
00069                                           H3D_FULL_LOCATION );
00070       }
00071 
00077       inline const H3DDouble &operator[]( int i ) const { 
00078         if( i == 0 ) return x;
00079         if( i == 1 ) return y;
00080         if( i == 2 ) return z;
00081         if( i == 3 ) return w;
00082         
00083         throw Exception::H3DAPIException( "Invalid index", 
00084                                           H3D_FULL_LOCATION );
00085       }
00086 
00088       H3DDouble x, y, z, w;
00089     };
00090     
00098 
00099                                 
00101     inline ostream& operator<<( ostream &os, const Vec4d &v ) {
00102       os << v.x << " " << v.y << " " << v.z << " " << v.w;
00103       return os;
00104     } 
00106     inline bool operator==( const Vec4d &v1, const Vec4d &v2 ) {
00107       return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z && v1.w == v2.w;
00108     }
00109 
00111     inline Vec4d operator+( const Vec4d &v1, const Vec4d &v2 ) {
00112       return Vec4d( v1.x + v2.x, v1.y + v2.y, v1.z + v2.z, v1.w + v2.w );
00113     }
00114                 
00116     inline Vec4d operator*( const Vec4d &v, const double &d ) {
00117       return Vec4d( v.x * d, v.y * d, v.z * d, v.w * d );
00118     }
00119 
00121     inline H3DDouble operator*( const Vec4d &v1, const Vec4d &v2 ) {
00122       return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z + v1.w*v2.w;
00123     }
00124 
00126     inline Vec4d operator*( const double &a, const Vec4d &b ) { return b * a; }
00127 
00129     inline Vec4d operator-( const Vec4d &b ) { return b * (double)-1; }
00130 
00132     inline Vec4d operator-( const Vec4d &a, const Vec4d &b ) { return a + (-b); }
00133                                 
00135   }
00136 }
00137 
00138 #endif

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