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