removed STL usage of Extras/ConvexBuilder and replaced by btAlignedObjectArray
fixed several warnings, thanks to sparkprime added comments patch for linear math, thanks to Tully Foote
This commit is contained in:
@@ -19,20 +19,28 @@ subject to the following restrictions:
|
||||
|
||||
#include "btQuadWord.h"
|
||||
|
||||
///btVector3 can be used to represent 3D points and vectors.
|
||||
///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
|
||||
///Ideally, this class should be replaced by a platform optimized SIMD version that keeps the data in registers
|
||||
/**@brief btVector3 can be used to represent 3D points and vectors.
|
||||
* 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
|
||||
* Ideally, this class should be replaced by a platform optimized SIMD version that keeps the data in registers
|
||||
*/
|
||||
class btVector3 : public btQuadWord {
|
||||
|
||||
public:
|
||||
/**@brief No initialization constructor */
|
||||
SIMD_FORCE_INLINE btVector3() {}
|
||||
|
||||
/**@brief Constructor from btQuadWordStorage (btVector3 inherits from this so is also valid)
|
||||
* Note: Vector3 derives from btQuadWordStorage*/
|
||||
SIMD_FORCE_INLINE btVector3(const btQuadWordStorage& q)
|
||||
: btQuadWord(q)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**@brief Constructor from scalars
|
||||
* @param x X value
|
||||
* @param y Y value
|
||||
* @param z Z value
|
||||
*/
|
||||
SIMD_FORCE_INLINE btVector3(const btScalar& x, const btScalar& y, const btScalar& z)
|
||||
:btQuadWord(x,y,z,btScalar(0.))
|
||||
{
|
||||
@@ -44,7 +52,8 @@ public:
|
||||
// }
|
||||
|
||||
|
||||
|
||||
/**@brief Add a vector to this one
|
||||
* @param The vector to add to this one */
|
||||
SIMD_FORCE_INLINE btVector3& operator+=(const btVector3& v)
|
||||
{
|
||||
|
||||
@@ -53,60 +62,80 @@ public:
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**@brief Subtract a vector from this one
|
||||
* @param The vector to subtract */
|
||||
SIMD_FORCE_INLINE btVector3& operator-=(const btVector3& v)
|
||||
{
|
||||
m_x -= v.x(); m_y -= v.y(); m_z -= v.z();
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**@brief Scale the vector
|
||||
* @param s Scale factor */
|
||||
SIMD_FORCE_INLINE btVector3& operator*=(const btScalar& s)
|
||||
{
|
||||
m_x *= s; m_y *= s; m_z *= s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**@brief Inversely scale the vector
|
||||
* @param s Scale factor to divide by */
|
||||
SIMD_FORCE_INLINE btVector3& operator/=(const btScalar& s)
|
||||
{
|
||||
btFullAssert(s != btScalar(0.0));
|
||||
return *this *= btScalar(1.0) / s;
|
||||
}
|
||||
|
||||
/**@brief Return the dot product
|
||||
* @param v The other vector in the dot product */
|
||||
SIMD_FORCE_INLINE btScalar dot(const btVector3& v) const
|
||||
{
|
||||
return m_x * v.x() + m_y * v.y() + m_z * v.z();
|
||||
}
|
||||
|
||||
/**@brief Return the length of the vector squared */
|
||||
SIMD_FORCE_INLINE btScalar length2() const
|
||||
{
|
||||
return dot(*this);
|
||||
}
|
||||
|
||||
/**@brief Return the length of the vector */
|
||||
SIMD_FORCE_INLINE btScalar length() const
|
||||
{
|
||||
return btSqrt(length2());
|
||||
}
|
||||
|
||||
/**@brief Return the distance squared between the ends of this and another vector
|
||||
* This is symantically treating the vector like a point */
|
||||
SIMD_FORCE_INLINE btScalar distance2(const btVector3& v) const;
|
||||
|
||||
/**@brief Return the distance between the ends of this and another vector
|
||||
* This is symantically treating the vector like a point */
|
||||
SIMD_FORCE_INLINE btScalar distance(const btVector3& v) const;
|
||||
|
||||
/**@brief Normalize this vector
|
||||
* x^2 + y^2 + z^2 = 1 */
|
||||
SIMD_FORCE_INLINE btVector3& normalize()
|
||||
{
|
||||
return *this /= length();
|
||||
}
|
||||
|
||||
/**@brief Return a normalized version of this vector */
|
||||
SIMD_FORCE_INLINE btVector3 normalized() const;
|
||||
|
||||
/**@brief Rotate this vector
|
||||
* @param wAxis The axis to rotate about
|
||||
* @param angle The angle to rotate by */
|
||||
SIMD_FORCE_INLINE btVector3 rotate( const btVector3& wAxis, const btScalar angle );
|
||||
|
||||
/**@brief Return the angle between this and another vector
|
||||
* @param v The other vector */
|
||||
SIMD_FORCE_INLINE btScalar angle(const btVector3& v) const
|
||||
{
|
||||
btScalar s = btSqrt(length2() * v.length2());
|
||||
btFullAssert(s != btScalar(0.0));
|
||||
return btAcos(dot(v) / s);
|
||||
}
|
||||
|
||||
/**@brief Return a vector will the absolute values of each element */
|
||||
SIMD_FORCE_INLINE btVector3 absolute() const
|
||||
{
|
||||
return btVector3(
|
||||
@@ -114,7 +143,8 @@ public:
|
||||
btFabs(m_y),
|
||||
btFabs(m_z));
|
||||
}
|
||||
|
||||
/**@brief Return the cross product between this and another vector
|
||||
* @param v The other vector */
|
||||
SIMD_FORCE_INLINE btVector3 cross(const btVector3& v) const
|
||||
{
|
||||
return btVector3(
|
||||
@@ -130,11 +160,15 @@ public:
|
||||
m_z * (v1.x() * v2.y() - v1.y() * v2.x());
|
||||
}
|
||||
|
||||
/**@brief Return the axis with the smallest value
|
||||
* Note return values are 0,1,2 for x, y, or z */
|
||||
SIMD_FORCE_INLINE int minAxis() const
|
||||
{
|
||||
return m_x < m_y ? (m_x < m_z ? 0 : 2) : (m_y < m_z ? 1 : 2);
|
||||
}
|
||||
|
||||
/**@brief Return the axis with the largest value
|
||||
* Note return values are 0,1,2 for x, y, or z */
|
||||
SIMD_FORCE_INLINE int maxAxis() const
|
||||
{
|
||||
return m_x < m_y ? (m_y < m_z ? 2 : 1) : (m_x < m_z ? 2 : 0);
|
||||
@@ -160,6 +194,9 @@ public:
|
||||
// m_co[3] = s * v0[3] + rt * v1[3];
|
||||
}
|
||||
|
||||
/**@brief Return the linear interpolation between this and another vector
|
||||
* @param v The other vector
|
||||
* @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
|
||||
{
|
||||
return btVector3(m_x + (v.x() - m_x) * t,
|
||||
@@ -167,7 +204,8 @@ public:
|
||||
m_z + (v.z() - m_z) * t);
|
||||
}
|
||||
|
||||
|
||||
/**@brief Elementwise multiply this vector by the other
|
||||
* @param v The other vector */
|
||||
SIMD_FORCE_INLINE btVector3& operator*=(const btVector3& v)
|
||||
{
|
||||
m_x *= v.x(); m_y *= v.y(); m_z *= v.z();
|
||||
@@ -178,42 +216,48 @@ public:
|
||||
|
||||
};
|
||||
|
||||
/**@brief Return the sum of two vectors (Point symantics)*/
|
||||
SIMD_FORCE_INLINE btVector3
|
||||
operator+(const btVector3& v1, const btVector3& v2)
|
||||
{
|
||||
return btVector3(v1.x() + v2.x(), v1.y() + v2.y(), v1.z() + v2.z());
|
||||
}
|
||||
|
||||
/**@brief Return the elementwise product of two vectors */
|
||||
SIMD_FORCE_INLINE btVector3
|
||||
operator*(const btVector3& v1, const btVector3& v2)
|
||||
{
|
||||
return btVector3(v1.x() * v2.x(), v1.y() * v2.y(), v1.z() * v2.z());
|
||||
}
|
||||
|
||||
/**@brief Return the difference between two vectors */
|
||||
SIMD_FORCE_INLINE btVector3
|
||||
operator-(const btVector3& v1, const btVector3& v2)
|
||||
{
|
||||
return btVector3(v1.x() - v2.x(), v1.y() - v2.y(), v1.z() - v2.z());
|
||||
}
|
||||
|
||||
/**@brief Return the negative of the vector */
|
||||
SIMD_FORCE_INLINE btVector3
|
||||
operator-(const btVector3& v)
|
||||
{
|
||||
return btVector3(-v.x(), -v.y(), -v.z());
|
||||
}
|
||||
|
||||
/**@brief Return the vector scaled by s */
|
||||
SIMD_FORCE_INLINE btVector3
|
||||
operator*(const btVector3& v, const btScalar& s)
|
||||
{
|
||||
return btVector3(v.x() * s, v.y() * s, v.z() * s);
|
||||
}
|
||||
|
||||
/**@brief Return the vector scaled by s */
|
||||
SIMD_FORCE_INLINE btVector3
|
||||
operator*(const btScalar& s, const btVector3& v)
|
||||
{
|
||||
return v * s;
|
||||
}
|
||||
|
||||
/**@brief Return the vector inversely scaled by s */
|
||||
SIMD_FORCE_INLINE btVector3
|
||||
operator/(const btVector3& v, const btScalar& s)
|
||||
{
|
||||
@@ -221,12 +265,14 @@ operator/(const btVector3& v, const btScalar& s)
|
||||
return v * (btScalar(1.0) / s);
|
||||
}
|
||||
|
||||
/**@brief Return the vector inversely scaled by s */
|
||||
SIMD_FORCE_INLINE btVector3
|
||||
operator/(const btVector3& v1, const btVector3& v2)
|
||||
{
|
||||
return btVector3(v1.x() / v2.x(),v1.y() / v2.y(),v1.z() / v2.z());
|
||||
}
|
||||
|
||||
/**@brief Return the dot product between two vectors */
|
||||
SIMD_FORCE_INLINE btScalar
|
||||
dot(const btVector3& v1, const btVector3& v2)
|
||||
{
|
||||
@@ -234,7 +280,7 @@ dot(const btVector3& v1, const btVector3& v2)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**@brief Return the distance squared between two vectors */
|
||||
SIMD_FORCE_INLINE btScalar
|
||||
distance2(const btVector3& v1, const btVector3& v2)
|
||||
{
|
||||
@@ -242,18 +288,21 @@ distance2(const btVector3& v1, const btVector3& v2)
|
||||
}
|
||||
|
||||
|
||||
/**@brief Return the distance between two vectors */
|
||||
SIMD_FORCE_INLINE btScalar
|
||||
distance(const btVector3& v1, const btVector3& v2)
|
||||
{
|
||||
return v1.distance(v2);
|
||||
}
|
||||
|
||||
/**@brief Return the angle between two vectors */
|
||||
SIMD_FORCE_INLINE btScalar
|
||||
angle(const btVector3& v1, const btVector3& v2)
|
||||
{
|
||||
return v1.angle(v2);
|
||||
}
|
||||
|
||||
/**@brief Return the cross product of two vectors */
|
||||
SIMD_FORCE_INLINE btVector3
|
||||
cross(const btVector3& v1, const btVector3& v2)
|
||||
{
|
||||
@@ -266,13 +315,17 @@ triple(const btVector3& v1, const btVector3& v2, const btVector3& v3)
|
||||
return v1.triple(v2, v3);
|
||||
}
|
||||
|
||||
/**@brief Return the linear interpolation between two vectors
|
||||
* @param v1 One vector
|
||||
* @param v2 The other vector
|
||||
* @param t The ration of this to v (t = 0 => return v1, t=1 => return v2) */
|
||||
SIMD_FORCE_INLINE btVector3
|
||||
lerp(const btVector3& v1, const btVector3& v2, const btScalar& t)
|
||||
{
|
||||
return v1.lerp(v2, t);
|
||||
}
|
||||
|
||||
|
||||
/**@brief Test if each element of the vector is equivalent */
|
||||
SIMD_FORCE_INLINE bool operator==(const btVector3& p1, const btVector3& p2)
|
||||
{
|
||||
return p1.x() == p2.x() && p1.y() == p2.y() && p1.z() == p2.z();
|
||||
|
||||
Reference in New Issue
Block a user