00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef freecloth_geom_geVector_inline_h
00020 #define freecloth_geom_geVector_inline_h
00021
00022 #include <freecloth/base/baMath.h>
00023 #include <freecloth/base/algorithm>
00024
00025 FREECLOTH_NAMESPACE_START
00026
00027
00028
00029
00030
00031
00032 inline const GeVector& GeVector::axis( UInt32 idx )
00033 {
00034 DGFX_ASSERT( idx < 3 );
00035 static const GeVector array[ 3 ] = { X, Y, Z };
00036 return array[ idx ];
00037 }
00038
00039
00040
00041 inline GeVector::GeVector()
00042 {}
00043
00044
00045
00046 inline GeVector::GeVector( Float x, Float y, Float z)
00047 : _x( x ), _y( y ), _z( z )
00048 {}
00049
00050
00051
00052 inline GeVector& GeVector::operator+=( const GeVector& rhs )
00053 {
00054 _x += rhs._x;
00055 _y += rhs._y;
00056 _z += rhs._z;
00057 return *this;
00058 }
00059
00060
00061
00062 inline GeVector& GeVector::operator-=( const GeVector& rhs )
00063 {
00064 _x -= rhs._x;
00065 _y -= rhs._y;
00066 _z -= rhs._z;
00067 return *this;
00068 }
00069
00070
00071
00072 inline GeVector& GeVector::operator+=( Float k )
00073 {
00074 _x += k;
00075 _y += k;
00076 _z += k;
00077 return *this;
00078 }
00079
00080
00081
00082 inline GeVector& GeVector::operator-=( Float k )
00083 {
00084 _x -= k;
00085 _y -= k;
00086 _z -= k;
00087 return *this;
00088 }
00089
00090
00091
00092 inline GeVector& GeVector::operator*=( Float k )
00093 {
00094 _x *= k;
00095 _y *= k;
00096 _z *= k;
00097 return *this;
00098 }
00099
00100
00101
00102 inline GeVector& GeVector::operator/=( Float k )
00103 {
00104 _x /= k;
00105 _y /= k;
00106 _z /= k;
00107 return *this;
00108 }
00109
00110
00111
00112 inline GeVector GeVector::operator-() const
00113 {
00114 return GeVector( -_x, -_y, -_z );
00115 }
00116
00117
00118
00119 inline GeVector GeVector::operator+( const GeVector& rhs ) const
00120 {
00121 GeVector temp( *this );
00122 temp += rhs;
00123 return temp;
00124 }
00125
00126
00127
00128 inline GeVector GeVector::operator-( const GeVector& rhs ) const
00129 {
00130 GeVector temp( *this );
00131 temp -= rhs;
00132 return temp;
00133 }
00134
00135
00136
00137 inline GeVector GeVector::operator+( Float k ) const
00138 {
00139 GeVector temp( *this );
00140 temp += k;
00141 return temp;
00142 }
00143
00144
00145
00146 inline GeVector GeVector::operator-( Float k ) const
00147 {
00148 GeVector temp( *this );
00149 temp -= k;
00150 return temp;
00151 }
00152
00153
00154
00155 inline GeVector GeVector::operator*( Float k ) const
00156 {
00157 GeVector temp( *this );
00158 temp *= k;
00159 return temp;
00160 }
00161
00162
00163
00164 inline GeVector GeVector::operator/( Float k ) const
00165 {
00166 GeVector temp( *this );
00167 temp /= k;
00168 return temp;
00169 }
00170
00171
00172
00173 inline bool GeVector::operator==( const GeVector& rhs ) const
00174 {
00175 return
00176 BaMath::isEqual( _x, rhs._x ) &&
00177 BaMath::isEqual( _y, rhs._y ) &&
00178 BaMath::isEqual( _z, rhs._z );
00179 }
00180
00181
00182
00183 inline bool GeVector::operator!=( const GeVector& rhs ) const
00184 {
00185 return !operator==( rhs );
00186 }
00187
00188
00189
00190 inline Float GeVector::dot( const GeVector& rhs ) const
00191 {
00192 return _x * rhs._x + _y * rhs._y + _z * rhs._z;
00193 }
00194
00195
00196
00197 inline GeVector GeVector::cross( const GeVector& rhs ) const
00198 {
00199 return GeVector(
00200 _y * rhs._z - _z * rhs._y,
00201 _z * rhs._x - _x * rhs._z,
00202 _x * rhs._y - _y * rhs._x
00203 );
00204 }
00205
00206
00207
00208 inline Float GeVector::squaredLength() const
00209 {
00210 return _x*_x + _y*_y + _z*_z;
00211 }
00212
00213
00214
00215 inline Float GeVector::length() const
00216 {
00217 return BaMath::sqrt( squaredLength() );
00218 }
00219
00220
00221
00222 inline Float GeVector::infinityNorm() const
00223 {
00224 return std::max(
00225 std::max( BaMath::abs( _x ), BaMath::abs( _y ) ),
00226 BaMath::abs( _z )
00227 );
00228 }
00229
00230
00231
00232 inline bool GeVector::isUnit() const
00233 {
00234 return BaMath::isEqual( squaredLength(), 1 );
00235 }
00236
00237
00238
00239 inline GeVector GeVector::getUnit() const
00240 {
00241 return (*this) / length();
00242 }
00243
00244
00245
00246 inline Float GeVector::operator[]( UInt32 i ) const
00247 {
00248 DGFX_ASSERT( i < 4 );
00249 switch( i ) {
00250 case 0: return _x;
00251 case 1: return _y;
00252 case 2: return _z;
00253 case 3: return 0;
00254 }
00255 return 0;
00256 }
00257
00258
00259
00260 inline Float& GeVector::operator[]( UInt32 i )
00261 {
00262 DGFX_ASSERT( i < 3 );
00263 switch( i ) {
00264 case 0: return _x;
00265 case 1: return _y;
00266 case 2: return _z;
00267 }
00268 static Float dummy;
00269 return dummy;
00270 }
00271
00272
00273
00274
00275
00276
00277
00278
00279 inline GeVector operator*( Float k, const GeVector& rhs )
00280 {
00281 return rhs * k;
00282 }
00283
00284 FREECLOTH_NAMESPACE_END
00285
00286 #endif