Some performance improvements and fixes related to btVector3 being aligned on SPU.

btQuantizedBvh has a version number, memory layout might be different now (due to aligned btVector3)
reorganized some data members of some classes, to reduce memory footprint
This commit is contained in:
erwin.coumans
2008-10-29 02:45:16 +00:00
parent b18aa2b375
commit aeb48644ee
4 changed files with 174 additions and 135 deletions

View File

@@ -20,22 +20,30 @@ subject to the following restrictions:
#include "btMinMax.h" #include "btMinMax.h"
#include <math.h> #include <math.h>
#if defined (__CELLOS_LV2) && defined (__SPU__)
#include <altivec.h>
#endif
/**@brief The btQuadWordStorage class is base class for btVector3 and btQuaternion. /**@brief The btQuadWordStorage class is base class for btVector3 and btQuaternion.
* Some issues under PS3 Linux with IBM 2.1 SDK, gcc compiler prevent from using aligned quadword. @todo look into this * Some issues under PS3 Linux with IBM 2.1 SDK, gcc compiler prevent from using aligned quadword.
* ATTRIBUTE_ALIGNED16(class) btQuadWordStorage */ */
class btQuadWordStorage
ATTRIBUTE_ALIGNED16(class) btQuadWordStorage
{ {
protected: protected:
#if defined (__SPU__)
btScalar m_x; union {
btScalar m_y; vec_float4 mVec128;
btScalar m_z; btScalar m_floats[4];
btScalar m_unusedW; };
public: public:
vec_float4 get128() const
{
return mVec128;
}
#else
btScalar m_floats[4];
#endif
}; };
@@ -44,34 +52,34 @@ class btQuadWord : public btQuadWordStorage
{ {
public: public:
// SIMD_FORCE_INLINE btScalar& operator[](int i) { return (&m_x)[i]; } // SIMD_FORCE_INLINE btScalar& operator[](int i) { return (&m_floats[0])[i]; }
// SIMD_FORCE_INLINE const btScalar& operator[](int i) const { return (&m_x)[i]; } // SIMD_FORCE_INLINE const btScalar& operator[](int i) const { return (&m_floats[0])[i]; }
/**@brief Return the x value */ /**@brief Return the x value */
SIMD_FORCE_INLINE const btScalar& getX() const { return m_x; } SIMD_FORCE_INLINE const btScalar& getX() const { return m_floats[0]; }
/**@brief Return the y value */ /**@brief Return the y value */
SIMD_FORCE_INLINE const btScalar& getY() const { return m_y; } SIMD_FORCE_INLINE const btScalar& getY() const { return m_floats[1]; }
/**@brief Return the z value */ /**@brief Return the z value */
SIMD_FORCE_INLINE const btScalar& getZ() const { return m_z; } SIMD_FORCE_INLINE const btScalar& getZ() const { return m_floats[2]; }
/**@brief Set the x value */ /**@brief Set the x value */
SIMD_FORCE_INLINE void setX(btScalar x) { m_x = x;}; SIMD_FORCE_INLINE void setX(btScalar x) { m_floats[0] = x;};
/**@brief Set the y value */ /**@brief Set the y value */
SIMD_FORCE_INLINE void setY(btScalar y) { m_y = y;}; SIMD_FORCE_INLINE void setY(btScalar y) { m_floats[1] = y;};
/**@brief Set the z value */ /**@brief Set the z value */
SIMD_FORCE_INLINE void setZ(btScalar z) { m_z = z;}; SIMD_FORCE_INLINE void setZ(btScalar z) { m_floats[2] = z;};
/**@brief Set the w value */ /**@brief Set the w value */
SIMD_FORCE_INLINE void setW(btScalar w) { m_unusedW = w;}; SIMD_FORCE_INLINE void setW(btScalar w) { m_floats[3] = w;};
/**@brief Return the x value */ /**@brief Return the x value */
SIMD_FORCE_INLINE const btScalar& x() const { return m_x; } SIMD_FORCE_INLINE const btScalar& x() const { return m_floats[0]; }
/**@brief Return the y value */ /**@brief Return the y value */
SIMD_FORCE_INLINE const btScalar& y() const { return m_y; } SIMD_FORCE_INLINE const btScalar& y() const { return m_floats[1]; }
/**@brief Return the z value */ /**@brief Return the z value */
SIMD_FORCE_INLINE const btScalar& z() const { return m_z; } SIMD_FORCE_INLINE const btScalar& z() const { return m_floats[2]; }
/**@brief Return the w value */ /**@brief Return the w value */
SIMD_FORCE_INLINE const btScalar& w() const { return m_unusedW; } SIMD_FORCE_INLINE const btScalar& w() const { return m_floats[3]; }
SIMD_FORCE_INLINE operator btScalar *() { return &m_x; } SIMD_FORCE_INLINE operator btScalar *() { return &m_floats[0]; }
SIMD_FORCE_INLINE operator const btScalar *() const { return &m_x; } SIMD_FORCE_INLINE operator const btScalar *() const { return &m_floats[0]; }
/**@brief Set x,y,z and zero w /**@brief Set x,y,z and zero w
@@ -81,17 +89,17 @@ class btQuadWord : public btQuadWordStorage
*/ */
SIMD_FORCE_INLINE void setValue(const btScalar& x, const btScalar& y, const btScalar& z) SIMD_FORCE_INLINE void setValue(const btScalar& x, const btScalar& y, const btScalar& z)
{ {
m_x=x; m_floats[0]=x;
m_y=y; m_floats[1]=y;
m_z=z; m_floats[2]=z;
m_unusedW = 0.f; m_floats[3] = 0.f;
} }
/* void getValue(btScalar *m) const /* void getValue(btScalar *m) const
{ {
m[0] = m_x; m[0] = m_floats[0];
m[1] = m_y; m[1] = m_floats[1];
m[2] = m_z; m[2] = m_floats[2];
} }
*/ */
/**@brief Set the values /**@brief Set the values
@@ -102,14 +110,14 @@ class btQuadWord : public btQuadWordStorage
*/ */
SIMD_FORCE_INLINE void setValue(const btScalar& x, const btScalar& y, const btScalar& z,const btScalar& w) SIMD_FORCE_INLINE void setValue(const btScalar& x, const btScalar& y, const btScalar& z,const btScalar& w)
{ {
m_x=x; m_floats[0]=x;
m_y=y; m_floats[1]=y;
m_z=z; m_floats[2]=z;
m_unusedW=w; m_floats[3]=w;
} }
/**@brief No initialization constructor */ /**@brief No initialization constructor */
SIMD_FORCE_INLINE btQuadWord() SIMD_FORCE_INLINE btQuadWord()
// :m_x(btScalar(0.)),m_y(btScalar(0.)),m_z(btScalar(0.)),m_unusedW(btScalar(0.)) // :m_floats[0](btScalar(0.)),m_floats[1](btScalar(0.)),m_floats[2](btScalar(0.)),m_floats[3](btScalar(0.))
{ {
} }
/**@brief Copy constructor */ /**@brief Copy constructor */
@@ -124,7 +132,7 @@ class btQuadWord : public btQuadWordStorage
*/ */
SIMD_FORCE_INLINE btQuadWord(const btScalar& x, const btScalar& y, const btScalar& z) SIMD_FORCE_INLINE btQuadWord(const btScalar& x, const btScalar& y, const btScalar& z)
{ {
m_x = x, m_y = y, m_z = z, m_unusedW = 0.0f; m_floats[0] = x, m_floats[1] = y, m_floats[2] = z, m_floats[3] = 0.0f;
} }
/**@brief Initializing constructor /**@brief Initializing constructor
@@ -135,7 +143,7 @@ class btQuadWord : public btQuadWordStorage
*/ */
SIMD_FORCE_INLINE btQuadWord(const btScalar& x, const btScalar& y, const btScalar& z,const btScalar& w) SIMD_FORCE_INLINE btQuadWord(const btScalar& x, const btScalar& y, const btScalar& z,const btScalar& w)
{ {
m_x = x, m_y = y, m_z = z, m_unusedW = w; m_floats[0] = x, m_floats[1] = y, m_floats[2] = z, m_floats[3] = w;
} }
/**@brief Set each element to the max of the current values and the values of another btQuadWord /**@brief Set each element to the max of the current values and the values of another btQuadWord
@@ -143,20 +151,20 @@ class btQuadWord : public btQuadWordStorage
*/ */
SIMD_FORCE_INLINE void setMax(const btQuadWord& other) SIMD_FORCE_INLINE void setMax(const btQuadWord& other)
{ {
btSetMax(m_x, other.m_x); btSetMax(m_floats[0], other.m_floats[0]);
btSetMax(m_y, other.m_y); btSetMax(m_floats[1], other.m_floats[1]);
btSetMax(m_z, other.m_z); btSetMax(m_floats[2], other.m_floats[2]);
btSetMax(m_unusedW, other.m_unusedW); btSetMax(m_floats[3], other.m_floats[3]);
} }
/**@brief Set each element to the min of the current values and the values of another btQuadWord /**@brief Set each element to the min of the current values and the values of another btQuadWord
* @param other The other btQuadWord to compare with * @param other The other btQuadWord to compare with
*/ */
SIMD_FORCE_INLINE void setMin(const btQuadWord& other) SIMD_FORCE_INLINE void setMin(const btQuadWord& other)
{ {
btSetMin(m_x, other.m_x); btSetMin(m_floats[0], other.m_floats[0]);
btSetMin(m_y, other.m_y); btSetMin(m_floats[1], other.m_floats[1]);
btSetMin(m_z, other.m_z); btSetMin(m_floats[2], other.m_floats[2]);
btSetMin(m_unusedW, other.m_unusedW); btSetMin(m_floats[3], other.m_floats[3]);
} }

View File

@@ -106,14 +106,14 @@ public:
* @param q The quaternion to add to this one */ * @param q The quaternion to add to this one */
btQuaternion& operator+=(const btQuaternion& q) btQuaternion& operator+=(const btQuaternion& q)
{ {
m_x += q.x(); m_y += q.y(); m_z += q.z(); m_unusedW += q.m_unusedW; m_floats[0] += q.x(); m_floats[1] += q.y(); m_floats[2] += q.z(); m_floats[3] += q.m_floats[3];
return *this; return *this;
} }
/**@brief Subtract out a quaternion /**@brief Subtract out a quaternion
* @param q The quaternion to subtract from this one */ * @param q The quaternion to subtract from this one */
btQuaternion& operator-=(const btQuaternion& q) btQuaternion& operator-=(const btQuaternion& q)
{ {
m_x -= q.x(); m_y -= q.y(); m_z -= q.z(); m_unusedW -= q.m_unusedW; m_floats[0] -= q.x(); m_floats[1] -= q.y(); m_floats[2] -= q.z(); m_floats[3] -= q.m_floats[3];
return *this; return *this;
} }
@@ -121,7 +121,7 @@ public:
* @param s The scalar to scale by */ * @param s The scalar to scale by */
btQuaternion& operator*=(const btScalar& s) btQuaternion& operator*=(const btScalar& s)
{ {
m_x *= s; m_y *= s; m_z *= s; m_unusedW *= s; m_floats[0] *= s; m_floats[1] *= s; m_floats[2] *= s; m_floats[3] *= s;
return *this; return *this;
} }
@@ -130,17 +130,17 @@ public:
* Equivilant to this = this * q */ * Equivilant to this = this * q */
btQuaternion& operator*=(const btQuaternion& q) btQuaternion& operator*=(const btQuaternion& q)
{ {
setValue(m_unusedW * q.x() + m_x * q.m_unusedW + m_y * q.z() - m_z * q.y(), setValue(m_floats[3] * q.x() + m_floats[0] * q.m_floats[3] + m_floats[1] * q.z() - m_floats[2] * q.y(),
m_unusedW * q.y() + m_y * q.m_unusedW + m_z * q.x() - m_x * q.z(), m_floats[3] * q.y() + m_floats[1] * q.m_floats[3] + m_floats[2] * q.x() - m_floats[0] * q.z(),
m_unusedW * q.z() + m_z * q.m_unusedW + m_x * q.y() - m_y * q.x(), m_floats[3] * q.z() + m_floats[2] * q.m_floats[3] + m_floats[0] * q.y() - m_floats[1] * q.x(),
m_unusedW * q.m_unusedW - m_x * q.x() - m_y * q.y() - m_z * q.z()); m_floats[3] * q.m_floats[3] - m_floats[0] * q.x() - m_floats[1] * q.y() - m_floats[2] * q.z());
return *this; return *this;
} }
/**@brief Return the dot product between this quaternion and another /**@brief Return the dot product between this quaternion and another
* @param q The other quaternion */ * @param q The other quaternion */
btScalar dot(const btQuaternion& q) const btScalar dot(const btQuaternion& q) const
{ {
return m_x * q.x() + m_y * q.y() + m_z * q.z() + m_unusedW * q.m_unusedW; return m_floats[0] * q.x() + m_floats[1] * q.y() + m_floats[2] * q.z() + m_floats[3] * q.m_floats[3];
} }
/**@brief Return the length squared of the quaternion */ /**@brief Return the length squared of the quaternion */
@@ -167,7 +167,7 @@ public:
SIMD_FORCE_INLINE btQuaternion SIMD_FORCE_INLINE btQuaternion
operator*(const btScalar& s) const operator*(const btScalar& s) const
{ {
return btQuaternion(x() * s, y() * s, z() * s, m_unusedW * s); return btQuaternion(x() * s, y() * s, z() * s, m_floats[3] * s);
} }
@@ -203,7 +203,7 @@ public:
/**@brief Return the angle of rotation represented by this quaternion */ /**@brief Return the angle of rotation represented by this quaternion */
btScalar getAngle() const btScalar getAngle() const
{ {
btScalar s = btScalar(2.) * btAcos(m_unusedW); btScalar s = btScalar(2.) * btAcos(m_floats[3]);
return s; return s;
} }
@@ -211,7 +211,7 @@ public:
/**@brief Return the inverse of this quaternion */ /**@brief Return the inverse of this quaternion */
btQuaternion inverse() const btQuaternion inverse() const
{ {
return btQuaternion(-m_x, -m_y, -m_z, m_unusedW); return btQuaternion(-m_floats[0], -m_floats[1], -m_floats[2], m_floats[3]);
} }
/**@brief Return the sum of this quaternion and the other /**@brief Return the sum of this quaternion and the other
@@ -220,7 +220,7 @@ public:
operator+(const btQuaternion& q2) const operator+(const btQuaternion& q2) const
{ {
const btQuaternion& q1 = *this; const btQuaternion& q1 = *this;
return btQuaternion(q1.x() + q2.x(), q1.y() + q2.y(), q1.z() + q2.z(), q1.m_unusedW + q2.m_unusedW); return btQuaternion(q1.x() + q2.x(), q1.y() + q2.y(), q1.z() + q2.z(), q1.m_floats[3] + q2.m_floats[3]);
} }
/**@brief Return the difference between this quaternion and the other /**@brief Return the difference between this quaternion and the other
@@ -229,7 +229,7 @@ public:
operator-(const btQuaternion& q2) const operator-(const btQuaternion& q2) const
{ {
const btQuaternion& q1 = *this; const btQuaternion& q1 = *this;
return btQuaternion(q1.x() - q2.x(), q1.y() - q2.y(), q1.z() - q2.z(), q1.m_unusedW - q2.m_unusedW); return btQuaternion(q1.x() - q2.x(), q1.y() - q2.y(), q1.z() - q2.z(), q1.m_floats[3] - q2.m_floats[3]);
} }
/**@brief Return the negative of this quaternion /**@brief Return the negative of this quaternion
@@ -237,7 +237,7 @@ public:
SIMD_FORCE_INLINE btQuaternion operator-() const SIMD_FORCE_INLINE btQuaternion operator-() const
{ {
const btQuaternion& q2 = *this; const btQuaternion& q2 = *this;
return btQuaternion( - q2.x(), - q2.y(), - q2.z(), - q2.m_unusedW); return btQuaternion( - q2.x(), - q2.y(), - q2.z(), - q2.m_floats[3]);
} }
/**@todo document this and it's use */ /**@todo document this and it's use */
SIMD_FORCE_INLINE btQuaternion farthest( const btQuaternion& qd) const SIMD_FORCE_INLINE btQuaternion farthest( const btQuaternion& qd) const
@@ -262,10 +262,10 @@ public:
btScalar d = btScalar(1.0) / btSin(theta); btScalar d = btScalar(1.0) / btSin(theta);
btScalar s0 = btSin((btScalar(1.0) - t) * theta); btScalar s0 = btSin((btScalar(1.0) - t) * theta);
btScalar s1 = btSin(t * theta); btScalar s1 = btSin(t * theta);
return btQuaternion((m_x * s0 + q.x() * s1) * d, return btQuaternion((m_floats[0] * s0 + q.x() * s1) * d,
(m_y * s0 + q.y() * s1) * d, (m_floats[1] * s0 + q.y() * s1) * d,
(m_z * s0 + q.z() * s1) * d, (m_floats[2] * s0 + q.z() * s1) * d,
(m_unusedW * s0 + q.m_unusedW * s1) * d); (m_floats[3] * s0 + q.m_floats[3] * s1) * d);
} }
else else
{ {
@@ -273,7 +273,7 @@ public:
} }
} }
SIMD_FORCE_INLINE const btScalar& getW() const { return m_unusedW; } SIMD_FORCE_INLINE const btScalar& getW() const { return m_floats[3]; }
}; };

