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