00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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