|
@@ -1,7 +1,4 @@
|
|
|
-#include "Common.inl.h"
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-namespace m {
|
|
|
|
|
|
|
+#include "MathCommonSrc.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
//==============================================================================
|
|
//==============================================================================
|
|
@@ -24,6 +21,7 @@ inline Mat4::Mat4(const Mat4& b)
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// float
|
|
// float
|
|
|
inline Mat4::Mat4(const float f)
|
|
inline Mat4::Mat4(const float f)
|
|
|
{
|
|
{
|
|
@@ -40,6 +38,7 @@ inline Mat4::Mat4(const float f)
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// float[]
|
|
// float[]
|
|
|
inline Mat4::Mat4(const float arr_[])
|
|
inline Mat4::Mat4(const float arr_[])
|
|
|
{
|
|
{
|
|
@@ -49,10 +48,14 @@ inline Mat4::Mat4(const float arr_[])
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// many floats
|
|
// many floats
|
|
|
-inline Mat4::Mat4(float m00, float m01, float m02, float m03, float m10,
|
|
|
|
|
- float m11, float m12, float m13, float m20, float m21, float m22,
|
|
|
|
|
- float m23, float m30, float m31, float m32, float m33)
|
|
|
|
|
|
|
+inline Mat4::Mat4(const float m00, const float m01, const float m02,
|
|
|
|
|
+ const float m03, const float m10, const float m11,
|
|
|
|
|
+ const float m12, const float m13, const float m20,
|
|
|
|
|
+ const float m21, const float m22, const float m23,
|
|
|
|
|
+ const float m30, const float m31, const float m32,
|
|
|
|
|
+ const float m33)
|
|
|
{
|
|
{
|
|
|
(*this)(0, 0) = m00;
|
|
(*this)(0, 0) = m00;
|
|
|
(*this)(0, 1) = m01;
|
|
(*this)(0, 1) = m01;
|
|
@@ -72,6 +75,7 @@ inline Mat4::Mat4(float m00, float m01, float m02, float m03, float m10,
|
|
|
(*this)(3, 3) = m33;
|
|
(*this)(3, 3) = m33;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// Mat3
|
|
// Mat3
|
|
|
inline Mat4::Mat4(const Mat3& m3)
|
|
inline Mat4::Mat4(const Mat3& m3)
|
|
|
{
|
|
{
|
|
@@ -89,6 +93,7 @@ inline Mat4::Mat4(const Mat3& m3)
|
|
|
(*this)(3, 3) = 1.0;
|
|
(*this)(3, 3) = 1.0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// Vec3
|
|
// Vec3
|
|
|
inline Mat4::Mat4(const Vec3& v)
|
|
inline Mat4::Mat4(const Vec3& v)
|
|
|
{
|
|
{
|
|
@@ -110,6 +115,7 @@ inline Mat4::Mat4(const Vec3& v)
|
|
|
(*this)(3, 3) = 1.0;
|
|
(*this)(3, 3) = 1.0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// vec4
|
|
// vec4
|
|
|
inline Mat4::Mat4(const Vec4& v)
|
|
inline Mat4::Mat4(const Vec4& v)
|
|
|
{
|
|
{
|
|
@@ -131,6 +137,7 @@ inline Mat4::Mat4(const Vec4& v)
|
|
|
(*this)(3, 3) = v.w();
|
|
(*this)(3, 3) = v.w();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// Vec3, Mat3
|
|
// Vec3, Mat3
|
|
|
inline Mat4::Mat4(const Vec3& transl, const Mat3& rot)
|
|
inline Mat4::Mat4(const Vec3& transl, const Mat3& rot)
|
|
|
{
|
|
{
|
|
@@ -140,10 +147,11 @@ inline Mat4::Mat4(const Vec3& transl, const Mat3& rot)
|
|
|
(*this)(3, 3) = 1.0;
|
|
(*this)(3, 3) = 1.0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// Vec3, Mat3, float
|
|
// Vec3, Mat3, float
|
|
|
-inline Mat4::Mat4(const Vec3& translate, const Mat3& rotate, float scale)
|
|
|
|
|
|
|
+inline Mat4::Mat4(const Vec3& translate, const Mat3& rotate, const float scale)
|
|
|
{
|
|
{
|
|
|
- if(!isZero(scale - 1.0))
|
|
|
|
|
|
|
+ if(!Math::isZero(scale - 1.0))
|
|
|
{
|
|
{
|
|
|
setRotationPart(rotate * scale);
|
|
setRotationPart(rotate * scale);
|
|
|
}
|
|
}
|
|
@@ -158,6 +166,7 @@ inline Mat4::Mat4(const Vec3& translate, const Mat3& rotate, float scale)
|
|
|
(*this)(3, 3) = 1.0;
|
|
(*this)(3, 3) = 1.0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// Transform
|
|
// Transform
|
|
|
inline Mat4::Mat4(const Transform& t)
|
|
inline Mat4::Mat4(const Transform& t)
|
|
|
{
|
|
{
|
|
@@ -169,33 +178,37 @@ inline Mat4::Mat4(const Transform& t)
|
|
|
// Accessors =
|
|
// Accessors =
|
|
|
//==============================================================================
|
|
//==============================================================================
|
|
|
|
|
|
|
|
-inline float& Mat4::operator()(const uint i, const uint j)
|
|
|
|
|
|
|
+inline float& Mat4::operator()(const size_t i, const size_t j)
|
|
|
{
|
|
{
|
|
|
return arr2[i][j];
|
|
return arr2[i][j];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-inline const float& Mat4::operator()(const uint i, const uint j) const
|
|
|
|
|
|
|
+
|
|
|
|
|
+inline const float& Mat4::operator()(const size_t i, const size_t j) const
|
|
|
{
|
|
{
|
|
|
return arr2[i][j];
|
|
return arr2[i][j];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-inline float& Mat4::operator[](const uint i)
|
|
|
|
|
|
|
+
|
|
|
|
|
+inline float& Mat4::operator[](const size_t i)
|
|
|
{
|
|
{
|
|
|
return arr1[i];
|
|
return arr1[i];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-inline const float& Mat4::operator[](const uint i) const
|
|
|
|
|
|
|
+
|
|
|
|
|
+inline const float& Mat4::operator[](const size_t i) const
|
|
|
{
|
|
{
|
|
|
return arr1[i];
|
|
return arr1[i];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
#if defined(MATH_INTEL_SIMD)
|
|
#if defined(MATH_INTEL_SIMD)
|
|
|
-inline const __m128& Mat4::getMm(uint i) const
|
|
|
|
|
|
|
+inline const __m128& Mat4::getMm(const size_t i) const
|
|
|
{
|
|
{
|
|
|
return arrMm[i];
|
|
return arrMm[i];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-inline __m128& Mat4::getMm(uint i)
|
|
|
|
|
|
|
+inline __m128& Mat4::getMm(const size_t i)
|
|
|
{
|
|
{
|
|
|
return arrMm[i];
|
|
return arrMm[i];
|
|
|
}
|
|
}
|
|
@@ -222,6 +235,7 @@ inline Mat4& Mat4::operator=(const Mat4& b)
|
|
|
return (*this);
|
|
return (*this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// +
|
|
// +
|
|
|
inline Mat4 Mat4::operator+(const Mat4& b) const
|
|
inline Mat4 Mat4::operator+(const Mat4& b) const
|
|
|
{
|
|
{
|
|
@@ -240,6 +254,7 @@ inline Mat4 Mat4::operator+(const Mat4& b) const
|
|
|
return c;
|
|
return c;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// +=
|
|
// +=
|
|
|
inline Mat4& Mat4::operator+=(const Mat4& b)
|
|
inline Mat4& Mat4::operator+=(const Mat4& b)
|
|
|
{
|
|
{
|
|
@@ -257,6 +272,7 @@ inline Mat4& Mat4::operator+=(const Mat4& b)
|
|
|
return (*this);
|
|
return (*this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// -
|
|
// -
|
|
|
inline Mat4 Mat4::operator-(const Mat4& b) const
|
|
inline Mat4 Mat4::operator-(const Mat4& b) const
|
|
|
{
|
|
{
|
|
@@ -275,6 +291,7 @@ inline Mat4 Mat4::operator-(const Mat4& b) const
|
|
|
return c;
|
|
return c;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// -=
|
|
// -=
|
|
|
inline Mat4& Mat4::operator-=(const Mat4& b)
|
|
inline Mat4& Mat4::operator-=(const Mat4& b)
|
|
|
{
|
|
{
|
|
@@ -292,6 +309,7 @@ inline Mat4& Mat4::operator-=(const Mat4& b)
|
|
|
return (*this);
|
|
return (*this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// *
|
|
// *
|
|
|
inline Mat4 Mat4::operator*(const Mat4& b) const
|
|
inline Mat4 Mat4::operator*(const Mat4& b) const
|
|
|
{
|
|
{
|
|
@@ -319,6 +337,7 @@ inline Mat4 Mat4::operator*(const Mat4& b) const
|
|
|
return c;
|
|
return c;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// *=
|
|
// *=
|
|
|
inline Mat4& Mat4::operator*=(const Mat4& b)
|
|
inline Mat4& Mat4::operator*=(const Mat4& b)
|
|
|
{
|
|
{
|
|
@@ -326,12 +345,13 @@ inline Mat4& Mat4::operator*=(const Mat4& b)
|
|
|
return (*this);
|
|
return (*this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// ==
|
|
// ==
|
|
|
inline bool Mat4::operator==(const Mat4& b) const
|
|
inline bool Mat4::operator==(const Mat4& b) const
|
|
|
{
|
|
{
|
|
|
for(int i = 0; i < 16; i++)
|
|
for(int i = 0; i < 16; i++)
|
|
|
{
|
|
{
|
|
|
- if(!isZero((*this)[i] - b[i]))
|
|
|
|
|
|
|
+ if(!Math::isZero((*this)[i] - b[i]))
|
|
|
{
|
|
{
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -339,12 +359,13 @@ inline bool Mat4::operator==(const Mat4& b) const
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// !=
|
|
// !=
|
|
|
inline bool Mat4::operator!=(const Mat4& b) const
|
|
inline bool Mat4::operator!=(const Mat4& b) const
|
|
|
{
|
|
{
|
|
|
for(int i = 0; i < 16; i++)
|
|
for(int i = 0; i < 16; i++)
|
|
|
{
|
|
{
|
|
|
- if(!isZero((*this)[i]-b[i]))
|
|
|
|
|
|
|
+ if(!Math::isZero((*this)[i]-b[i]))
|
|
|
{
|
|
{
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -352,12 +373,13 @@ inline bool Mat4::operator!=(const Mat4& b) const
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
//==============================================================================
|
|
//==============================================================================
|
|
|
// Operators with float =
|
|
// Operators with float =
|
|
|
//==============================================================================
|
|
//==============================================================================
|
|
|
|
|
|
|
|
// 4x4 + float
|
|
// 4x4 + float
|
|
|
-inline Mat4 Mat4::operator+(float f) const
|
|
|
|
|
|
|
+inline Mat4 Mat4::operator+(const float f) const
|
|
|
{
|
|
{
|
|
|
Mat4 c;
|
|
Mat4 c;
|
|
|
#if defined(MATH_INTEL_SIMD)
|
|
#if defined(MATH_INTEL_SIMD)
|
|
@@ -376,14 +398,9 @@ inline Mat4 Mat4::operator+(float f) const
|
|
|
return c;
|
|
return c;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// float + 4x4
|
|
|
|
|
-inline Mat4 operator+(float f, const Mat4& m4)
|
|
|
|
|
-{
|
|
|
|
|
- return m4 + f;
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
// 4x4 += float
|
|
// 4x4 += float
|
|
|
-inline Mat4& Mat4::operator+=(float f)
|
|
|
|
|
|
|
+inline Mat4& Mat4::operator+=(const float f)
|
|
|
{
|
|
{
|
|
|
#if defined(MATH_INTEL_SIMD)
|
|
#if defined(MATH_INTEL_SIMD)
|
|
|
__m128 mm;
|
|
__m128 mm;
|
|
@@ -401,8 +418,9 @@ inline Mat4& Mat4::operator+=(float f)
|
|
|
return (*this);
|
|
return (*this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// 4x4 - float
|
|
// 4x4 - float
|
|
|
-inline Mat4 Mat4::operator-(float f) const
|
|
|
|
|
|
|
+inline Mat4 Mat4::operator-(const float f) const
|
|
|
{
|
|
{
|
|
|
Mat4 r;
|
|
Mat4 r;
|
|
|
#if defined(MATH_INTEL_SIMD)
|
|
#if defined(MATH_INTEL_SIMD)
|
|
@@ -421,28 +439,9 @@ inline Mat4 Mat4::operator-(float f) const
|
|
|
return r;
|
|
return r;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// float - 4x4
|
|
|
|
|
-inline Mat4 operator-(float f, const Mat4& m4)
|
|
|
|
|
-{
|
|
|
|
|
- Mat4 r;
|
|
|
|
|
-#if defined(MATH_INTEL_SIMD)
|
|
|
|
|
- __m128 mm;
|
|
|
|
|
- mm = _mm_set1_ps(f);
|
|
|
|
|
- for(int i = 0; i < 4; i++)
|
|
|
|
|
- {
|
|
|
|
|
- r.arrMm[i] = _mm_sub_ps(mm, m4.arrMm[i]);
|
|
|
|
|
- }
|
|
|
|
|
-#else
|
|
|
|
|
- for(int i = 0; i < 16; i++)
|
|
|
|
|
- {
|
|
|
|
|
- r[i] = f - m4[i];
|
|
|
|
|
- }
|
|
|
|
|
-#endif
|
|
|
|
|
- return r;
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
// 4x4 -= float
|
|
// 4x4 -= float
|
|
|
-inline Mat4& Mat4::operator-=(float f)
|
|
|
|
|
|
|
+inline Mat4& Mat4::operator-=(const float f)
|
|
|
{
|
|
{
|
|
|
#if defined(MATH_INTEL_SIMD)
|
|
#if defined(MATH_INTEL_SIMD)
|
|
|
__m128 mm;
|
|
__m128 mm;
|
|
@@ -460,8 +459,9 @@ inline Mat4& Mat4::operator-=(float f)
|
|
|
return (*this);
|
|
return (*this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// 4x4 * float
|
|
// 4x4 * float
|
|
|
-inline Mat4 Mat4::operator*(float f) const
|
|
|
|
|
|
|
+inline Mat4 Mat4::operator*(const float f) const
|
|
|
{
|
|
{
|
|
|
Mat4 r;
|
|
Mat4 r;
|
|
|
#if defined(MATH_INTEL_SIMD)
|
|
#if defined(MATH_INTEL_SIMD)
|
|
@@ -480,14 +480,9 @@ inline Mat4 Mat4::operator*(float f) const
|
|
|
return r;
|
|
return r;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// float * 4x4
|
|
|
|
|
-inline Mat4 operator*(float f, const Mat4& m4)
|
|
|
|
|
-{
|
|
|
|
|
- return m4 * f;
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
// 4x4 *= float
|
|
// 4x4 *= float
|
|
|
-inline Mat4& Mat4::operator*=(float f)
|
|
|
|
|
|
|
+inline Mat4& Mat4::operator*=(const float f)
|
|
|
{
|
|
{
|
|
|
#if defined(MATH_INTEL_SIMD)
|
|
#if defined(MATH_INTEL_SIMD)
|
|
|
__m128 mm;
|
|
__m128 mm;
|
|
@@ -505,8 +500,9 @@ inline Mat4& Mat4::operator*=(float f)
|
|
|
return (*this);
|
|
return (*this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// 4x4 / float
|
|
// 4x4 / float
|
|
|
-inline Mat4 Mat4::operator/(float f) const
|
|
|
|
|
|
|
+inline Mat4 Mat4::operator/(const float f) const
|
|
|
{
|
|
{
|
|
|
Mat4 r;
|
|
Mat4 r;
|
|
|
#if defined(MATH_INTEL_SIMD)
|
|
#if defined(MATH_INTEL_SIMD)
|
|
@@ -525,28 +521,9 @@ inline Mat4 Mat4::operator/(float f) const
|
|
|
return r;
|
|
return r;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// float / 4x4
|
|
|
|
|
-inline Mat4 operator/(float f, const Mat4& m4)
|
|
|
|
|
-{
|
|
|
|
|
- Mat4 r;
|
|
|
|
|
-#if defined(MATH_INTEL_SIMD)
|
|
|
|
|
- __m128 mm;
|
|
|
|
|
- mm = _mm_set1_ps(f);
|
|
|
|
|
- for(int i = 0; i < 4; i++)
|
|
|
|
|
- {
|
|
|
|
|
- r.arrMm[i] = _mm_div_ps(mm, m4.arrMm[i]);
|
|
|
|
|
- }
|
|
|
|
|
-#else
|
|
|
|
|
- for(int i = 0; i < 16; i++)
|
|
|
|
|
- {
|
|
|
|
|
- r[i] = f / m4[i];
|
|
|
|
|
- }
|
|
|
|
|
-#endif
|
|
|
|
|
- return r;
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
// 4x4 /= float
|
|
// 4x4 /= float
|
|
|
-inline Mat4& Mat4::operator/=(float f)
|
|
|
|
|
|
|
+inline Mat4& Mat4::operator/=(const float f)
|
|
|
{
|
|
{
|
|
|
#if defined(MATH_INTEL_SIMD)
|
|
#if defined(MATH_INTEL_SIMD)
|
|
|
__m128 mm;
|
|
__m128 mm;
|
|
@@ -593,7 +570,7 @@ inline Vec4 Mat4::operator*(const Vec4& b) const
|
|
|
|
|
|
|
|
|
|
|
|
|
//==============================================================================
|
|
//==============================================================================
|
|
|
-// Misc methods =
|
|
|
|
|
|
|
+// Other =
|
|
|
//==============================================================================
|
|
//==============================================================================
|
|
|
|
|
|
|
|
// setRows
|
|
// setRows
|
|
@@ -625,8 +602,9 @@ inline void Mat4::setRows(const Vec4& a, const Vec4& b, const Vec4& c,
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// setRow
|
|
// setRow
|
|
|
-inline void Mat4::setRow(uint i, const Vec4& v)
|
|
|
|
|
|
|
+inline void Mat4::setRow(const size_t i, const Vec4& v)
|
|
|
{
|
|
{
|
|
|
#if defined(MATH_INTEL_SIMD)
|
|
#if defined(MATH_INTEL_SIMD)
|
|
|
arrMm[i] = v.getMm();
|
|
arrMm[i] = v.getMm();
|
|
@@ -638,6 +616,7 @@ inline void Mat4::setRow(uint i, const Vec4& v)
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// setColumns
|
|
// setColumns
|
|
|
inline void Mat4::setColumns(const Vec4& a, const Vec4& b, const Vec4& c,
|
|
inline void Mat4::setColumns(const Vec4& a, const Vec4& b, const Vec4& c,
|
|
|
const Vec4& d)
|
|
const Vec4& d)
|
|
@@ -660,8 +639,9 @@ inline void Mat4::setColumns(const Vec4& a, const Vec4& b, const Vec4& c,
|
|
|
(*this)(3, 3) = d.w();
|
|
(*this)(3, 3) = d.w();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// setColumn
|
|
// setColumn
|
|
|
-inline void Mat4::setColumn(uint i, const Vec4& v)
|
|
|
|
|
|
|
+inline void Mat4::setColumn(const size_t i, const Vec4& v)
|
|
|
{
|
|
{
|
|
|
(*this)(0, i) = v.x();
|
|
(*this)(0, i) = v.x();
|
|
|
(*this)(1, i) = v.y();
|
|
(*this)(1, i) = v.y();
|
|
@@ -669,6 +649,7 @@ inline void Mat4::setColumn(uint i, const Vec4& v)
|
|
|
(*this)(3, i) = v.w();
|
|
(*this)(3, i) = v.w();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// transpose
|
|
// transpose
|
|
|
inline void Mat4::transpose()
|
|
inline void Mat4::transpose()
|
|
|
{
|
|
{
|
|
@@ -696,6 +677,7 @@ inline void Mat4::transpose()
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// getTransposed
|
|
// getTransposed
|
|
|
inline Mat4 Mat4::getTransposed() const
|
|
inline Mat4 Mat4::getTransposed() const
|
|
|
{
|
|
{
|
|
@@ -719,6 +701,7 @@ inline Mat4 Mat4::getTransposed() const
|
|
|
return m4;
|
|
return m4;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// setRotationPart
|
|
// setRotationPart
|
|
|
inline void Mat4::setRotationPart(const Mat3& m3)
|
|
inline void Mat4::setRotationPart(const Mat3& m3)
|
|
|
{
|
|
{
|
|
@@ -733,6 +716,7 @@ inline void Mat4::setRotationPart(const Mat3& m3)
|
|
|
(*this)(2, 2) = m3(2, 2);
|
|
(*this)(2, 2) = m3(2, 2);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// getRotationPart
|
|
// getRotationPart
|
|
|
inline Mat3 Mat4::getRotationPart() const
|
|
inline Mat3 Mat4::getRotationPart() const
|
|
|
{
|
|
{
|
|
@@ -749,6 +733,7 @@ inline Mat3 Mat4::getRotationPart() const
|
|
|
return m3;
|
|
return m3;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// setTranslationPart
|
|
// setTranslationPart
|
|
|
inline void Mat4::setTranslationPart(const Vec4& v)
|
|
inline void Mat4::setTranslationPart(const Vec4& v)
|
|
|
{
|
|
{
|
|
@@ -758,6 +743,7 @@ inline void Mat4::setTranslationPart(const Vec4& v)
|
|
|
(*this)(3, 3) = v.w();
|
|
(*this)(3, 3) = v.w();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// setTranslationPart
|
|
// setTranslationPart
|
|
|
inline void Mat4::setTranslationPart(const Vec3& v)
|
|
inline void Mat4::setTranslationPart(const Vec3& v)
|
|
|
{
|
|
{
|
|
@@ -766,12 +752,14 @@ inline void Mat4::setTranslationPart(const Vec3& v)
|
|
|
(*this)(2, 3) = v.z();
|
|
(*this)(2, 3) = v.z();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// getTranslationPart
|
|
// getTranslationPart
|
|
|
inline Vec3 Mat4::getTranslationPart() const
|
|
inline Vec3 Mat4::getTranslationPart() const
|
|
|
{
|
|
{
|
|
|
return Vec3((*this)(0, 3), (*this)(1, 3), (*this)(2, 3));
|
|
return Vec3((*this)(0, 3), (*this)(1, 3), (*this)(2, 3));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// getIdentity
|
|
// getIdentity
|
|
|
inline const Mat4& Mat4::getIdentity()
|
|
inline const Mat4& Mat4::getIdentity()
|
|
|
{
|
|
{
|
|
@@ -780,6 +768,7 @@ inline const Mat4& Mat4::getIdentity()
|
|
|
return ident;
|
|
return ident;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// getZero
|
|
// getZero
|
|
|
inline const Mat4& Mat4::getZero()
|
|
inline const Mat4& Mat4::getZero()
|
|
|
{
|
|
{
|
|
@@ -787,6 +776,7 @@ inline const Mat4& Mat4::getZero()
|
|
|
return zero;
|
|
return zero;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// Determinant
|
|
// Determinant
|
|
|
inline float Mat4::getDet() const
|
|
inline float Mat4::getDet() const
|
|
|
{
|
|
{
|
|
@@ -817,93 +807,10 @@ inline float Mat4::getDet() const
|
|
|
t(0, 0) * t(1, 1) * t(2, 2) * t(3, 3);
|
|
t(0, 0) * t(1, 1) * t(2, 2) * t(3, 3);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// getInverse
|
|
// getInverse
|
|
|
inline Mat4 Mat4::getInverse() const
|
|
inline Mat4 Mat4::getInverse() const
|
|
|
{
|
|
{
|
|
|
- /// @todo test this
|
|
|
|
|
-/*#if !defined(MATH_INTEL_SIMD)
|
|
|
|
|
- Mat4 r((*this));
|
|
|
|
|
- __m128 minor0, minor1, minor2, minor3;
|
|
|
|
|
- __m128 det, tmp1;
|
|
|
|
|
-
|
|
|
|
|
- // Transpose
|
|
|
|
|
- r.transpose();
|
|
|
|
|
-
|
|
|
|
|
- // Calc coeffs
|
|
|
|
|
- tmp1 = _mm_mul_ps(r.arrMm[2], r.arrMm[3]);
|
|
|
|
|
- tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0xB1);
|
|
|
|
|
- minor0 = _mm_mul_ps(r.arrMm[1], tmp1);
|
|
|
|
|
- minor1 = _mm_mul_ps(r.arrMm[0], tmp1);
|
|
|
|
|
- tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0x4E);
|
|
|
|
|
- minor0 = _mm_sub_ps(_mm_mul_ps(r.arrMm[1], tmp1), minor0);
|
|
|
|
|
- minor1 = _mm_sub_ps(_mm_mul_ps(r.arrMm[0], tmp1), minor1);
|
|
|
|
|
- minor1 = _mm_shuffle_ps(minor1, minor1, 0x4E);
|
|
|
|
|
-
|
|
|
|
|
- tmp1 = _mm_mul_ps(r.arrMm[1], r.arrMm[2]);
|
|
|
|
|
- tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0xB1);
|
|
|
|
|
- minor0 = _mm_add_ps(_mm_mul_ps(r.arrMm[3], tmp1), minor0);
|
|
|
|
|
- minor3 = _mm_mul_ps(r.arrMm[0], tmp1);
|
|
|
|
|
- tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0x4E);
|
|
|
|
|
- minor0 = _mm_sub_ps(minor0, _mm_mul_ps(r.arrMm[3], tmp1));
|
|
|
|
|
- minor3 = _mm_sub_ps(_mm_mul_ps(r.arrMm[0], tmp1), minor3);
|
|
|
|
|
- minor3 = _mm_shuffle_ps(minor3, minor3, 0x4E);
|
|
|
|
|
-
|
|
|
|
|
- tmp1 = _mm_mul_ps(_mm_shuffle_ps(r.arrMm[1], r.arrMm[1], 0x4E),
|
|
|
|
|
- r.arrMm[3]);
|
|
|
|
|
- tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0xB1);
|
|
|
|
|
- r.arrMm[2] = _mm_shuffle_ps(r.arrMm[2], r.arrMm[2], 0x4E);
|
|
|
|
|
- minor0 = _mm_add_ps(_mm_mul_ps(r.arrMm[2], tmp1), minor0);
|
|
|
|
|
- minor2 = _mm_mul_ps(r.arrMm[0], tmp1);
|
|
|
|
|
- tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0x4E);
|
|
|
|
|
- minor0 = _mm_sub_ps(minor0, _mm_mul_ps(r.arrMm[2], tmp1));
|
|
|
|
|
- minor2 = _mm_sub_ps(_mm_mul_ps(r.arrMm[0], tmp1), minor2);
|
|
|
|
|
- minor2 = _mm_shuffle_ps(minor2, minor2, 0x4E);
|
|
|
|
|
-
|
|
|
|
|
- tmp1 = _mm_mul_ps(r.arrMm[0], r.arrMm[1]);
|
|
|
|
|
- tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0xB1);
|
|
|
|
|
- minor2 = _mm_add_ps(_mm_mul_ps(r.arrMm[3], tmp1), minor2);
|
|
|
|
|
- minor3 = _mm_sub_ps(_mm_mul_ps(r.arrMm[2], tmp1), minor3);
|
|
|
|
|
- tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0x4E);
|
|
|
|
|
- minor2 = _mm_sub_ps(_mm_mul_ps(r.arrMm[3], tmp1), minor2);
|
|
|
|
|
- minor3 = _mm_sub_ps(minor3, _mm_mul_ps(r.arrMm[2], tmp1));
|
|
|
|
|
-
|
|
|
|
|
- tmp1 = _mm_mul_ps(r.arrMm[0], r.arrMm[3]);
|
|
|
|
|
- tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0xB1);
|
|
|
|
|
- minor1 = _mm_sub_ps(minor1, _mm_mul_ps(r.arrMm[2], tmp1));
|
|
|
|
|
- minor2 = _mm_add_ps(_mm_mul_ps(r.arrMm[1], tmp1), minor2);
|
|
|
|
|
- tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0x4E);
|
|
|
|
|
- minor1 = _mm_add_ps(_mm_mul_ps(r.arrMm[2], tmp1), minor1);
|
|
|
|
|
- minor2 = _mm_sub_ps(minor2, _mm_mul_ps(r.arrMm[1], tmp1));
|
|
|
|
|
-
|
|
|
|
|
- tmp1 = _mm_mul_ps(r.arrMm[0], r.arrMm[2]);
|
|
|
|
|
- tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0xB1);
|
|
|
|
|
- minor1 = _mm_add_ps(_mm_mul_ps(r.arrMm[3], tmp1), minor1);
|
|
|
|
|
- minor3 = _mm_sub_ps(minor3, _mm_mul_ps(r.arrMm[1], tmp1));
|
|
|
|
|
- tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0x4E);
|
|
|
|
|
- minor1 = _mm_sub_ps(minor1, _mm_mul_ps(r.arrMm[3], tmp1));
|
|
|
|
|
- minor3 = _mm_add_ps(_mm_mul_ps(r.arrMm[1], tmp1), minor3);
|
|
|
|
|
-
|
|
|
|
|
- // 1 / det
|
|
|
|
|
- det = _mm_mul_ps(r.arrMm[0], minor0);
|
|
|
|
|
- det = _mm_add_ps(_mm_shuffle_ps(det, det, 0x4E), det);
|
|
|
|
|
- det = _mm_add_ss(_mm_shuffle_ps(det, det, 0xB1), det);
|
|
|
|
|
- tmp1 = _mm_rcp_ss(det);
|
|
|
|
|
- det = _mm_sub_ss(_mm_add_ss(tmp1, tmp1),
|
|
|
|
|
- _mm_mul_ss(det, _mm_mul_ss(tmp1, tmp1)));
|
|
|
|
|
- det = _mm_shuffle_ps(det, det, 0x00);
|
|
|
|
|
-
|
|
|
|
|
- // Mul and store
|
|
|
|
|
- minor0 = _mm_mul_ps(det, minor0);
|
|
|
|
|
- r.arrMm[0] = minor0;
|
|
|
|
|
- minor1 = _mm_mul_ps(det, minor1);
|
|
|
|
|
- r.arrMm[1] = minor1;
|
|
|
|
|
- minor2 = _mm_mul_ps(det, minor2);
|
|
|
|
|
- r.arrMm[2] = minor2;
|
|
|
|
|
- minor3 = _mm_mul_ps(det, minor3);
|
|
|
|
|
- r.arrMm[3] = minor3;
|
|
|
|
|
-
|
|
|
|
|
- return r;
|
|
|
|
|
-#else*/
|
|
|
|
|
float tmp[12];
|
|
float tmp[12];
|
|
|
float det;
|
|
float det;
|
|
|
const Mat4& in = (*this);
|
|
const Mat4& in = (*this);
|
|
@@ -972,13 +879,13 @@ inline Mat4 Mat4::getInverse() const
|
|
|
det = (*this)(0, 0) * m4(0, 0) + (*this)(1, 0) * m4(0, 1) +
|
|
det = (*this)(0, 0) * m4(0, 0) + (*this)(1, 0) * m4(0, 1) +
|
|
|
(*this)(2, 0) * m4(0, 2) + (*this)(3, 0) * m4(0, 3);
|
|
(*this)(2, 0) * m4(0, 2) + (*this)(3, 0) * m4(0, 3);
|
|
|
|
|
|
|
|
- ASSERT(!isZero(det)); // Cannot invert, det == 0
|
|
|
|
|
|
|
+ ASSERT(!Math::isZero(det)); // Cannot invert, det == 0
|
|
|
det = 1.0 / det;
|
|
det = 1.0 / det;
|
|
|
m4 *= det;
|
|
m4 *= det;
|
|
|
return m4;
|
|
return m4;
|
|
|
-//#endif
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// invert
|
|
// invert
|
|
|
inline void Mat4::invert()
|
|
inline void Mat4::invert()
|
|
|
{
|
|
{
|
|
@@ -995,18 +902,21 @@ inline Mat4 Mat4::getInverseTransformation() const
|
|
|
return Mat4(invertedTsl, invertedRot);
|
|
return Mat4(invertedTsl, invertedRot);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// lerp
|
|
// lerp
|
|
|
-inline Mat4 Mat4::lerp(const Mat4& b, float t) const
|
|
|
|
|
|
|
+inline Mat4 Mat4::lerp(const Mat4& b, const float t) const
|
|
|
{
|
|
{
|
|
|
return ((*this) * (1.0 - t)) + (b * t);
|
|
return ((*this) * (1.0 - t)) + (b * t);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// setIdentity
|
|
// setIdentity
|
|
|
inline void Mat4::setIdentity()
|
|
inline void Mat4::setIdentity()
|
|
|
{
|
|
{
|
|
|
(*this) = getIdentity();
|
|
(*this) = getIdentity();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// combineTransformations
|
|
// combineTransformations
|
|
|
inline Mat4 Mat4::combineTransformations(const Mat4& m0, const Mat4& m1)
|
|
inline Mat4 Mat4::combineTransformations(const Mat4& m0, const Mat4& m1)
|
|
|
{
|
|
{
|
|
@@ -1021,8 +931,8 @@ inline Mat4 Mat4::combineTransformations(const Mat4& m0, const Mat4& m1)
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
// one of the 2 mat4 doesnt represent transformation
|
|
// one of the 2 mat4 doesnt represent transformation
|
|
|
- ASSERT(isZero(m0(3, 0) + m0(3, 1) + m0(3, 2) + m0(3, 3)-1.0) &&
|
|
|
|
|
- isZero(m1(3, 0) + m1(3, 1) + m1(3, 2) + m1(3, 3)-1.0));
|
|
|
|
|
|
|
+ ASSERT(Math::isZero(m0(3, 0) + m0(3, 1) + m0(3, 2) + m0(3, 3)-1.0) &&
|
|
|
|
|
+ Math::isZero(m1(3, 0) + m1(3, 1) + m1(3, 2) + m1(3, 3)-1.0));
|
|
|
|
|
|
|
|
Mat4 m4;
|
|
Mat4 m4;
|
|
|
|
|
|
|
@@ -1053,8 +963,66 @@ inline Mat4 Mat4::combineTransformations(const Mat4& m0, const Mat4& m1)
|
|
|
|
|
|
|
|
|
|
|
|
|
//==============================================================================
|
|
//==============================================================================
|
|
|
-// Print =
|
|
|
|
|
|
|
+// Friends =
|
|
|
//==============================================================================
|
|
//==============================================================================
|
|
|
|
|
+
|
|
|
|
|
+// float + 4x4
|
|
|
|
|
+inline Mat4 operator+(const float f, const Mat4& m4)
|
|
|
|
|
+{
|
|
|
|
|
+ return m4 + f;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+// float - 4x4
|
|
|
|
|
+inline Mat4 operator-(const float f, const Mat4& m4)
|
|
|
|
|
+{
|
|
|
|
|
+ Mat4 r;
|
|
|
|
|
+#if defined(MATH_INTEL_SIMD)
|
|
|
|
|
+ __m128 mm;
|
|
|
|
|
+ mm = _mm_set1_ps(f);
|
|
|
|
|
+ for(int i = 0; i < 4; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ r.arrMm[i] = _mm_sub_ps(mm, m4.arrMm[i]);
|
|
|
|
|
+ }
|
|
|
|
|
+#else
|
|
|
|
|
+ for(int i = 0; i < 16; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ r[i] = f - m4[i];
|
|
|
|
|
+ }
|
|
|
|
|
+#endif
|
|
|
|
|
+ return r;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+// float * 4x4
|
|
|
|
|
+inline Mat4 operator*(const float f, const Mat4& m4)
|
|
|
|
|
+{
|
|
|
|
|
+ return m4 * f;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+// float / 4x4
|
|
|
|
|
+inline Mat4 operator/(const float f, const Mat4& m4)
|
|
|
|
|
+{
|
|
|
|
|
+ Mat4 r;
|
|
|
|
|
+#if defined(MATH_INTEL_SIMD)
|
|
|
|
|
+ __m128 mm;
|
|
|
|
|
+ mm = _mm_set1_ps(f);
|
|
|
|
|
+ for(int i = 0; i < 4; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ r.arrMm[i] = _mm_div_ps(mm, m4.arrMm[i]);
|
|
|
|
|
+ }
|
|
|
|
|
+#else
|
|
|
|
|
+ for(int i = 0; i < 16; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ r[i] = f / m4[i];
|
|
|
|
|
+ }
|
|
|
|
|
+#endif
|
|
|
|
|
+ return r;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+// Print
|
|
|
inline std::ostream& operator<<(std::ostream& s, const Mat4& m)
|
|
inline std::ostream& operator<<(std::ostream& s, const Mat4& m)
|
|
|
{
|
|
{
|
|
|
for(int i = 0; i < 4; i++)
|
|
for(int i = 0; i < 4; i++)
|
|
@@ -1071,6 +1039,3 @@ inline std::ostream& operator<<(std::ostream& s, const Mat4& m)
|
|
|
}
|
|
}
|
|
|
return s;
|
|
return s;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-} // end namespace
|
|
|