00001 #ifndef Vector4_h
00002 #define Vector4_h 1
00003
00004 #include <assert.h>
00005 #include <iostream>
00006 #include "math2.h"
00007
00008
00009 class Vector4
00010 {
00011
00012 public:
00013
00014
00015 Vector4 ();
00016
00017
00018 Vector4 (const Vector4& right);
00019
00020
00021 Vector4 (const double x, const double y, const double z);
00022
00023
00024 ~Vector4();
00025
00026
00027
00028
00029 double& operator [] (const unsigned int index);
00030
00031
00032 Vector4 operator + (const Vector4& right) const;
00033
00034
00035 Vector4 operator - (const Vector4& right) const;
00036
00037 Vector4& operator -= (const Vector4& right);
00038
00039
00040 Vector4 operator * (const double right) const;
00041
00042
00043 Vector4 operator / (const double right) const;
00044
00045
00046 const double operator [] (const unsigned int index) const;
00047
00048
00049
00050 double Magnitude () const;
00051
00052
00053
00054 double MagSquared () const;
00055
00056
00057 double Dot (const Vector4& right) const;
00058
00059
00060 Vector4 Cross (const Vector4& right) const;
00061
00062
00063 Vector4 Projection (const Vector4& right) const;
00064
00065
00066 double ProjectionMag (const Vector4& right) const;
00067
00068
00069 void Reflect( const Vector4& normal );
00070
00071
00072 bool operator == (const Vector4& right) const;
00073
00074 bool operator< ( const Vector4& right ) const;
00075
00076
00077 void Normalize ();
00078
00079
00080 bool Compare( const Vector4& right, const double& tol) const;
00081
00082
00083
00084
00085 bool operator !=( const Vector4& right ) const;
00086 Vector4& operator +=( const Vector4& right );
00087 Vector4& operator *=( const double right );
00088 Vector4& operator /=( const double right );
00089 Vector4 operator -() const;
00090
00091
00092 protected:
00093 double elements[ 3 ];
00094
00095 private:
00096
00097 private:
00098
00099 };
00100
00101
00102
00103 inline double& Vector4::operator [] (const unsigned int index)
00104 {
00105 IJG_Assert( index < 3 );
00106 IJG_Assert( index >= 0 );
00107 return elements[ index ];
00108 }
00109
00110 inline const double Vector4::operator [] (const unsigned int index) const
00111 {
00112 IJG_Assert( index < 3 );
00113 IJG_Assert( index >= 0 );
00114 return elements[ index ];
00115 }
00116
00117
00118
00119
00120
00121
00122 inline Vector4& Vector4::operator +=( const Vector4& right )
00123 {
00124 elements[ 0 ] += right.elements[ 0 ];
00125 elements[ 1 ] += right.elements[ 1 ];
00126 elements[ 2 ] += right.elements[ 2 ];
00127 return *this;
00128 }
00129
00130
00131
00132
00133
00134
00135 inline Vector4::Vector4 (const double x, const double y, const double z)
00136 {
00137 elements[ 0 ] = x ;
00138 elements[ 1 ] = y ;
00139 elements[ 2 ] = z ;
00140 }
00141
00142
00143
00144
00145
00146
00147 inline Vector4::~Vector4()
00148 {
00149 }
00150
00151
00152 std::ostream & operator<<( std::ostream &os, const Vector4& v ) ;
00153 std::istream & operator>>( std::istream &is, Vector4& v ) ;
00154
00155
00156
00157
00158
00159
00160 #ifdef _DEBUG
00161 inline void Verify( const Vector4& v )
00162 {
00163 assert( Between( v[ 0 ], -10000.0, 10000.0 ) );
00164 assert( Between( v[ 1 ], -10000.0, 10000.0 ) );
00165 assert( Between( v[ 2 ], -10000.0, 10000.0 ) );
00166 }
00167 #else
00168 inline void Verify( const Vector4& v )
00169 {
00170
00171 }
00172 #endif
00173
00174 #endif