[1963] | 1 | /* |
---|
| 2 | Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans http://continuousphysics.com/Bullet/ |
---|
| 3 | |
---|
| 4 | This software is provided 'as-is', without any express or implied warranty. |
---|
| 5 | In no event will the authors be held liable for any damages arising from the use of this software. |
---|
| 6 | Permission is granted to anyone to use this software for any purpose, |
---|
| 7 | including commercial applications, and to alter it and redistribute it freely, |
---|
| 8 | subject to the following restrictions: |
---|
| 9 | |
---|
| 10 | 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. |
---|
| 11 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. |
---|
| 12 | 3. This notice may not be removed or altered from any source distribution. |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | #ifndef SIMD__VECTOR3_H |
---|
| 18 | #define SIMD__VECTOR3_H |
---|
| 19 | |
---|
| 20 | #include "btQuadWord.h" |
---|
| 21 | |
---|
[2430] | 22 | /**@brief btVector3 can be used to represent 3D points and vectors. |
---|
| 23 | * It has an un-used w component to suit 16-byte alignment when btVector3 is stored in containers. This extra component can be used by derived classes (Quaternion?) or by user |
---|
| 24 | * Ideally, this class should be replaced by a platform optimized SIMD version that keeps the data in registers |
---|
| 25 | */ |
---|
[1963] | 26 | class btVector3 : public btQuadWord { |
---|
| 27 | |
---|
| 28 | public: |
---|
[2430] | 29 | /**@brief No initialization constructor */ |
---|
[1963] | 30 | SIMD_FORCE_INLINE btVector3() {} |
---|
| 31 | |
---|
[2430] | 32 | /**@brief Constructor from btQuadWordStorage (btVector3 inherits from this so is also valid) |
---|
| 33 | * Note: Vector3 derives from btQuadWordStorage*/ |
---|
[1963] | 34 | SIMD_FORCE_INLINE btVector3(const btQuadWordStorage& q) |
---|
| 35 | : btQuadWord(q) |
---|
| 36 | { |
---|
| 37 | } |
---|
| 38 | |
---|
[2430] | 39 | /**@brief Constructor from scalars |
---|
| 40 | * @param x X value |
---|
| 41 | * @param y Y value |
---|
| 42 | * @param z Z value |
---|
| 43 | */ |
---|
[1963] | 44 | SIMD_FORCE_INLINE btVector3(const btScalar& x, const btScalar& y, const btScalar& z) |
---|
| 45 | :btQuadWord(x,y,z,btScalar(0.)) |
---|
| 46 | { |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | // SIMD_FORCE_INLINE btVector3(const btScalar& x, const btScalar& y, const btScalar& z,const btScalar& w) |
---|
| 50 | // : btQuadWord(x,y,z,w) |
---|
| 51 | // { |
---|
| 52 | // } |
---|
| 53 | |
---|
| 54 | |
---|
[2430] | 55 | /**@brief Add a vector to this one |
---|
| 56 | * @param The vector to add to this one */ |
---|
[1963] | 57 | SIMD_FORCE_INLINE btVector3& operator+=(const btVector3& v) |
---|
| 58 | { |
---|
| 59 | |
---|
[2430] | 60 | m_floats[0] += v.x(); m_floats[1] += v.y(); m_floats[2] += v.z(); |
---|
[1963] | 61 | return *this; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | |
---|
[2430] | 65 | /**@brief Subtract a vector from this one |
---|
| 66 | * @param The vector to subtract */ |
---|
[1963] | 67 | SIMD_FORCE_INLINE btVector3& operator-=(const btVector3& v) |
---|
| 68 | { |
---|
[2430] | 69 | m_floats[0] -= v.x(); m_floats[1] -= v.y(); m_floats[2] -= v.z(); |
---|
[1963] | 70 | return *this; |
---|
| 71 | } |
---|
[2430] | 72 | /**@brief Scale the vector |
---|
| 73 | * @param s Scale factor */ |
---|
[1963] | 74 | SIMD_FORCE_INLINE btVector3& operator*=(const btScalar& s) |
---|
| 75 | { |
---|
[2430] | 76 | m_floats[0] *= s; m_floats[1] *= s; m_floats[2] *= s; |
---|
[1963] | 77 | return *this; |
---|
| 78 | } |
---|
| 79 | |
---|
[2430] | 80 | /**@brief Inversely scale the vector |
---|
| 81 | * @param s Scale factor to divide by */ |
---|
[1963] | 82 | SIMD_FORCE_INLINE btVector3& operator/=(const btScalar& s) |
---|
| 83 | { |
---|
| 84 | btFullAssert(s != btScalar(0.0)); |
---|
| 85 | return *this *= btScalar(1.0) / s; |
---|
| 86 | } |
---|
| 87 | |
---|
[2430] | 88 | /**@brief Return the dot product |
---|
| 89 | * @param v The other vector in the dot product */ |
---|
[1963] | 90 | SIMD_FORCE_INLINE btScalar dot(const btVector3& v) const |
---|
| 91 | { |
---|
[2430] | 92 | return m_floats[0] * v.x() + m_floats[1] * v.y() + m_floats[2] * v.z(); |
---|
[1963] | 93 | } |
---|
| 94 | |
---|
[2430] | 95 | /**@brief Return the length of the vector squared */ |
---|
[1963] | 96 | SIMD_FORCE_INLINE btScalar length2() const |
---|
| 97 | { |
---|
| 98 | return dot(*this); |
---|
| 99 | } |
---|
| 100 | |
---|
[2430] | 101 | /**@brief Return the length of the vector */ |
---|
[1963] | 102 | SIMD_FORCE_INLINE btScalar length() const |
---|
| 103 | { |
---|
| 104 | return btSqrt(length2()); |
---|
| 105 | } |
---|
| 106 | |
---|
[2430] | 107 | /**@brief Return the distance squared between the ends of this and another vector |
---|
| 108 | * This is symantically treating the vector like a point */ |
---|
[1963] | 109 | SIMD_FORCE_INLINE btScalar distance2(const btVector3& v) const; |
---|
| 110 | |
---|
[2430] | 111 | /**@brief Return the distance between the ends of this and another vector |
---|
| 112 | * This is symantically treating the vector like a point */ |
---|
[1963] | 113 | SIMD_FORCE_INLINE btScalar distance(const btVector3& v) const; |
---|
| 114 | |
---|
[2430] | 115 | /**@brief Normalize this vector |
---|
| 116 | * x^2 + y^2 + z^2 = 1 */ |
---|
[1963] | 117 | SIMD_FORCE_INLINE btVector3& normalize() |
---|
| 118 | { |
---|
| 119 | return *this /= length(); |
---|
| 120 | } |
---|
| 121 | |
---|
[2430] | 122 | /**@brief Return a normalized version of this vector */ |
---|
[1963] | 123 | SIMD_FORCE_INLINE btVector3 normalized() const; |
---|
| 124 | |
---|
[2430] | 125 | /**@brief Rotate this vector |
---|
| 126 | * @param wAxis The axis to rotate about |
---|
| 127 | * @param angle The angle to rotate by */ |
---|
[1963] | 128 | SIMD_FORCE_INLINE btVector3 rotate( const btVector3& wAxis, const btScalar angle ); |
---|
| 129 | |
---|
[2430] | 130 | /**@brief Return the angle between this and another vector |
---|
| 131 | * @param v The other vector */ |
---|
[1963] | 132 | SIMD_FORCE_INLINE btScalar angle(const btVector3& v) const |
---|
| 133 | { |
---|
| 134 | btScalar s = btSqrt(length2() * v.length2()); |
---|
| 135 | btFullAssert(s != btScalar(0.0)); |
---|
| 136 | return btAcos(dot(v) / s); |
---|
| 137 | } |
---|
[2430] | 138 | /**@brief Return a vector will the absolute values of each element */ |
---|
[1963] | 139 | SIMD_FORCE_INLINE btVector3 absolute() const |
---|
| 140 | { |
---|
| 141 | return btVector3( |
---|
[2430] | 142 | btFabs(m_floats[0]), |
---|
| 143 | btFabs(m_floats[1]), |
---|
| 144 | btFabs(m_floats[2])); |
---|
[1963] | 145 | } |
---|
[2430] | 146 | /**@brief Return the cross product between this and another vector |
---|
| 147 | * @param v The other vector */ |
---|
[1963] | 148 | SIMD_FORCE_INLINE btVector3 cross(const btVector3& v) const |
---|
| 149 | { |
---|
| 150 | return btVector3( |
---|
[2430] | 151 | m_floats[1] * v.z() - m_floats[2] * v.y(), |
---|
| 152 | m_floats[2] * v.x() - m_floats[0] * v.z(), |
---|
| 153 | m_floats[0] * v.y() - m_floats[1] * v.x()); |
---|
[1963] | 154 | } |
---|
| 155 | |
---|
| 156 | SIMD_FORCE_INLINE btScalar triple(const btVector3& v1, const btVector3& v2) const |
---|
| 157 | { |
---|
[2430] | 158 | return m_floats[0] * (v1.y() * v2.z() - v1.z() * v2.y()) + |
---|
| 159 | m_floats[1] * (v1.z() * v2.x() - v1.x() * v2.z()) + |
---|
| 160 | m_floats[2] * (v1.x() * v2.y() - v1.y() * v2.x()); |
---|
[1963] | 161 | } |
---|
| 162 | |
---|
[2430] | 163 | /**@brief Return the axis with the smallest value |
---|
| 164 | * Note return values are 0,1,2 for x, y, or z */ |
---|
[1963] | 165 | SIMD_FORCE_INLINE int minAxis() const |
---|
| 166 | { |
---|
[2430] | 167 | return m_floats[0] < m_floats[1] ? (m_floats[0] < m_floats[2] ? 0 : 2) : (m_floats[1] < m_floats[2] ? 1 : 2); |
---|
[1963] | 168 | } |
---|
| 169 | |
---|
[2430] | 170 | /**@brief Return the axis with the largest value |
---|
| 171 | * Note return values are 0,1,2 for x, y, or z */ |
---|
[1963] | 172 | SIMD_FORCE_INLINE int maxAxis() const |
---|
| 173 | { |
---|
[2430] | 174 | return m_floats[0] < m_floats[1] ? (m_floats[1] < m_floats[2] ? 2 : 1) : (m_floats[0] < m_floats[2] ? 2 : 0); |
---|
[1963] | 175 | } |
---|
| 176 | |
---|
| 177 | SIMD_FORCE_INLINE int furthestAxis() const |
---|
| 178 | { |
---|
| 179 | return absolute().minAxis(); |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | SIMD_FORCE_INLINE int closestAxis() const |
---|
| 183 | { |
---|
| 184 | return absolute().maxAxis(); |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | SIMD_FORCE_INLINE void setInterpolate3(const btVector3& v0, const btVector3& v1, btScalar rt) |
---|
| 188 | { |
---|
| 189 | btScalar s = btScalar(1.0) - rt; |
---|
[2430] | 190 | m_floats[0] = s * v0.x() + rt * v1.x(); |
---|
| 191 | m_floats[1] = s * v0.y() + rt * v1.y(); |
---|
| 192 | m_floats[2] = s * v0.z() + rt * v1.z(); |
---|
[1963] | 193 | //don't do the unused w component |
---|
| 194 | // m_co[3] = s * v0[3] + rt * v1[3]; |
---|
| 195 | } |
---|
| 196 | |
---|
[2430] | 197 | /**@brief Return the linear interpolation between this and another vector |
---|
| 198 | * @param v The other vector |
---|
| 199 | * @param t The ration of this to v (t = 0 => return this, t=1 => return other) */ |
---|
[1963] | 200 | SIMD_FORCE_INLINE btVector3 lerp(const btVector3& v, const btScalar& t) const |
---|
| 201 | { |
---|
[2430] | 202 | return btVector3(m_floats[0] + (v.x() - m_floats[0]) * t, |
---|
| 203 | m_floats[1] + (v.y() - m_floats[1]) * t, |
---|
| 204 | m_floats[2] + (v.z() - m_floats[2]) * t); |
---|
[1963] | 205 | } |
---|
| 206 | |
---|
[2430] | 207 | /**@brief Elementwise multiply this vector by the other |
---|
| 208 | * @param v The other vector */ |
---|
[1963] | 209 | SIMD_FORCE_INLINE btVector3& operator*=(const btVector3& v) |
---|
| 210 | { |
---|
[2430] | 211 | m_floats[0] *= v.x(); m_floats[1] *= v.y(); m_floats[2] *= v.z(); |
---|
[1963] | 212 | return *this; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | |
---|
| 216 | |
---|
| 217 | }; |
---|
| 218 | |
---|
[2430] | 219 | /**@brief Return the sum of two vectors (Point symantics)*/ |
---|
[1963] | 220 | SIMD_FORCE_INLINE btVector3 |
---|
| 221 | operator+(const btVector3& v1, const btVector3& v2) |
---|
| 222 | { |
---|
| 223 | return btVector3(v1.x() + v2.x(), v1.y() + v2.y(), v1.z() + v2.z()); |
---|
| 224 | } |
---|
| 225 | |
---|
[2430] | 226 | /**@brief Return the elementwise product of two vectors */ |
---|
[1963] | 227 | SIMD_FORCE_INLINE btVector3 |
---|
| 228 | operator*(const btVector3& v1, const btVector3& v2) |
---|
| 229 | { |
---|
| 230 | return btVector3(v1.x() * v2.x(), v1.y() * v2.y(), v1.z() * v2.z()); |
---|
| 231 | } |
---|
| 232 | |
---|
[2430] | 233 | /**@brief Return the difference between two vectors */ |
---|
[1963] | 234 | SIMD_FORCE_INLINE btVector3 |
---|
| 235 | operator-(const btVector3& v1, const btVector3& v2) |
---|
| 236 | { |
---|
| 237 | return btVector3(v1.x() - v2.x(), v1.y() - v2.y(), v1.z() - v2.z()); |
---|
| 238 | } |
---|
[2430] | 239 | /**@brief Return the negative of the vector */ |
---|
[1963] | 240 | SIMD_FORCE_INLINE btVector3 |
---|
| 241 | operator-(const btVector3& v) |
---|
| 242 | { |
---|
| 243 | return btVector3(-v.x(), -v.y(), -v.z()); |
---|
| 244 | } |
---|
| 245 | |
---|
[2430] | 246 | /**@brief Return the vector scaled by s */ |
---|
[1963] | 247 | SIMD_FORCE_INLINE btVector3 |
---|
| 248 | operator*(const btVector3& v, const btScalar& s) |
---|
| 249 | { |
---|
| 250 | return btVector3(v.x() * s, v.y() * s, v.z() * s); |
---|
| 251 | } |
---|
| 252 | |
---|
[2430] | 253 | /**@brief Return the vector scaled by s */ |
---|
[1963] | 254 | SIMD_FORCE_INLINE btVector3 |
---|
| 255 | operator*(const btScalar& s, const btVector3& v) |
---|
| 256 | { |
---|
| 257 | return v * s; |
---|
| 258 | } |
---|
| 259 | |
---|
[2430] | 260 | /**@brief Return the vector inversely scaled by s */ |
---|
[1963] | 261 | SIMD_FORCE_INLINE btVector3 |
---|
| 262 | operator/(const btVector3& v, const btScalar& s) |
---|
| 263 | { |
---|
| 264 | btFullAssert(s != btScalar(0.0)); |
---|
| 265 | return v * (btScalar(1.0) / s); |
---|
| 266 | } |
---|
| 267 | |
---|
[2430] | 268 | /**@brief Return the vector inversely scaled by s */ |
---|
[1963] | 269 | SIMD_FORCE_INLINE btVector3 |
---|
| 270 | operator/(const btVector3& v1, const btVector3& v2) |
---|
| 271 | { |
---|
| 272 | return btVector3(v1.x() / v2.x(),v1.y() / v2.y(),v1.z() / v2.z()); |
---|
| 273 | } |
---|
| 274 | |
---|
[2430] | 275 | /**@brief Return the dot product between two vectors */ |
---|
[1963] | 276 | SIMD_FORCE_INLINE btScalar |
---|
| 277 | dot(const btVector3& v1, const btVector3& v2) |
---|
| 278 | { |
---|
| 279 | return v1.dot(v2); |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | |
---|
[2430] | 283 | /**@brief Return the distance squared between two vectors */ |
---|
[1963] | 284 | SIMD_FORCE_INLINE btScalar |
---|
| 285 | distance2(const btVector3& v1, const btVector3& v2) |
---|
| 286 | { |
---|
| 287 | return v1.distance2(v2); |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | |
---|
[2430] | 291 | /**@brief Return the distance between two vectors */ |
---|
[1963] | 292 | SIMD_FORCE_INLINE btScalar |
---|
| 293 | distance(const btVector3& v1, const btVector3& v2) |
---|
| 294 | { |
---|
| 295 | return v1.distance(v2); |
---|
| 296 | } |
---|
| 297 | |
---|
[2430] | 298 | /**@brief Return the angle between two vectors */ |
---|
[1963] | 299 | SIMD_FORCE_INLINE btScalar |
---|
| 300 | angle(const btVector3& v1, const btVector3& v2) |
---|
| 301 | { |
---|
| 302 | return v1.angle(v2); |
---|
| 303 | } |
---|
| 304 | |
---|
[2430] | 305 | /**@brief Return the cross product of two vectors */ |
---|
[1963] | 306 | SIMD_FORCE_INLINE btVector3 |
---|
| 307 | cross(const btVector3& v1, const btVector3& v2) |
---|
| 308 | { |
---|
| 309 | return v1.cross(v2); |
---|
| 310 | } |
---|
| 311 | |
---|
| 312 | SIMD_FORCE_INLINE btScalar |
---|
| 313 | triple(const btVector3& v1, const btVector3& v2, const btVector3& v3) |
---|
| 314 | { |
---|
| 315 | return v1.triple(v2, v3); |
---|
| 316 | } |
---|
| 317 | |
---|
[2430] | 318 | /**@brief Return the linear interpolation between two vectors |
---|
| 319 | * @param v1 One vector |
---|
| 320 | * @param v2 The other vector |
---|
| 321 | * @param t The ration of this to v (t = 0 => return v1, t=1 => return v2) */ |
---|
[1963] | 322 | SIMD_FORCE_INLINE btVector3 |
---|
| 323 | lerp(const btVector3& v1, const btVector3& v2, const btScalar& t) |
---|
| 324 | { |
---|
| 325 | return v1.lerp(v2, t); |
---|
| 326 | } |
---|
| 327 | |
---|
[2430] | 328 | /**@brief Test if each element of the vector is equivalent */ |
---|
[1963] | 329 | SIMD_FORCE_INLINE bool operator==(const btVector3& p1, const btVector3& p2) |
---|
| 330 | { |
---|
| 331 | return p1.x() == p2.x() && p1.y() == p2.y() && p1.z() == p2.z(); |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | SIMD_FORCE_INLINE btScalar btVector3::distance2(const btVector3& v) const |
---|
| 335 | { |
---|
| 336 | return (v - *this).length2(); |
---|
| 337 | } |
---|
| 338 | |
---|
| 339 | SIMD_FORCE_INLINE btScalar btVector3::distance(const btVector3& v) const |
---|
| 340 | { |
---|
| 341 | return (v - *this).length(); |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | SIMD_FORCE_INLINE btVector3 btVector3::normalized() const |
---|
| 345 | { |
---|
| 346 | return *this / length(); |
---|
| 347 | } |
---|
| 348 | |
---|
| 349 | SIMD_FORCE_INLINE btVector3 btVector3::rotate( const btVector3& wAxis, const btScalar angle ) |
---|
| 350 | { |
---|
| 351 | // wAxis must be a unit lenght vector |
---|
| 352 | |
---|
| 353 | btVector3 o = wAxis * wAxis.dot( *this ); |
---|
| 354 | btVector3 x = *this - o; |
---|
| 355 | btVector3 y; |
---|
| 356 | |
---|
| 357 | y = wAxis.cross( *this ); |
---|
| 358 | |
---|
| 359 | return ( o + x * btCos( angle ) + y * btSin( angle ) ); |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | class btVector4 : public btVector3 |
---|
| 363 | { |
---|
| 364 | public: |
---|
| 365 | |
---|
| 366 | SIMD_FORCE_INLINE btVector4() {} |
---|
| 367 | |
---|
| 368 | |
---|
| 369 | SIMD_FORCE_INLINE btVector4(const btScalar& x, const btScalar& y, const btScalar& z,const btScalar& w) |
---|
| 370 | : btVector3(x,y,z) |
---|
| 371 | { |
---|
[2430] | 372 | m_floats[3] = w; |
---|
[1963] | 373 | } |
---|
| 374 | |
---|
| 375 | |
---|
| 376 | SIMD_FORCE_INLINE btVector4 absolute4() const |
---|
| 377 | { |
---|
| 378 | return btVector4( |
---|
[2430] | 379 | btFabs(m_floats[0]), |
---|
| 380 | btFabs(m_floats[1]), |
---|
| 381 | btFabs(m_floats[2]), |
---|
| 382 | btFabs(m_floats[3])); |
---|
[1963] | 383 | } |
---|
| 384 | |
---|
| 385 | |
---|
| 386 | |
---|
[2430] | 387 | btScalar getW() const { return m_floats[3];} |
---|
[1963] | 388 | |
---|
| 389 | |
---|
| 390 | SIMD_FORCE_INLINE int maxAxis4() const |
---|
| 391 | { |
---|
| 392 | int maxIndex = -1; |
---|
| 393 | btScalar maxVal = btScalar(-1e30); |
---|
[2430] | 394 | if (m_floats[0] > maxVal) |
---|
[1963] | 395 | { |
---|
| 396 | maxIndex = 0; |
---|
[2430] | 397 | maxVal = m_floats[0]; |
---|
[1963] | 398 | } |
---|
[2430] | 399 | if (m_floats[1] > maxVal) |
---|
[1963] | 400 | { |
---|
| 401 | maxIndex = 1; |
---|
[2430] | 402 | maxVal = m_floats[1]; |
---|
[1963] | 403 | } |
---|
[2430] | 404 | if (m_floats[2] > maxVal) |
---|
[1963] | 405 | { |
---|
| 406 | maxIndex = 2; |
---|
[2430] | 407 | maxVal = m_floats[2]; |
---|
[1963] | 408 | } |
---|
[2430] | 409 | if (m_floats[3] > maxVal) |
---|
[1963] | 410 | { |
---|
| 411 | maxIndex = 3; |
---|
[2430] | 412 | maxVal = m_floats[3]; |
---|
[1963] | 413 | } |
---|
| 414 | |
---|
| 415 | |
---|
| 416 | |
---|
| 417 | |
---|
| 418 | return maxIndex; |
---|
| 419 | |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | |
---|
| 423 | SIMD_FORCE_INLINE int minAxis4() const |
---|
| 424 | { |
---|
| 425 | int minIndex = -1; |
---|
| 426 | btScalar minVal = btScalar(1e30); |
---|
[2430] | 427 | if (m_floats[0] < minVal) |
---|
[1963] | 428 | { |
---|
| 429 | minIndex = 0; |
---|
[2430] | 430 | minVal = m_floats[0]; |
---|
[1963] | 431 | } |
---|
[2430] | 432 | if (m_floats[1] < minVal) |
---|
[1963] | 433 | { |
---|
| 434 | minIndex = 1; |
---|
[2430] | 435 | minVal = m_floats[1]; |
---|
[1963] | 436 | } |
---|
[2430] | 437 | if (m_floats[2] < minVal) |
---|
[1963] | 438 | { |
---|
| 439 | minIndex = 2; |
---|
[2430] | 440 | minVal = m_floats[2]; |
---|
[1963] | 441 | } |
---|
[2430] | 442 | if (m_floats[3] < minVal) |
---|
[1963] | 443 | { |
---|
| 444 | minIndex = 3; |
---|
[2430] | 445 | minVal = m_floats[3]; |
---|
[1963] | 446 | } |
---|
| 447 | |
---|
| 448 | return minIndex; |
---|
| 449 | |
---|
| 450 | } |
---|
| 451 | |
---|
| 452 | |
---|
| 453 | SIMD_FORCE_INLINE int closestAxis4() const |
---|
| 454 | { |
---|
| 455 | return absolute4().maxAxis4(); |
---|
| 456 | } |
---|
| 457 | |
---|
| 458 | }; |
---|
| 459 | |
---|
| 460 | |
---|
| 461 | ///btSwapVector3Endian swaps vector endianness, useful for network and cross-platform serialization |
---|
| 462 | SIMD_FORCE_INLINE void btSwapScalarEndian(const btScalar& sourceVal, btScalar& destVal) |
---|
| 463 | { |
---|
| 464 | #ifdef BT_USE_DOUBLE_PRECISION |
---|
| 465 | unsigned char* dest = (unsigned char*) &destVal; |
---|
| 466 | unsigned char* src = (unsigned char*) &sourceVal; |
---|
| 467 | dest[0] = src[7]; |
---|
| 468 | dest[1] = src[6]; |
---|
| 469 | dest[2] = src[5]; |
---|
| 470 | dest[3] = src[4]; |
---|
| 471 | dest[4] = src[3]; |
---|
| 472 | dest[5] = src[2]; |
---|
| 473 | dest[6] = src[1]; |
---|
| 474 | dest[7] = src[0]; |
---|
| 475 | #else |
---|
| 476 | unsigned char* dest = (unsigned char*) &destVal; |
---|
| 477 | unsigned char* src = (unsigned char*) &sourceVal; |
---|
| 478 | dest[0] = src[3]; |
---|
| 479 | dest[1] = src[2]; |
---|
| 480 | dest[2] = src[1]; |
---|
| 481 | dest[3] = src[0]; |
---|
| 482 | #endif //BT_USE_DOUBLE_PRECISION |
---|
| 483 | } |
---|
| 484 | ///btSwapVector3Endian swaps vector endianness, useful for network and cross-platform serialization |
---|
| 485 | SIMD_FORCE_INLINE void btSwapVector3Endian(const btVector3& sourceVec, btVector3& destVec) |
---|
| 486 | { |
---|
| 487 | for (int i=0;i<4;i++) |
---|
| 488 | { |
---|
| 489 | btSwapScalarEndian(sourceVec[i],destVec[i]); |
---|
| 490 | } |
---|
| 491 | |
---|
| 492 | } |
---|
| 493 | |
---|
| 494 | ///btUnSwapVector3Endian swaps vector endianness, useful for network and cross-platform serialization |
---|
| 495 | SIMD_FORCE_INLINE void btUnSwapVector3Endian(btVector3& vector) |
---|
| 496 | { |
---|
| 497 | |
---|
| 498 | btVector3 swappedVec; |
---|
| 499 | for (int i=0;i<4;i++) |
---|
| 500 | { |
---|
| 501 | btSwapScalarEndian(vector[i],swappedVec[i]); |
---|
| 502 | } |
---|
| 503 | vector = swappedVec; |
---|
| 504 | } |
---|
| 505 | |
---|
| 506 | #endif //SIMD__VECTOR3_H |
---|