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 __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