From 500e2ebfd61d03a973e254b36d6f87d4bfdcf282 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 27 May 2015 21:21:29 +0200 Subject: [PATCH] [DEV] update compile without bullet --- etk/math/Vector2D.h | 10 +++- etk/math/Vector4D.h | 127 +++++++++++++++++--------------------------- 2 files changed, 57 insertions(+), 80 deletions(-) diff --git a/etk/math/Vector2D.h b/etk/math/Vector2D.h index 380403d..e4785f3 100644 --- a/etk/math/Vector2D.h +++ b/etk/math/Vector2D.h @@ -235,7 +235,15 @@ namespace etk { * @brief Return the length of the vector */ btScalar length() const { - return btSqrt(length2()); + #ifdef ETK_BUILD_LINEARMATH + return btSqrt(length2()); + #else + #if __CPP_VERSION__ >= 2011 + return std::sqrt(length2()); + #else + return sqrt(length2()); + #endif + #endif } /** * @brief Return the distance squared between the ends of this and another vector diff --git a/etk/math/Vector4D.h b/etk/math/Vector4D.h index fa8cd96..a841e2f 100644 --- a/etk/math/Vector4D.h +++ b/etk/math/Vector4D.h @@ -31,8 +31,7 @@ namespace etk { /** * @brief No initialization constructor (faster ...) */ - Vector4D() - { + Vector4D() { #ifdef DEBUG // in debug mode we set supid value to prevent forget of the inits ... m_floats[0] = (T)34673363; @@ -47,8 +46,7 @@ namespace etk { * @param y Y value * @param z Z value */ - Vector4D(const T& _x, const T& _y, const T& _z, const T& _w) - { + Vector4D(const T& _x, const T& _y, const T& _z, const T& _w) { m_floats[0] = _x; m_floats[1] = _y; m_floats[2] = _z; @@ -59,16 +57,14 @@ namespace etk { * @brief Add a vector to this one * @param The vector to add to this one */ - Vector4D& operator+=(const Vector4D& v) - { + Vector4D& operator+=(const Vector4D& v) { m_floats[0] += v.m_floats[0]; m_floats[1] += v.m_floats[1]; m_floats[2] += v.m_floats[2]; m_floats[3] += v.m_floats[3]; return *this; } - Vector4D operator+(const Vector4D& v) - { + Vector4D operator+(const Vector4D& v) { return Vector4D(m_floats[0] + v.m_floats[0], m_floats[1] + v.m_floats[1], m_floats[2] + v.m_floats[2], @@ -80,16 +76,14 @@ namespace etk { * @brief Subtract a vector from this one * @param The vector to subtract */ - Vector4D& operator-=(const Vector4D& v) - { + Vector4D& operator-=(const Vector4D& v) { m_floats[0] -= v.m_floats[0]; m_floats[1] -= v.m_floats[1]; m_floats[2] -= v.m_floats[2]; m_floats[3] -= v.m_floats[3]; return *this; } - Vector4D operator-(const Vector4D& v) - { + Vector4D operator-(const Vector4D& v) { return Vector4D(m_floats[0] - v.m_floats[0], m_floats[1] - v.m_floats[1], m_floats[2] - v.m_floats[2], @@ -100,16 +94,14 @@ namespace etk { * @brief Scale the vector * @param s Scale factor */ - Vector4D& operator*=(const T& s) - { + Vector4D& operator*=(const T& s) { m_floats[0] *= s; m_floats[1] *= s; m_floats[2] *= s; m_floats[3] *= s; return *this; } - Vector4D operator*(const T& s) - { + Vector4D operator*(const T& s) { return Vector4D(m_floats[0] * s, m_floats[1] * s, m_floats[2] * s, @@ -120,15 +112,13 @@ namespace etk { * @brief Inversely scale the vector * @param s Scale factor to divide by */ - Vector4D& operator/=(const Vector4D& s) - { + Vector4D& operator/=(const Vector4D& s) { if (0!=s) { return *this *= 1.0f / s; } return *this; } - Vector4D& operator/=(const T& s) - { + Vector4D& operator/=(const T& s) { if (0!=s) { m_floats[0]/=s; m_floats[1]/=s; @@ -143,8 +133,7 @@ namespace etk { * @brief Return the dot product * @param v The other vector in the dot product */ - float dot(const Vector4D& v) const - { + float dot(const Vector4D& v) const { return m_floats[0] * v.m_floats[0] + m_floats[1] * v.m_floats[1] + m_floats[2] * v.m_floats[2] + @@ -154,25 +143,30 @@ namespace etk { /** * @brief Return the length of the vector squared */ - float length2() const - { + float length2() const { return dot(*this); } /** * @brief Return the length of the vector */ - float length() const - { - return btSqrt(length2()); + float length() const { + #ifdef ETK_BUILD_LINEARMATH + return btSqrt(length2()); + #else + #if __CPP_VERSION__ >= 2011 + return std::sqrt(length2()); + #else + return sqrt(length2()); + #endif + #endif } /** * @brief Return the distance squared between the ends of this and another vector * This is symantically treating the vector like a point */ - float distance2(const Vector4D& v) const - { + float distance2(const Vector4D& v) const { return (v - *this).length2(); } @@ -180,13 +174,11 @@ namespace etk { * @brief Return the distance between the ends of this and another vector * This is symantically treating the vector like a point */ - float distance(const Vector4D& v) const - { + float distance(const Vector4D& v) const { return (v - *this).length(); } /* - Vector4D& safeNormalize() - { + Vector4D& safeNormalize() { Vector4D absVec = this->absolute(); int maxIndex = absVec.maxAxis(); if (absVec[maxIndex]>0) @@ -202,16 +194,14 @@ namespace etk { * @brief Normalize this vector * x^2 + y^2 + z^2 = 1 */ - Vector4D& normalize() - { + Vector4D& normalize() { return *this /= length(); } /** * @brief Return a normalized version of this vector */ - Vector4D normalized() const - { + Vector4D normalized() const { return *this / length(); } @@ -221,8 +211,7 @@ namespace etk { * @param angle The angle to rotate by */ /* - Vector4D rotate( const Vector3D& wAxis, const btScalar angle ) const - { + Vector4D rotate( const Vector3D& wAxis, const btScalar angle ) const { Vector4D o = wAxis * wAxis.dot( *this ); Vector4D _x = *this - o; Vector4D _y; @@ -235,8 +224,7 @@ namespace etk { * @param v The other vector */ /* - btScalar angle(const Vector3D& v) const - { + btScalar angle(const Vector3D& v) const { btScalar s = sqrtf(length2() * v.length2()); if (0!=s) { return acosf(dot(v) / s); @@ -247,8 +235,7 @@ namespace etk { /** * @brief Return a vector will the absolute values of each element */ - Vector4D absolute() const - { + Vector4D absolute() const { return Vector4D( abs(m_floats[0]), abs(m_floats[1]), abs(m_floats[2]), @@ -260,15 +247,13 @@ namespace etk { * @param v The other vector */ /* - Vector4D cross(const Vector4D& v) const - { + Vector4D cross(const Vector4D& v) const { return Vector4D(m_floats[1] * v.m_floats[2] - m_floats[2] * v.m_floats[1], m_floats[2] * v.m_floats[0] - m_floats[0] * v.m_floats[2], m_floats[0] * v.m_floats[1] - m_floats[1] * v.m_floats[0]); } - T triple(const Vector4D& v1, const Vector4D& v2) const - { + T triple(const Vector4D& v1, const Vector4D& v2) const { return m_floats[0] * (v1.m_floats[1] * v2.m_floats[2] - v1.m_floats[2] * v2.m_floats[1]) + m_floats[1] * (v1.m_floats[2] * v2.m_floats[0] - v1.m_floats[0] * v2.m_floats[2]) + m_floats[2] * (v1.m_floats[0] * v2.m_floats[1] - v1.m_floats[1] * v2.m_floats[0]); @@ -279,8 +264,7 @@ namespace etk { * Note return values are 0,1,2 for x, y, or z */ /* - int32_t minAxis() const - { + int32_t minAxis() const { return m_floats[0] < m_floats[1] ? (m_floats[0] & v0, const Vector4D& v1, T rt) - { + void setInterpolate3(const Vector4D& v0, const Vector4D& v1, T rt) { btScalar s = 1 - rt; m_floats[0] = s * v0.m_floats[0] + rt * v1.m_floats[0]; m_floats[1] = s * v0.m_floats[1] + rt * v1.m_floats[1]; @@ -321,8 +301,7 @@ namespace etk { * @param t The ration of this to v (t = 0 => return this, t=1 => return other) */ /* - Vector3D lerp(const Vector4D& v, const btScalar& t) const - { + Vector3D lerp(const Vector4D& v, const btScalar& t) const { return Vector3D(m_floats[0] + (v.m_floats[0] - m_floats[0]) * t, m_floats[1] + (v.m_floats[1] - m_floats[1]) * t, m_floats[2] + (v.m_floats[2] - m_floats[2]) * t, @@ -333,16 +312,14 @@ namespace etk { * @brief Elementwise multiply this vector by the other * @param v The other vector */ - Vector4D& operator*=(const Vector4D& v) - { + Vector4D& operator*=(const Vector4D& v) { m_floats[0] *= v.m_floats[0]; m_floats[1] *= v.m_floats[1]; m_floats[2] *= v.m_floats[2]; m_floats[3] *= v.m_floats[3]; return *this; } - Vector4D operator*(const Vector4D& v) - { + Vector4D operator*(const Vector4D& v) { return Vector4D(m_floats[0] * v.m_floats[0], m_floats[1] * v.m_floats[1], m_floats[2] * v.m_floats[2], @@ -401,16 +378,14 @@ namespace etk { operator T *() { return &m_floats[0]; } operator const T *() const { return &m_floats[0]; } - bool operator==(const Vector4D& other) const - { + bool operator==(const Vector4D& other) const { return ( (m_floats[3]==other.m_floats[3]) && (m_floats[2]==other.m_floats[2]) && (m_floats[1]==other.m_floats[1]) && (m_floats[0]==other.m_floats[0])); } - bool operator!=(const Vector4D& other) const - { + bool operator!=(const Vector4D& other) const { return ( (m_floats[3]!=other.m_floats[3]) || (m_floats[2]!=other.m_floats[2]) || (m_floats[1]!=other.m_floats[1]) @@ -421,8 +396,7 @@ namespace etk { * @brief Set each element to the max of the current values and the values of another btVector3 * @param other The other btVector3 to compare with */ - void setMax(const Vector4D& other) - { + void setMax(const Vector4D& other) { btSetMax(m_floats[0], other.m_floats[0]); btSetMax(m_floats[1], other.m_floats[1]); btSetMax(m_floats[2], other.m_floats[2]); @@ -433,36 +407,31 @@ namespace etk { * @brief Set each element to the min of the current values and the values of another btVector3 * @param other The other btVector3 to compare with */ - void setMin(const Vector4D& other) - { + void setMin(const Vector4D& other) { btSetMin(m_floats[0], other.m_floats[0]); btSetMin(m_floats[1], other.m_floats[1]); btSetMin(m_floats[2], other.m_floats[2]); btSetMin(m_floats[3], other.m_floats[3]); } - void setValue(const T& _x, const T& _y, const T& _z, const T& _w) - { + void setValue(const T& _x, const T& _y, const T& _z, const T& _w) { m_floats[0]=_x; m_floats[1]=_y; m_floats[2]=_z; m_floats[3]=_w; } /* - void getSkewSymmetricMatrix(Vector3D* v0,Vector3D* v1,Vector3D* v2) const - { + void getSkewSymmetricMatrix(Vector3D* v0,Vector3D* v1,Vector3D* v2) const { v0->setValue(0. ,-z() ,y()); v1->setValue(z() ,0. ,-x()); v2->setValue(-y() ,x() ,0.); } */ - void setZero() - { + void setZero() { setValue(0,0,0,0); } - bool isZero() const - { + bool isZero() const { return m_floats[0] == 0 && m_floats[1] == 0 && m_floats[2] == 0 && m_floats[3] == 0; } };