View File

@@ -100,6 +100,32 @@ public:
predictedTransform.setRotation(predictedOrn); predictedTransform.setRotation(predictedOrn);
} }
static void calculateVelocityQuaternion(const btVector3& pos0,const btVector3& pos1,const btQuaternion& orn0,const btQuaternion& orn1,btScalar timeStep,btVector3& linVel,btVector3& angVel)
{
linVel = (pos1 - pos0) / timeStep;
btVector3 axis;
btScalar angle;
calculateDiffAxisAngleQuaternion(orn0,orn1,axis,angle);
angVel = axis * angle / timeStep;
}
static void calculateDiffAxisAngleQuaternion(const btQuaternion& orn0,const btQuaternion& orn1a,btVector3& axis,btScalar& angle)
{
btQuaternion orn1 = orn0.farthest(orn1a);
btQuaternion dorn = orn1 * orn0.inverse();
///floating point inaccuracy can lead to w component > 1..., which breaks
dorn.normalize();
angle = dorn.getAngle();
axis = btVector3(dorn.x(),dorn.y(),dorn.z());
axis[3] = btScalar(0.);
//check for axis length
btScalar len = axis.length2();
if (len < SIMD_EPSILON*SIMD_EPSILON)
axis = btVector3(btScalar(1.),btScalar(0.),btScalar(0.));
else
axis /= btSqrt(len);
}
static void calculateVelocity(const btTransform& transform0,const btTransform& transform1,btScalar timeStep,btVector3& linVel,btVector3& angVel) static void calculateVelocity(const btTransform& transform0,const btTransform& transform1,btScalar timeStep,btVector3& linVel,btVector3& angVel)
{ {
linVel = (transform1.getOrigin() - transform0.getOrigin()) / timeStep; linVel = (transform1.getOrigin() - transform0.getOrigin()) / timeStep;
@@ -111,20 +137,11 @@ public:
static void calculateDiffAxisAngle(const btTransform& transform0,const btTransform& transform1,btVector3& axis,btScalar& angle) static void calculateDiffAxisAngle(const btTransform& transform0,const btTransform& transform1,btVector3& axis,btScalar& angle)
{ {
#ifdef USE_QUATERNION_DIFF
btQuaternion orn0 = transform0.getRotation();
btQuaternion orn1a = transform1.getRotation();
btQuaternion orn1 = orn0.farthest(orn1a);
btQuaternion dorn = orn1 * orn0.inverse();
#else
btMatrix3x3 dmat = transform1.getBasis() * transform0.getBasis().inverse(); btMatrix3x3 dmat = transform1.getBasis() * transform0.getBasis().inverse();
btQuaternion dorn; btQuaternion dorn;
dmat.getRotation(dorn); dmat.getRotation(dorn);
#endif//USE_QUATERNION_DIFF
///floating point inaccuracy can lead to w component > 1..., which breaks
///floating point inaccuracy can lead to w component > 1..., which breaks
dorn.normalize(); dorn.normalize();
angle = dorn.getAngle(); angle = dorn.getAngle();
@@ -145,13 +162,15 @@ public:
///by conservatively updating a cached separating distance/vector instead of re-calculating the closest distance ///by conservatively updating a cached separating distance/vector instead of re-calculating the closest distance
class btConvexSeparatingDistanceUtil class btConvexSeparatingDistanceUtil
{ {
btTransform m_cachedTransformA; btQuaternion m_ornA;
btTransform m_cachedTransformB; btQuaternion m_ornB;
btVector3 m_posA;
btVector3 m_posB;
btVector3 m_separatingNormal;
btScalar m_boundingRadiusA; btScalar m_boundingRadiusA;
btScalar m_boundingRadiusB; btScalar m_boundingRadiusB;
btVector3 m_separatingNormal;
btScalar m_separatingDistance; btScalar m_separatingDistance;
public: public:
@@ -170,15 +189,18 @@ public:
void updateSeparatingDistance(const btTransform& transA,const btTransform& transB) void updateSeparatingDistance(const btTransform& transA,const btTransform& transB)
{ {
const btVector3& toPosA = transA.getOrigin();
const btVector3& toPosB = transB.getOrigin();
btQuaternion toOrnA = transA.getRotation();
btQuaternion toOrnB = transB.getRotation();
if (m_separatingDistance>0.f) if (m_separatingDistance>0.f)
{ {
const btTransform& fromA = m_cachedTransformA;
const btTransform& fromB = m_cachedTransformB;
const btTransform& toA = transA;
const btTransform& toB = transB;
btVector3 linVelA,angVelA,linVelB,angVelB; btVector3 linVelA,angVelA,linVelB,angVelB;
btTransformUtil::calculateVelocity(fromA,toA,btScalar(1.),linVelA,angVelA); btTransformUtil::calculateVelocityQuaternion(m_posA,toPosA,m_ornA,toOrnA,btScalar(1.),linVelA,angVelA);
btTransformUtil::calculateVelocity(fromB,toB,btScalar(1.),linVelB,angVelB); btTransformUtil::calculateVelocityQuaternion(m_posB,toPosB,m_ornB,toOrnB,btScalar(1.),linVelB,angVelB);
btScalar maxAngularProjectedVelocity = angVelA.length() * m_boundingRadiusA + angVelB.length() * m_boundingRadiusB; btScalar maxAngularProjectedVelocity = angVelA.length() * m_boundingRadiusA + angVelB.length() * m_boundingRadiusB;
btVector3 relLinVel = (linVelB-linVelA); btVector3 relLinVel = (linVelB-linVelA);
btScalar relLinVelocLength = (linVelB-linVelA).dot(m_separatingNormal); btScalar relLinVelocLength = (linVelB-linVelA).dot(m_separatingNormal);
@@ -191,16 +213,25 @@ public:
m_separatingDistance -= projectedMotion; m_separatingDistance -= projectedMotion;
} }
m_cachedTransformA = transA; m_posA = toPosA;
m_cachedTransformB = transB; m_posB = toPosB;
m_ornA = toOrnA;
m_ornB = toOrnB;
} }
void initSeparatingDistance(const btVector3& separatingVector,btScalar separatingDistance,const btTransform& transA,const btTransform& transB) void initSeparatingDistance(const btVector3& separatingVector,btScalar separatingDistance,const btTransform& transA,const btTransform& transB)
{ {
m_separatingNormal = separatingVector; m_separatingNormal = separatingVector;
m_separatingDistance = separatingDistance; m_separatingDistance = separatingDistance;
m_cachedTransformA = transA;
m_cachedTransformB = transB; const btVector3& toPosA = transA.getOrigin();
const btVector3& toPosB = transB.getOrigin();
btQuaternion toOrnA = transA.getRotation();
btQuaternion toOrnB = transB.getRotation();
m_posA = toPosA;
m_posB = toPosB;
m_ornA = toOrnA;
m_ornB = toOrnB;
} }
}; };

View File

@@ -57,7 +57,7 @@ public:
SIMD_FORCE_INLINE btVector3& operator+=(const btVector3& v) SIMD_FORCE_INLINE btVector3& operator+=(const btVector3& v)
{ {
m_x += v.x(); m_y += v.y(); m_z += v.z(); m_floats[0] += v.x(); m_floats[1] += v.y(); m_floats[2] += v.z();
return *this; return *this;
} }
@@ -66,14 +66,14 @@ public:
* @param The vector to subtract */ * @param The vector to subtract */
SIMD_FORCE_INLINE btVector3& operator-=(const btVector3& v) SIMD_FORCE_INLINE btVector3& operator-=(const btVector3& v)
{ {
m_x -= v.x(); m_y -= v.y(); m_z -= v.z(); m_floats[0] -= v.x(); m_floats[1] -= v.y(); m_floats[2] -= v.z();
return *this; return *this;
} }
/**@brief Scale the vector /**@brief Scale the vector
* @param s Scale factor */ * @param s Scale factor */
SIMD_FORCE_INLINE btVector3& operator*=(const btScalar& s) SIMD_FORCE_INLINE btVector3& operator*=(const btScalar& s)
{ {
m_x *= s; m_y *= s; m_z *= s; m_floats[0] *= s; m_floats[1] *= s; m_floats[2] *= s;
return *this; return *this;
} }
@@ -89,7 +89,7 @@ public:
* @param v The other vector in the dot product */ * @param v The other vector in the dot product */
SIMD_FORCE_INLINE btScalar dot(const btVector3& v) const SIMD_FORCE_INLINE btScalar dot(const btVector3& v) const
{ {
return m_x * v.x() + m_y * v.y() + m_z * v.z(); return m_floats[0] * v.x() + m_floats[1] * v.y() + m_floats[2] * v.z();
} }
/**@brief Return the length of the vector squared */ /**@brief Return the length of the vector squared */
@@ -139,39 +139,39 @@ public:
SIMD_FORCE_INLINE btVector3 absolute() const SIMD_FORCE_INLINE btVector3 absolute() const
{ {
return btVector3( return btVector3(
btFabs(m_x), btFabs(m_floats[0]),
btFabs(m_y), btFabs(m_floats[1]),
btFabs(m_z)); btFabs(m_floats[2]));
} }
/**@brief Return the cross product between this and another vector /**@brief Return the cross product between this and another vector
* @param v The other vector */ * @param v The other vector */
SIMD_FORCE_INLINE btVector3 cross(const btVector3& v) const SIMD_FORCE_INLINE btVector3 cross(const btVector3& v) const
{ {
return btVector3( return btVector3(
m_y * v.z() - m_z * v.y(), m_floats[1] * v.z() - m_floats[2] * v.y(),
m_z * v.x() - m_x * v.z(), m_floats[2] * v.x() - m_floats[0] * v.z(),
m_x * v.y() - m_y * v.x()); m_floats[0] * v.y() - m_floats[1] * v.x());
} }
SIMD_FORCE_INLINE btScalar triple(const btVector3& v1, const btVector3& v2) const SIMD_FORCE_INLINE btScalar triple(const btVector3& v1, const btVector3& v2) const
{ {
return m_x * (v1.y() * v2.z() - v1.z() * v2.y()) + return m_floats[0] * (v1.y() * v2.z() - v1.z() * v2.y()) +
m_y * (v1.z() * v2.x() - v1.x() * v2.z()) + m_floats[1] * (v1.z() * v2.x() - v1.x() * v2.z()) +
m_z * (v1.x() * v2.y() - v1.y() * v2.x()); m_floats[2] * (v1.x() * v2.y() - v1.y() * v2.x());
} }
/**@brief Return the axis with the smallest value /**@brief Return the axis with the smallest value
* Note return values are 0,1,2 for x, y, or z */ * Note return values are 0,1,2 for x, y, or z */
SIMD_FORCE_INLINE int minAxis() const SIMD_FORCE_INLINE int minAxis() const
{ {
return m_x < m_y ? (m_x < m_z ? 0 : 2) : (m_y < m_z ? 1 : 2); return m_floats[0] < m_floats[1] ? (m_floats[0] < m_floats[2] ? 0 : 2) : (m_floats[1] < m_floats[2] ? 1 : 2);
} }
/**@brief Return the axis with the largest value /**@brief Return the axis with the largest value
* Note return values are 0,1,2 for x, y, or z */ * Note return values are 0,1,2 for x, y, or z */
SIMD_FORCE_INLINE int maxAxis() const SIMD_FORCE_INLINE int maxAxis() const
{ {
return m_x < m_y ? (m_y < m_z ? 2 : 1) : (m_x < m_z ? 2 : 0); return m_floats[0] < m_floats[1] ? (m_floats[1] < m_floats[2] ? 2 : 1) : (m_floats[0] < m_floats[2] ? 2 : 0);
} }
SIMD_FORCE_INLINE int furthestAxis() const SIMD_FORCE_INLINE int furthestAxis() const
@@ -187,9 +187,9 @@ public:
SIMD_FORCE_INLINE void setInterpolate3(const btVector3& v0, const btVector3& v1, btScalar rt) SIMD_FORCE_INLINE void setInterpolate3(const btVector3& v0, const btVector3& v1, btScalar rt)
{ {
btScalar s = btScalar(1.0) - rt; btScalar s = btScalar(1.0) - rt;
m_x = s * v0.x() + rt * v1.x(); m_floats[0] = s * v0.x() + rt * v1.x();
m_y = s * v0.y() + rt * v1.y(); m_floats[1] = s * v0.y() + rt * v1.y();
m_z = s * v0.z() + rt * v1.z(); m_floats[2] = s * v0.z() + rt * v1.z();
//don't do the unused w component //don't do the unused w component
// m_co[3] = s * v0[3] + rt * v1[3]; // m_co[3] = s * v0[3] + rt * v1[3];
} }
@@ -199,16 +199,16 @@ public:
* @param t The ration of this to v (t = 0 => return this, t=1 => return other) */ * @param t The ration of this to v (t = 0 => return this, t=1 => return other) */
SIMD_FORCE_INLINE btVector3 lerp(const btVector3& v, const btScalar& t) const SIMD_FORCE_INLINE btVector3 lerp(const btVector3& v, const btScalar& t) const
{ {
return btVector3(m_x + (v.x() - m_x) * t, return btVector3(m_floats[0] + (v.x() - m_floats[0]) * t,
m_y + (v.y() - m_y) * t, m_floats[1] + (v.y() - m_floats[1]) * t,
m_z + (v.z() - m_z) * t); m_floats[2] + (v.z() - m_floats[2]) * t);
} }
/**@brief Elementwise multiply this vector by the other /**@brief Elementwise multiply this vector by the other
* @param v The other vector */ * @param v The other vector */
SIMD_FORCE_INLINE btVector3& operator*=(const btVector3& v) SIMD_FORCE_INLINE btVector3& operator*=(const btVector3& v)
{ {
m_x *= v.x(); m_y *= v.y(); m_z *= v.z(); m_floats[0] *= v.x(); m_floats[1] *= v.y(); m_floats[2] *= v.z();
return *this; return *this;
} }
@@ -369,47 +369,47 @@ public:
SIMD_FORCE_INLINE btVector4(const btScalar& x, const btScalar& y, const btScalar& z,const btScalar& w) SIMD_FORCE_INLINE btVector4(const btScalar& x, const btScalar& y, const btScalar& z,const btScalar& w)
: btVector3(x,y,z) : btVector3(x,y,z)
{ {
m_unusedW = w; m_floats[3] = w;
} }
SIMD_FORCE_INLINE btVector4 absolute4() const SIMD_FORCE_INLINE btVector4 absolute4() const
{ {
return btVector4( return btVector4(
btFabs(m_x), btFabs(m_floats[0]),
btFabs(m_y), btFabs(m_floats[1]),
btFabs(m_z), btFabs(m_floats[2]),
btFabs(m_unusedW)); btFabs(m_floats[3]));
} }
btScalar getW() const { return m_unusedW;} btScalar getW() const { return m_floats[3];}
SIMD_FORCE_INLINE int maxAxis4() const SIMD_FORCE_INLINE int maxAxis4() const
{ {
int maxIndex = -1; int maxIndex = -1;
btScalar maxVal = btScalar(-1e30); btScalar maxVal = btScalar(-1e30);
if (m_x > maxVal) if (m_floats[0] > maxVal)
{ {
maxIndex = 0; maxIndex = 0;
maxVal = m_x; maxVal = m_floats[0];
} }
if (m_y > maxVal) if (m_floats[1] > maxVal)
{ {
maxIndex = 1; maxIndex = 1;
maxVal = m_y; maxVal = m_floats[1];
} }
if (m_z > maxVal) if (m_floats[2] > maxVal)
{ {
maxIndex = 2; maxIndex = 2;
maxVal = m_z; maxVal = m_floats[2];
} }
if (m_unusedW > maxVal) if (m_floats[3] > maxVal)
{ {
maxIndex = 3; maxIndex = 3;
maxVal = m_unusedW; maxVal = m_floats[3];
} }
@@ -424,25 +424,25 @@ public:
{ {
int minIndex = -1; int minIndex = -1;
btScalar minVal = btScalar(1e30); btScalar minVal = btScalar(1e30);
if (m_x < minVal) if (m_floats[0] < minVal)
{ {
minIndex = 0; minIndex = 0;
minVal = m_x; minVal = m_floats[0];
} }
if (m_y < minVal) if (m_floats[1] < minVal)
{ {
minIndex = 1; minIndex = 1;
minVal = m_y; minVal = m_floats[1];
} }
if (m_z < minVal) if (m_floats[2] < minVal)
{ {
minIndex = 2; minIndex = 2;
minVal = m_z; minVal = m_floats[2];
} }
if (m_unusedW < minVal) if (m_floats[3] < minVal)
{ {
minIndex = 3; minIndex = 3;
minVal = m_unusedW; minVal = m_floats[3];
} }
return minIndex; return minIndex;