Vec4f.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 __VEC4F_H__
00031 #define __VEC4F_H__
00032 
00033 #include "H3DApi.h"
00034 #include "H3DBasicTypes.h"
00035 #include "H3DTemplateOperators.h"
00036 #include "Exception.h"
00037 #include <ostream>
00038 using namespace std;
00039 
00040 namespace H3D {
00041   namespace ArithmeticTypes {
00042     struct Vec4d;
00043 
00047     struct H3DAPI_API Vec4f {
00049       Vec4f(): x(0), y(0), z(0), w(1){}
00050 
00052       Vec4f( H3DFloat _x,
00053              H3DFloat _y,
00054              H3DFloat _z,
00055              H3DFloat _w = 1 ) : x(_x), y(_y), z(_z), w(_w) {}
00056 
00058       explicit Vec4f( const Vec4d &v );
00059 
00065       inline H3DFloat &operator[]( int i ) { 
00066         if( i == 0 ) return x;
00067         if( i == 1 ) return y;
00068         if( i == 2 ) return z;
00069         if( i == 3 ) return w;
00070         
00071         throw Exception::H3DAPIException( "Invalid index", 
00072                                           H3D_FULL_LOCATION );
00073       }
00074 
00080       inline const H3DFloat &operator[]( int i ) const { 
00081         if( i == 0 ) return x;
00082         if( i == 1 ) return y;
00083         if( i == 2 ) return z;
00084         if( i == 3 ) return w;
00085         
00086         throw Exception::H3DAPIException( "Invalid index", 
00087                                           H3D_FULL_LOCATION );
00088       }
00089 
00091       H3DFloat x, y, z, w;
00092     };
00093 
00101 
00102                                 
00104     inline ostream& operator<<( ostream &os, const Vec4f &v ) {
00105       os << v.x << " " << v.y << " " << v.z << " " << v.w;
00106       return os;
00107     } 
00109     inline bool operator==( const Vec4f &v1, const Vec4f &v2 ) {
00110       return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z && v1.w == v2.w;
00111     }
00112 
00114     inline Vec4f operator+( const Vec4f &v1, const Vec4f &v2 ) {
00115       return Vec4f( v1.x + v2.x, v1.y + v2.y, v1.z + v2.z, v1.w + v2.w );
00116     }
00117                 
00119     inline Vec4f operator*( const Vec4f &v, const float &f ) {
00120       return Vec4f( v.x * f, v.y * f, v.z * f, v.w * f );
00121     }
00122 
00124     inline Vec4f operator*( const Vec4f &v, const double &d ) {
00125       return Vec4f( (H3DFloat)(v.x * d),
00126                     (H3DFloat)(v.y * d),
00127                     (H3DFloat)(v.z * d),
00128                     (H3DFloat)(v.w * d) );
00129     }
00130 
00132     inline Vec4f operator*( const Vec4f &v, const int &f ) {
00133       return Vec4f( v.x * f, v.y * f, v.z * f, v.w * f );
00134     }
00135 
00137     inline Vec4f operator*( const Vec4f &v, const long &f ) {
00138       return Vec4f( v.x * f, v.y * f, v.z * f, v.w * f );
00139     }
00140 
00142     inline H3DFloat operator*( const Vec4f &v1, const Vec4f &v2 ) {
00143       return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z + v1.w*v2.w;
00144     }
00145 
00147     inline Vec4f operator*( const float &a, const Vec4f &b ) { return b * a; }
00148 
00150     inline Vec4f operator*( const double &a, const Vec4f &b ) { return b * a; }
00151 
00153     inline Vec4f operator*( const int &a, const Vec4f &b ) { return b * a; }
00154 
00156     inline Vec4f operator*( const long &a, const Vec4f &b ) { return b * a; }
00157 
00159     inline Vec4f operator-( const Vec4f &b ) { return b * (float)-1; }
00160 
00162     inline Vec4f operator-( const Vec4f &a, const Vec4f &b ) { 
00163       return a + (-b); 
00164     }
00165                                 
00166     // \}
00167     
00168   }
00169 }
00170 
00171 #endif

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