00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __DEMOPAJA_VECTOR3_H__
00015 #define __DEMOPAJA_VECTOR3_H__
00016
00017
00018 #include "PajaTypes.h"
00019 #include <math.h>
00020 #include <assert.h>
00021
00022 namespace PajaTypes {
00023
00025
00031 class Vector3C {
00032
00033 public:
00035 Vector3C( float32 f32X = 0, float32 f32Y = 0, float32 f32Z = 0 );
00036
00038 Vector3C( const Vector3C& rVec );
00039
00041 Vector3C( float32 f32A[3] );
00042
00044 virtual ~Vector3C();
00045
00047
00050 float32& operator[]( int32 i );
00051
00053
00056 const float32& operator[]( int32 i ) const;
00057
00059 Vector3C operator-() const;
00060
00062 bool operator==( const Vector3C& rVec ) const;
00063
00065 bool operator!=( const Vector3C& rVec ) const;
00066
00068 Vector3C& operator-=( const Vector3C& rVec );
00069
00071 Vector3C& operator+=( const Vector3C& rVec );
00072
00074 Vector3C& operator*=( float32 f32S );
00075
00077 Vector3C& operator/=( float32 f32S );
00078
00080 Vector3C operator*( float32 f32S );
00081
00083 Vector3C operator/( float32 f32S );
00084
00086 Vector3C operator-( const Vector3C& rVec ) const;
00087
00089 Vector3C operator+( const Vector3C& rVec ) const;
00090
00092
00093 Vector3C operator*( const Vector3C& rVec ) const;
00094
00096 friend Vector3C operator*( float32 f32S, const Vector3C& rVec );
00097
00099 Vector3C normalize() const;
00100
00102 float32 length() const;
00103
00105 float32 dot( const Vector3C& v ) const;
00106
00108 Vector3C cross( const Vector3C& v ) const;
00109
00110 private:
00111 float32 m_vec[3];
00112 };
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 inline
00123 float32&
00124 Vector3C::operator[]( int32 i )
00125 {
00126 assert( i >= 0 && i < 4 );
00127 return m_vec[i];
00128 }
00129
00130 inline
00131 const float32&
00132 Vector3C::operator[]( int32 i ) const
00133 {
00134 assert( i >= 0 && i < 3 );
00135 return m_vec[i];
00136 }
00137
00138 inline
00139 Vector3C
00140 Vector3C::operator-() const
00141 {
00142 return Vector3C( -m_vec[0], -m_vec[1], -m_vec[2] );
00143 }
00144
00145 inline
00146 Vector3C&
00147 Vector3C::operator-=( const Vector3C& a )
00148 {
00149 m_vec[0] -= a.m_vec[0];
00150 m_vec[1] -= a.m_vec[1];
00151 m_vec[2] -= a.m_vec[2];
00152 return *this;
00153 }
00154
00155 inline
00156 Vector3C&
00157 Vector3C::operator+=( const Vector3C& a )
00158 {
00159 m_vec[0] += a.m_vec[0];
00160 m_vec[1] += a.m_vec[1];
00161 m_vec[2] += a.m_vec[2];
00162 return *this;
00163 }
00164
00165 inline
00166 Vector3C&
00167 Vector3C::operator*=( float32 s )
00168 {
00169 m_vec[0] *= s;
00170 m_vec[1] *= s;
00171 m_vec[2] *= s;
00172 return *this;
00173 }
00174
00175 inline
00176 Vector3C&
00177 Vector3C::operator/=( float32 s )
00178 {
00179 s = 1.0f / s;
00180 m_vec[0] *= s;
00181 m_vec[1] *= s;
00182 m_vec[2] *= s;
00183 return *this;
00184 }
00185
00186 inline
00187 Vector3C
00188 Vector3C::operator*( float32 s )
00189 {
00190 return Vector3C( m_vec[0] * s, m_vec[1] * s, m_vec[2] * s );
00191 }
00192
00193
00194 inline
00195 Vector3C
00196 Vector3C::operator/( float32 s )
00197 {
00198 s = 1.0f / s;
00199 return Vector3C( m_vec[0] * s, m_vec[1] * s, m_vec[2] * s );
00200 }
00201
00202 inline
00203 Vector3C
00204 Vector3C::operator-( const Vector3C& a ) const
00205 {
00206 return Vector3C( m_vec[0] - a.m_vec[0], m_vec[1] - a.m_vec[1], m_vec[2] - a.m_vec[2] );
00207 }
00208
00209 inline
00210 Vector3C
00211 Vector3C::operator+( const Vector3C& a ) const
00212 {
00213 return Vector3C( m_vec[0] + a.m_vec[0], m_vec[1] + a.m_vec[1], m_vec[2] + a.m_vec[2] );
00214 }
00215
00216 inline
00217 Vector3C
00218 Vector3C::operator*( const Vector3C& a ) const
00219 {
00220 return Vector3C( m_vec[0] * a.m_vec[0], m_vec[1] * a.m_vec[1], m_vec[2] * a.m_vec[2] );
00221 }
00222
00223 inline
00224 float32
00225 Vector3C::length() const
00226 {
00227 return (float32)sqrt( (m_vec[0] * m_vec[0]) + (m_vec[1] * m_vec[1]) + (m_vec[2] * m_vec[2]) );
00228 }
00229
00230 inline
00231 float32
00232 Vector3C::dot( const Vector3C& v ) const
00233 {
00234 return (m_vec[0] * v.m_vec[0]) + (m_vec[1] * v.m_vec[1]) + (m_vec[2] * v.m_vec[2]);
00235 }
00236
00237 inline
00238 Vector3C
00239 operator*( float32 s, const Vector3C& v )
00240 {
00241 return Vector3C( v.m_vec[0] * s, v.m_vec[1] * s, v.m_vec[2] * s );
00242 }
00243
00244
00245 };
00246
00247
00248 #endif