diff --git a/Gems/EMotionFX/Code/MCore/Source/Matrix4.cpp b/Gems/EMotionFX/Code/MCore/Source/Matrix4.cpp deleted file mode 100644 index f454df04ab..0000000000 --- a/Gems/EMotionFX/Code/MCore/Source/Matrix4.cpp +++ /dev/null @@ -1,2730 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - -// include required headers -#include "Matrix4.h" -#include -#include -#include - - -namespace MCore -{ - // set the matrix to identity - void Matrix::Identity() - { - TMAT(0, 0) = 1.0f; - TMAT(0, 1) = 0.0f; - TMAT(0, 2) = 0.0f; - TMAT(0, 3) = 0.0f; - TMAT(1, 0) = 0.0f; - TMAT(1, 1) = 1.0f; - TMAT(1, 2) = 0.0f; - TMAT(1, 3) = 0.0f; - TMAT(2, 0) = 0.0f; - TMAT(2, 1) = 0.0f; - TMAT(2, 2) = 1.0f; - TMAT(2, 3) = 0.0f; - TMAT(3, 0) = 0.0f; - TMAT(3, 1) = 0.0f; - TMAT(3, 2) = 0.0f; - TMAT(3, 3) = 1.0f; - } - - - // calculate the matrix determinant - float Matrix::CalcDeterminant() const - { - return - TMAT(0, 0) * TMAT(1, 1) * TMAT(2, 2) + - TMAT(0, 1) * TMAT(1, 2) * TMAT(2, 0) + - TMAT(0, 2) * TMAT(1, 0) * TMAT(2, 1) - - TMAT(0, 2) * TMAT(1, 1) * TMAT(2, 0) - - TMAT(0, 1) * TMAT(1, 0) * TMAT(2, 2) - - TMAT(0, 0) * TMAT(1, 2) * TMAT(2, 1); - } - - - // add operator - Matrix Matrix::operator + (const Matrix& right) const - { - Matrix r; - for (uint32 i = 0; i < 4; ++i) - { - MMAT(r, i, 0) = TMAT(i, 0) + MMAT(right, i, 0); - MMAT(r, i, 1) = TMAT(i, 1) + MMAT(right, i, 1); - MMAT(r, i, 2) = TMAT(i, 2) + MMAT(right, i, 2); - MMAT(r, i, 3) = TMAT(i, 3) + MMAT(right, i, 3); - } - return r; - } - - - // subtract operator - Matrix Matrix::operator - (const Matrix& right) const - { - Matrix r; - for (uint32 i = 0; i < 4; ++i) - { - MMAT(r, i, 0) = TMAT(i, 0) - MMAT(right, i, 0); - MMAT(r, i, 1) = TMAT(i, 1) - MMAT(right, i, 1); - MMAT(r, i, 2) = TMAT(i, 2) - MMAT(right, i, 2); - MMAT(r, i, 3) = TMAT(i, 3) - MMAT(right, i, 3); - } - return r; - } - - - - Matrix Matrix::operator * (const Matrix& right) const - { - Matrix r; - - #if (AZ_TRAIT_USE_PLATFORM_SIMD_SSE && defined(MCORE_MATRIX_ROWMAJOR)) - const float* m = right.m_m16; - const float* n = m_m16; - float* t = r.m_m16; - - __m128 x0; - __m128 x1; - __m128 x2; - __m128 x3; - __m128 x4; - __m128 x5; - __m128 x6; - __m128 x7; - x0 = _mm_loadu_ps(&m[0]); - x1 = _mm_loadu_ps(&m[4]); - x2 = _mm_loadu_ps(&m[8]); - x3 = _mm_loadu_ps(&m[12]); - x4 = _mm_load_ps1(&n[0]); - x5 = _mm_load_ps1(&n[1]); - x6 = _mm_load_ps1(&n[2]); - x7 = _mm_load_ps1(&n[3]); - x4 = _mm_mul_ps(x4, x0); - x5 = _mm_mul_ps(x5, x1); - x6 = _mm_mul_ps(x6, x2); - x7 = _mm_mul_ps(x7, x3); - x4 = _mm_add_ps(x4, x5); - x6 = _mm_add_ps(x6, x7); - x4 = _mm_add_ps(x4, x6); - x5 = _mm_load_ps1(&n[4]); - x6 = _mm_load_ps1(&n[5]); - x7 = _mm_load_ps1(&n[6]); - x5 = _mm_mul_ps(x5, x0); - x6 = _mm_mul_ps(x6, x1); - x7 = _mm_mul_ps(x7, x2); - x5 = _mm_add_ps(x5, x6); - x5 = _mm_add_ps(x5, x7); - x6 = _mm_load_ps1(&n[7]); - x6 = _mm_mul_ps(x6, x3); - x5 = _mm_add_ps(x5, x6); - x6 = _mm_load_ps1(&n[8]); - x7 = _mm_load_ps1(&n[9]); - x6 = _mm_mul_ps(x6, x0); - x7 = _mm_mul_ps(x7, x1); - x6 = _mm_add_ps(x6, x7); - x7 = _mm_load_ps1(&n[10]); - x7 = _mm_mul_ps(x7, x2); - x6 = _mm_add_ps(x6, x7); - x7 = _mm_load_ps1(&n[11]); - x7 = _mm_mul_ps(x7, x3); - x6 = _mm_add_ps(x6, x7); - x7 = _mm_load_ps1(&n[12]); - x0 = _mm_mul_ps(x0, x7); - x7 = _mm_load_ps1(&n[13]); - x1 = _mm_mul_ps(x1, x7); - x7 = _mm_load_ps1(&n[14]); - x2 = _mm_mul_ps(x2, x7); - x7 = _mm_load_ps1(&n[15]); - x3 = _mm_mul_ps(x3, x7); - x0 = _mm_add_ps(x0, x1); - x2 = _mm_add_ps(x2, x3); - x0 = _mm_add_ps(x0, x2); - - //store result - _mm_storeu_ps(&t[0], x4); - _mm_storeu_ps(&t[4], x5); - _mm_storeu_ps(&t[8], x6); - _mm_storeu_ps(&t[12], x0); - #else - for (uint32 i = 0; i < 4; ++i) - { - MMAT(r, i, 0) = TMAT(i, 0) * MMAT(right, 0, 0) + TMAT(i, 1) * MMAT(right, 1, 0) + TMAT(i, 2) * MMAT(right, 2, 0) + TMAT(i, 3) * MMAT(right, 3, 0); - MMAT(r, i, 1) = TMAT(i, 0) * MMAT(right, 0, 1) + TMAT(i, 1) * MMAT(right, 1, 1) + TMAT(i, 2) * MMAT(right, 2, 1) + TMAT(i, 3) * MMAT(right, 3, 1); - MMAT(r, i, 2) = TMAT(i, 0) * MMAT(right, 0, 2) + TMAT(i, 1) * MMAT(right, 1, 2) + TMAT(i, 2) * MMAT(right, 2, 2) + TMAT(i, 3) * MMAT(right, 3, 2); - MMAT(r, i, 3) = TMAT(i, 0) * MMAT(right, 0, 3) + TMAT(i, 1) * MMAT(right, 1, 3) + TMAT(i, 2) * MMAT(right, 2, 3) + TMAT(i, 3) * MMAT(right, 3, 3); - } - #endif - - return r; - } - - - - Matrix& Matrix::operator += (const Matrix& right) - { - for (uint32 i = 0; i < 4; ++i) - { - TMAT(i, 0) += MMAT(right, i, 0); - TMAT(i, 1) += MMAT(right, i, 1); - TMAT(i, 2) += MMAT(right, i, 2); - TMAT(i, 3) += MMAT(right, i, 3); - } - return *this; - } - - - Matrix Matrix::operator * (float value) const - { - Matrix result(*this); - for (uint32 i = 0; i < 4; ++i) - { - MMAT(result, i, 0) *= value; - MMAT(result, i, 1) *= value; - MMAT(result, i, 2) *= value; - MMAT(result, i, 3) *= value; - } - return result; - } - - - Matrix& Matrix::operator -= (const Matrix& right) - { - for (uint32 i = 0; i < 4; ++i) - { - TMAT(i, 0) -= MMAT(right, i, 0); - TMAT(i, 1) -= MMAT(right, i, 1); - TMAT(i, 2) -= MMAT(right, i, 2); - TMAT(i, 3) -= MMAT(right, i, 3); - } - return *this; - } - - - - Matrix& Matrix::operator *= (const Matrix& right) - { - #if (AZ_TRAIT_USE_PLATFORM_SIMD_SSE && defined(MCORE_MATRIX_ROWMAJOR)) - const float* m = right.m_m16; - const float* n = m_m16; - float* t = this->m_m16; - - __m128 x0; - __m128 x1; - __m128 x2; - __m128 x3; - __m128 x4; - __m128 x5; - __m128 x6; - __m128 x7; - x0 = _mm_loadu_ps(&m[0]); - x1 = _mm_loadu_ps(&m[4]); - x2 = _mm_loadu_ps(&m[8]); - x3 = _mm_loadu_ps(&m[12]); - x4 = _mm_load_ps1(&n[0]); - x5 = _mm_load_ps1(&n[1]); - x6 = _mm_load_ps1(&n[2]); - x7 = _mm_load_ps1(&n[3]); - x4 = _mm_mul_ps(x4, x0); - x5 = _mm_mul_ps(x5, x1); - x6 = _mm_mul_ps(x6, x2); - x7 = _mm_mul_ps(x7, x3); - x4 = _mm_add_ps(x4, x5); - x6 = _mm_add_ps(x6, x7); - x4 = _mm_add_ps(x4, x6); - x5 = _mm_load_ps1(&n[4]); - x6 = _mm_load_ps1(&n[5]); - x7 = _mm_load_ps1(&n[6]); - x5 = _mm_mul_ps(x5, x0); - x6 = _mm_mul_ps(x6, x1); - x7 = _mm_mul_ps(x7, x2); - x5 = _mm_add_ps(x5, x6); - x5 = _mm_add_ps(x5, x7); - x6 = _mm_load_ps1(&n[7]); - x6 = _mm_mul_ps(x6, x3); - x5 = _mm_add_ps(x5, x6); - x6 = _mm_load_ps1(&n[8]); - x7 = _mm_load_ps1(&n[9]); - x6 = _mm_mul_ps(x6, x0); - x7 = _mm_mul_ps(x7, x1); - x6 = _mm_add_ps(x6, x7); - x7 = _mm_load_ps1(&n[10]); - x7 = _mm_mul_ps(x7, x2); - x6 = _mm_add_ps(x6, x7); - x7 = _mm_load_ps1(&n[11]); - x7 = _mm_mul_ps(x7, x3); - x6 = _mm_add_ps(x6, x7); - x7 = _mm_load_ps1(&n[12]); - x0 = _mm_mul_ps(x0, x7); - x7 = _mm_load_ps1(&n[13]); - x1 = _mm_mul_ps(x1, x7); - x7 = _mm_load_ps1(&n[14]); - x2 = _mm_mul_ps(x2, x7); - x7 = _mm_load_ps1(&n[15]); - x3 = _mm_mul_ps(x3, x7); - x0 = _mm_add_ps(x0, x1); - x2 = _mm_add_ps(x2, x3); - x0 = _mm_add_ps(x0, x2); - - //store result - _mm_storeu_ps(&t[0], x4); - _mm_storeu_ps(&t[4], x5); - _mm_storeu_ps(&t[8], x6); - _mm_storeu_ps(&t[12], x0); - #else - float v[4]; - for (uint32 i = 0; i < 4; ++i) - { - v[0] = TMAT(i, 0); - v[1] = TMAT(i, 1); - v[2] = TMAT(i, 2); - v[3] = TMAT(i, 3); - TMAT(i, 0) = v[0] * MMAT(right, 0, 0) + v[1] * MMAT(right, 1, 0) + v[2] * MMAT(right, 2, 0) + v[3] * MMAT(right, 3, 0); - TMAT(i, 1) = v[0] * MMAT(right, 0, 1) + v[1] * MMAT(right, 1, 1) + v[2] * MMAT(right, 2, 1) + v[3] * MMAT(right, 3, 1); - TMAT(i, 2) = v[0] * MMAT(right, 0, 2) + v[1] * MMAT(right, 1, 2) + v[2] * MMAT(right, 2, 2) + v[3] * MMAT(right, 3, 2); - TMAT(i, 3) = v[0] * MMAT(right, 0, 3) + v[1] * MMAT(right, 1, 3) + v[2] * MMAT(right, 2, 3) + v[3] * MMAT(right, 3, 3); - } - #endif - - return *this; - } - - - - // calculate euler angles - AZ::Vector3 Matrix::CalcEulerAngles() const - { - AZ::Vector3 v; - /* - // Version with smooth transitions to poles, but slow - float SignCosY = 1; - float NearPole = Math::Pow(Math::Abs(m44[2][0]), 12); - v.y = Math::ASin( -m44[2][0] ); - v.z = Math::ATan( m44[1][0] / m44[0][0] ); - if( Math::Abs(v.y) < Math::Abs(v.z) ) - { - SignCosY = Math::SignOfCos(v.y); - v.z = Math::ATan2( SignCosY * m44[1][0], SignCosY * m44[0][0] ); - } - else - { - v.y = Math::ATan2( -m44[2][0], Math::Sqrt( m44[0][0]*m44[0][0] + m44[1][0]*m44[1][0] ) - * Math::SignOfFloat(Math::SignOfCos(v.z) * m44[0][0])); - SignCosY = Math::SignOfCos(v.y); - } - v.x = (1 - NearPole) * Math::ATan2( SignCosY * m44[2][1], SignCosY * m44[2][2] ) - + NearPole * 0.5 * Math::ATan2(-m44[1][2], m44[1][1]); - v.y = (1 - NearPole) * v.y + NearPole * Math::ATan2(-m44[2][0], m44[0][0]); - v.z = (1 - NearPole) * v.z - NearPole * Math::SignOfSin(v.y) * 0.5 * Math::ATan2(-m44[1][2], m44[1][1]); - */ - - if (Math::Abs(TMAT(2, 0)) < 0.9f) - { - float SignCosY = 1.0f; - v.SetY(Math::ASin(-TMAT(2, 0))); - v.SetZ(Math::ATan(TMAT(1, 0) / TMAT(0, 0))); - if (Math::Abs(v.GetY()) < Math::Abs(v.GetZ())) - { - SignCosY = Math::SignOfCos(v.GetY()); - v.SetZ(Math::ATan2(SignCosY * TMAT(1, 0), SignCosY * TMAT(0, 0))); - } - else - { - v.SetY(Math::ATan2(-TMAT(2, 0), Math::Sqrt(TMAT(0, 0) * TMAT(0, 0) + TMAT(1, 0) * TMAT(1, 0)) * Math::SignOfFloat(Math::SignOfCos(v.GetZ()) * TMAT(0, 0)))); - SignCosY = Math::SignOfCos(v.GetY()); - } - v.SetX(Math::ATan2(SignCosY * m44[2][1], SignCosY * TMAT(2, 2))); - } - else - { - v.SetZ(0.5f * Math::ATan2(-TMAT(1, 2), TMAT(1, 1))); - v.SetY(Math::ATan2(-TMAT(2, 0), TMAT(0, 0))); - v.SetX(-Math::SignOfSin(v.GetY()) * v.GetZ()); - } - - v.SetY(-v.GetY()); - v.SetZ(-v.GetZ()); - - // get the angles in the range [-pi, pi] - v.SetX(v.GetX() + Math::twoPi * Math::Floor((-v.GetX()) / Math::twoPi + 0.5f)); - v.SetY(v.GetY() + Math::twoPi * Math::Floor((-v.GetY()) / Math::twoPi + 0.5f)); - v.SetZ(v.GetZ() + Math::twoPi * Math::Floor((-v.GetZ()) / Math::twoPi + 0.5f)); - - return v; - } - - - - - /* - void Matrix::SetRotationMatrixEulerXYZ(const Vector3& v) - { - const float sy = Math::Sin(v.x); - const float cy = Math::Cos(v.x); - const float sp = Math::Sin(v.y); - const float cp = Math::Cos(v.y); - const float sr = Math::Sin(v.z); - const float cr = Math::Cos(v.z); - const float spsy = sp * sy; - const float spcy = sp * cy; - - m44[0][0] = cr * cp; - m44[0][1] = sr * cp; - m44[0][2] = -sp; - m44[0][3] = 0; - m44[1][0] = cr * spsy - sr * cy; - m44[1][1] = sr * spsy + cr * cy; - m44[1][2] = cp * sy; - m44[1][3] = 0; - m44[2][0] = cr * spcy + sr * sy; - m44[2][1] = sr * spcy - cr * sy; - m44[2][2] = cp * cy; - m44[2][3] = 0; - m44[3][0] = 0; - m44[3][1] = 0; - m44[3][2] = 0; - m44[3][3] = 1; - } - */ - - - // setup as scale matrix - void Matrix::SetScaleMatrix(const AZ::Vector3& s) - { - TMAT(0, 0) = s.GetX(); - TMAT(0, 1) = 0.0f; - TMAT(0, 2) = 0.0f; - TMAT(0, 3) = 0.0f; - TMAT(1, 0) = 0.0f; - TMAT(1, 1) = s.GetY(); - TMAT(1, 2) = 0.0f; - TMAT(1, 3) = 0.0f; - TMAT(2, 0) = 0.0f; - TMAT(2, 1) = 0.0f; - TMAT(2, 2) = s.GetZ(); - TMAT(2, 3) = 0.0f; - TMAT(3, 0) = 0.0f; - TMAT(3, 1) = 0.0f; - TMAT(3, 2) = 0.0f; - TMAT(3, 3) = 1.0f; - } - - - // setup as translation matrix - void Matrix::SetTranslationMatrix(const AZ::Vector3& t) - { - TMAT(0, 0) = 1.0f; - TMAT(0, 1) = 0.0f; - TMAT(0, 2) = 0.0f; - TMAT(0, 3) = 0.0f; - TMAT(1, 0) = 0.0f; - TMAT(1, 1) = 1.0f; - TMAT(1, 2) = 0.0f; - TMAT(1, 3) = 0.0f; - TMAT(2, 0) = 0.0f; - TMAT(2, 1) = 0.0f; - TMAT(2, 2) = 1.0f; - TMAT(2, 3) = 0.0f; - TMAT(3, 0) = t.GetX(); - TMAT(3, 1) = t.GetY(); - TMAT(3, 2) = t.GetZ(); - TMAT(3, 3) = 1.0f; - } - - - // setup as rotation matrix - void Matrix::SetRotationMatrixX(float angle) - { - const float s = Math::Sin(angle); - const float c = Math::Cos(angle); - - TMAT(0, 0) = 1.0f; - TMAT(0, 1) = 0.0f; - TMAT(0, 2) = 0.0f; - TMAT(0, 3) = 0.0f; - TMAT(1, 0) = 0.0f; - TMAT(1, 1) = c; - TMAT(1, 2) = s; - TMAT(1, 3) = 0.0f; - TMAT(2, 0) = 0.0f; - TMAT(2, 1) = -s; - TMAT(2, 2) = c; - TMAT(2, 3) = 0.0f; - TMAT(3, 0) = 0.0f; - TMAT(3, 1) = 0.0f; - TMAT(3, 2) = 0.0f; - TMAT(3, 3) = 1.0f; - } - - - // setup as rotation matrix - void Matrix::SetRotationMatrixY(float angle) - { - const float s = Math::Sin(angle); - const float c = Math::Cos(angle); - - TMAT(0, 0) = c; - TMAT(0, 1) = 0.0f; - TMAT(0, 2) = -s; - TMAT(0, 3) = 0.0f; - TMAT(1, 0) = 0.0f; - TMAT(1, 1) = 1.0f; - TMAT(1, 2) = 0.0f; - TMAT(1, 3) = 0.0f; - TMAT(2, 0) = s; - TMAT(2, 1) = 0.0f; - TMAT(2, 2) = c; - TMAT(2, 3) = 0.0f; - TMAT(3, 0) = 0.0f; - TMAT(3, 1) = 0.0f; - TMAT(3, 2) = 0.0f; - TMAT(3, 3) = 1.0f; - } - - - // setup as rotation matrix - void Matrix::SetRotationMatrixZ(float angle) - { - const float s = Math::Sin(angle); - const float c = Math::Cos(angle); - - TMAT(0, 0) = c; - TMAT(0, 1) = s; - TMAT(0, 2) = 0.0f; - TMAT(0, 3) = 0.0f; - TMAT(1, 0) = -s; - TMAT(1, 1) = c; - TMAT(1, 2) = 0.0f; - TMAT(1, 3) = 0.0f; - TMAT(2, 0) = 0.0f; - TMAT(2, 1) = 0.0f; - TMAT(2, 2) = 1.0f; - TMAT(2, 3) = 0.0f; - TMAT(3, 0) = 0.0f; - TMAT(3, 1) = 0.0f; - TMAT(3, 2) = 0.0f; - TMAT(3, 3) = 1.0f; - } - - - void Matrix::SetRotationMatrixEulerZYX(const AZ::Vector3& v) - { - *this = Matrix::RotationMatrixX(v.GetZ()); - this->MultMatrix4x3(Matrix::RotationMatrixY(v.GetY())); - this->MultMatrix4x3(Matrix::RotationMatrixZ(v.GetX())); - } - - - - void Matrix::SetRotationMatrixEulerXYZ(const AZ::Vector3& v) - { - *this = Matrix::RotationMatrixX(v.GetX()); - this->MultMatrix4x3(Matrix::RotationMatrixY(v.GetY())); - this->MultMatrix4x3(Matrix::RotationMatrixZ(v.GetZ())); - } - - - - void Matrix::SetRotationMatrixAxisAngle(const AZ::Vector3& axis, float angle) - { - const float length2 = axis.GetLengthSq(); - if (Math::Abs(length2) < 0.00001f) - { - Identity(); - return; - } - - const AZ::Vector3 n = axis / Math::Sqrt(length2); - const float s = Math::Sin(angle); - const float c = Math::Cos(angle); - const float k = 1.0f - c; - const float xx = n.GetX() * n.GetX() * k + c; - const float yy = n.GetY() * n.GetY() * k + c; - const float zz = n.GetZ() * n.GetZ() * k + c; - const float xy = n.GetX() * n.GetY() * k; - const float yz = n.GetY() * n.GetZ() * k; - const float zx = n.GetZ() * n.GetX() * k; - const float xs = n.GetX() * s; - const float ys = n.GetY() * s; - const float zs = n.GetZ() * s; - - TMAT(0, 0) = xx; - TMAT(0, 1) = xy + zs; - TMAT(0, 2) = zx - ys; - TMAT(0, 3) = 0.0f; - TMAT(1, 0) = xy - zs; - TMAT(1, 1) = yy; - TMAT(1, 2) = yz + xs; - TMAT(1, 3) = 0.0f; - TMAT(2, 0) = zx + ys; - TMAT(2, 1) = yz - xs; - TMAT(2, 2) = zz; - TMAT(2, 3) = 0.0f; - TMAT(3, 0) = 0.0f; - TMAT(3, 1) = 0.0f; - TMAT(3, 2) = 0.0f; - TMAT(3, 3) = 1.0f; - } - - - void Matrix::Scale3x3(const AZ::Vector3& scale) - { - TMAT(0, 0) *= scale.GetX(); - TMAT(0, 1) *= scale.GetY(); - TMAT(0, 2) *= scale.GetZ(); - - TMAT(1, 0) *= scale.GetX(); - TMAT(1, 1) *= scale.GetY(); - TMAT(1, 2) *= scale.GetZ(); - - TMAT(2, 0) *= scale.GetX(); - TMAT(2, 1) *= scale.GetY(); - TMAT(2, 2) *= scale.GetZ(); - } - - - AZ::Vector3 Matrix::ExtractScale() - { - const AZ::Vector4 x = GetRow4D(0); - const AZ::Vector4 y = GetRow4D(1); - const AZ::Vector4 z = GetRow4D(2); - const float lengthX = x.GetLength(); - const float lengthY = y.GetLength(); - const float lengthZ = z.GetLength(); - SetRow(0, x / lengthX); - SetRow(1, y / lengthY); - SetRow(2, z / lengthZ); - - return AZ::Vector3(lengthX, lengthY, lengthZ); - } - - void Matrix::RotateX(float angle) - { - const float s = Math::Sin(angle); - const float c = Math::Cos(angle); - - for (uint32 i = 0; i < 3; ++i) - { - const float x = TMAT(2, i); - const float z = TMAT(1, i); - TMAT(2, i) = x * c - z * s; - TMAT(1, i) = x * s + z * c; - } - } - - - - void Matrix::RotateY(float angle) - { - const float s = Math::Sin(angle); - const float c = Math::Cos(angle); - - for (uint32 i = 0; i < 3; ++i) - { - const float x = TMAT(0, i); - const float z = TMAT(2, i); - TMAT(0, i) = x * c - z * s; - TMAT(2, i) = x * s + z * c; - } - } - - - - void Matrix::RotateZ(float angle) - { - const float s = Math::Sin(angle); - const float c = Math::Cos(angle); - - for (uint32 i = 0; i < 3; ++i) - { - const float x = TMAT(1, i); - const float z = TMAT(0, i); - TMAT(1, i) = x * c - z * s; - TMAT(0, i) = x * s + z * c; - } - } - - /* - void Matrix::RotateXYZ(const float yaw, const float pitch, const float roll) - { - const float sy = Math::Sin(yaw); - const float cy = Math::Cos(yaw); - const float sp = Math::Sin(pitch); - const float cp = Math::Cos(pitch); - const float sr = Math::Sin(roll); - const float cr = Math::Cos(roll); - const float spsy = sp * sy; - const float spcy = sp * cy; - const float m00 = cr * cp; - const float m01 = sr * cp; - const float m02 = -sp; - const float m10 = cr * spsy - sr * cy; - const float m11 = sr * spsy + cr * cy; - const float m12 = cp * sy; - const float m20 = cr * spcy + sr * sy; - const float m21 = sr * spcy - cr * sy; - const float m22 = cp * cy; - - for ( int32 i=0; i<4; i++ ) - { - const float x = m44[i][0]; - const float y = m44[i][1]; - const float z = m44[i][2]; - m44[i][0] = x * m00 + y * m10 + z * m20; - m44[i][1] = x * m01 + y * m11 + z * m21; - m44[i][2] = x * m02 + y * m12 + z * m22; - } - } - */ - - - void Matrix::MultMatrix(const Matrix& right) - { - #if (AZ_TRAIT_USE_PLATFORM_SIMD_SSE && defined(MCORE_MATRIX_ROWMAJOR)) - const float* m = right.m_m16; - const float* n = m_m16; - float* t = this->m_m16; - - __m128 x0; - __m128 x1; - __m128 x2; - __m128 x3; - __m128 x4; - __m128 x5; - __m128 x6; - __m128 x7; - x0 = _mm_loadu_ps(&m[0]); - x1 = _mm_loadu_ps(&m[4]); - x2 = _mm_loadu_ps(&m[8]); - x3 = _mm_loadu_ps(&m[12]); - x4 = _mm_load_ps1(&n[0]); - x5 = _mm_load_ps1(&n[1]); - x6 = _mm_load_ps1(&n[2]); - x7 = _mm_load_ps1(&n[3]); - x4 = _mm_mul_ps(x4, x0); - x5 = _mm_mul_ps(x5, x1); - x6 = _mm_mul_ps(x6, x2); - x7 = _mm_mul_ps(x7, x3); - x4 = _mm_add_ps(x4, x5); - x6 = _mm_add_ps(x6, x7); - x4 = _mm_add_ps(x4, x6); - x5 = _mm_load_ps1(&n[4]); - x6 = _mm_load_ps1(&n[5]); - x7 = _mm_load_ps1(&n[6]); - x5 = _mm_mul_ps(x5, x0); - x6 = _mm_mul_ps(x6, x1); - x7 = _mm_mul_ps(x7, x2); - x5 = _mm_add_ps(x5, x6); - x5 = _mm_add_ps(x5, x7); - x6 = _mm_load_ps1(&n[7]); - x6 = _mm_mul_ps(x6, x3); - x5 = _mm_add_ps(x5, x6); - x6 = _mm_load_ps1(&n[8]); - x7 = _mm_load_ps1(&n[9]); - x6 = _mm_mul_ps(x6, x0); - x7 = _mm_mul_ps(x7, x1); - x6 = _mm_add_ps(x6, x7); - x7 = _mm_load_ps1(&n[10]); - x7 = _mm_mul_ps(x7, x2); - x6 = _mm_add_ps(x6, x7); - x7 = _mm_load_ps1(&n[11]); - x7 = _mm_mul_ps(x7, x3); - x6 = _mm_add_ps(x6, x7); - x7 = _mm_load_ps1(&n[12]); - x0 = _mm_mul_ps(x0, x7); - x7 = _mm_load_ps1(&n[13]); - x1 = _mm_mul_ps(x1, x7); - x7 = _mm_load_ps1(&n[14]); - x2 = _mm_mul_ps(x2, x7); - x7 = _mm_load_ps1(&n[15]); - x3 = _mm_mul_ps(x3, x7); - x0 = _mm_add_ps(x0, x1); - x2 = _mm_add_ps(x2, x3); - x0 = _mm_add_ps(x0, x2); - - //store result - _mm_storeu_ps(&t[0], x4); - _mm_storeu_ps(&t[4], x5); - _mm_storeu_ps(&t[8], x6); - _mm_storeu_ps(&t[12], x0); - #else - float v[4]; - for (uint32 i = 0; i < 4; ++i) - { - v[0] = TMAT(i, 0); - v[1] = TMAT(i, 1); - v[2] = TMAT(i, 2); - v[3] = TMAT(i, 3); - TMAT(i, 0) = v[0] * MMAT(right, 0, 0) + v[1] * MMAT(right, 1, 0) + v[2] * MMAT(right, 2, 0) + v[3] * MMAT(right, 3, 0); - TMAT(i, 1) = v[0] * MMAT(right, 0, 1) + v[1] * MMAT(right, 1, 1) + v[2] * MMAT(right, 2, 1) + v[3] * MMAT(right, 3, 1); - TMAT(i, 2) = v[0] * MMAT(right, 0, 2) + v[1] * MMAT(right, 1, 2) + v[2] * MMAT(right, 2, 2) + v[3] * MMAT(right, 3, 2); - TMAT(i, 3) = v[0] * MMAT(right, 0, 3) + v[1] * MMAT(right, 1, 3) + v[2] * MMAT(right, 2, 3) + v[3] * MMAT(right, 3, 3); - } - #endif - } - - - // init from position, rotation, scale and shear - // use this to reconstruct a matrix that has been decomposed using the DecomposeQRGramSchmidt method - void Matrix::InitFromPosRotScaleShear(const AZ::Vector3& pos, const AZ::Quaternion& rot, const AZ::Vector3& scale, const AZ::Vector3& shear) - { - // convert quat to matrix - const float xx = rot.GetX() * rot.GetX(); - const float xy = rot.GetX() * rot.GetY(), yy = rot.GetY() * rot.GetY(); - const float xz = rot.GetX() * rot.GetZ(), yz = rot.GetY() * rot.GetZ(), zz = rot.GetZ() * rot.GetZ(); - const float xw = rot.GetX() * rot.GetW(), yw = rot.GetY() * rot.GetW(), zw = rot.GetZ() * rot.GetW(), ww = rot.GetW() * rot.GetW(); - TMAT(0, 0) = +xx - yy - zz + ww; - TMAT(0, 1) = +xy + zw + xy + zw; - TMAT(0, 2) = +xz - yw + xz - yw; - TMAT(0, 3) = 0.0f; - TMAT(1, 0) = +xy - zw + xy - zw; - TMAT(1, 1) = -xx + yy - zz + ww; - TMAT(1, 2) = +yz + xw + yz + xw; - TMAT(1, 3) = 0.0f; - TMAT(2, 0) = +xz + yw + xz + yw; - TMAT(2, 1) = +yz - xw + yz - xw; - TMAT(2, 2) = -xx - yy + zz + ww; - TMAT(2, 3) = 0.0f; - - // scale - TMAT(0, 0) *= scale.GetX(); - TMAT(0, 1) *= scale.GetY(); - TMAT(0, 2) *= scale.GetZ(); - TMAT(1, 0) *= scale.GetX(); - TMAT(1, 1) *= scale.GetY(); - TMAT(1, 2) *= scale.GetZ(); - TMAT(2, 0) *= scale.GetX(); - TMAT(2, 1) *= scale.GetY(); - TMAT(2, 2) *= scale.GetZ(); - - // multiply with the shear matrix - float v[3]; - v[0] = TMAT(0, 0); - v[1] = TMAT(0, 1); - v[2] = TMAT(0, 2); - TMAT(0, 1) = v[0] * shear.GetX() + v[1]; - TMAT(0, 2) = v[0] * shear.GetY() + v[1] * shear.GetZ() + v[2]; - - v[0] = TMAT(1, 0); - v[1] = TMAT(1, 1); - v[2] = TMAT(1, 2); - TMAT(1, 1) = v[0] * shear.GetX() + v[1]; - TMAT(1, 2) = v[0] * shear.GetY() + v[1] * shear.GetZ() + v[2]; - - v[0] = TMAT(2, 0); - v[1] = TMAT(2, 1); - v[2] = TMAT(2, 2); - TMAT(2, 1) = v[0] * shear.GetX() + v[1]; - TMAT(2, 2) = v[0] * shear.GetY() + v[1] * shear.GetZ() + v[2]; - - // translation - TMAT(3, 0) = pos.GetX(); - TMAT(3, 1) = pos.GetY(); - TMAT(3, 2) = pos.GetZ(); - TMAT(3, 3) = 1.0f; - } - - - // init from position, rotation, scale, scale rotation - // use this to reconstruct a matrix decomposed using the MatrixDecomposer class using polar decomposition - void Matrix::InitFromPosRotScaleScaleRot(const AZ::Vector3& pos, const AZ::Quaternion& rot, const AZ::Vector3& scale, const AZ::Quaternion& scaleRot) - { - float xx = scaleRot.GetX() * scaleRot.GetX(); - float xy = scaleRot.GetX() * scaleRot.GetY(), yy = scaleRot.GetY() * scaleRot.GetY(); - float xz = scaleRot.GetX() * scaleRot.GetZ(), yz = scaleRot.GetY() * scaleRot.GetZ(), zz = scaleRot.GetZ() * scaleRot.GetZ(); - float xw = scaleRot.GetX() * scaleRot.GetW(), yw = scaleRot.GetY() * scaleRot.GetW(), zw = scaleRot.GetZ() * scaleRot.GetW(), ww = scaleRot.GetW() * scaleRot.GetW(); - - // init on the inversed scale rotation - TMAT(0, 0) = +xx - yy - zz + ww; - TMAT(1, 0) = +xy + zw + xy + zw; - TMAT(2, 0) = +xz - yw + xz - yw; // translation part not initialized - TMAT(0, 1) = +xy - zw + xy - zw; - TMAT(1, 1) = -xx + yy - zz + ww; - TMAT(2, 1) = +yz + xw + yz + xw; - TMAT(0, 2) = +xz + yw + xz + yw; - TMAT(1, 2) = +yz - xw + yz - xw; - TMAT(2, 2) = -xx - yy + zz + ww; - TMAT(0, 3) = 0.0f; - TMAT(1, 3) = 0.0f; - TMAT(2, 3) = 0.0f; - TMAT(3, 3) = 1.0f; - - // copy the 3x3 part into a temp buffer, so that we have the inverse scale rotation, before scaling applied to it - float r33[3][3]; - uint32 i; - for (i = 0; i < 3; ++i) - { -#ifdef MCORE_MATRIX_ROWMAJOR - r33[i][0] = TMAT(i, 0); - r33[i][1] = TMAT(i, 1); - r33[i][2] = TMAT(i, 2); -#else - r33[0][i] = TMAT(i, 0); - r33[1][i] = TMAT(i, 1); - r33[2][i] = TMAT(i, 2); -#endif - } - - // apply scaling - TMAT(0, 0) *= scale.GetX(); - TMAT(0, 1) *= scale.GetY(); - TMAT(0, 2) *= scale.GetZ(); - TMAT(1, 0) *= scale.GetX(); - TMAT(1, 1) *= scale.GetY(); - TMAT(1, 2) *= scale.GetZ(); - TMAT(2, 0) *= scale.GetX(); - TMAT(2, 1) *= scale.GetY(); - TMAT(2, 2) *= scale.GetZ(); - - // undo the scale rotation - float v[3]; - for (i = 0; i < 3; ++i) - { - v[0] = TMAT(i, 0); - v[1] = TMAT(i, 1); - v[2] = TMAT(i, 2); - -#ifdef MCORE_MATRIX_ROWMAJOR - TMAT(i, 0) = v[0] * r33[0][0] + v[1] * r33[0][1] + v[2] * r33[0][2]; // transposed multiply - TMAT(i, 1) = v[0] * r33[1][0] + v[1] * r33[1][1] + v[2] * r33[1][2]; - TMAT(i, 2) = v[0] * r33[2][0] + v[1] * r33[2][1] + v[2] * r33[2][2]; -#else - TMAT(i, 0) = v[0] * r33[0][0] + v[1] * r33[1][0] + v[2] * r33[2][0]; // transposed multiply - TMAT(i, 1) = v[0] * r33[0][1] + v[1] * r33[1][1] + v[2] * r33[2][1]; - TMAT(i, 2) = v[0] * r33[0][2] + v[1] * r33[1][2] + v[2] * r33[2][2]; -#endif - } - - // apply regular rotation - xx = rot.GetX() * rot.GetX(); - xy = rot.GetX() * rot.GetY(); - yy = rot.GetY() * rot.GetY(); - xz = rot.GetX() * rot.GetZ(); - yz = rot.GetY() * rot.GetZ(); - zz = rot.GetZ() * rot.GetZ(); - xw = rot.GetX() * rot.GetW(); - yw = rot.GetY() * rot.GetW(); - zw = rot.GetZ() * rot.GetW(); - ww = rot.GetW() * rot.GetW(); - -#ifdef MCORE_MATRIX_ROWMAJOR - r33[0][0] = +xx - yy - zz + ww; - r33[0][1] = +xy + zw + xy + zw; - r33[0][2] = +xz - yw + xz - yw; - r33[1][0] = +xy - zw + xy - zw; - r33[1][1] = -xx + yy - zz + ww; - r33[1][2] = +yz + xw + yz + xw; - r33[2][0] = +xz + yw + xz + yw; - r33[2][1] = +yz - xw + yz - xw; - r33[2][2] = -xx - yy + zz + ww; -#else - r33[0][0] = +xx - yy - zz + ww; - r33[1][0] = +xy + zw + xy + zw; - r33[2][0] = +xz - yw + xz - yw; - r33[0][1] = +xy - zw + xy - zw; - r33[1][1] = -xx + yy - zz + ww; - r33[2][1] = +yz + xw + yz + xw; - r33[0][2] = +xz + yw + xz + yw; - r33[1][2] = +yz - xw + yz - xw; - r33[2][2] = -xx - yy + zz + ww; -#endif - - // mult 3x3 matrix - for (i = 0; i < 3; ++i) - { - v[0] = TMAT(i, 0); - v[1] = TMAT(i, 1); - v[2] = TMAT(i, 2); - -#ifdef MCORE_MATRIX_ROWMAJOR - TMAT(i, 0) = v[0] * r33[0][0] + v[1] * r33[1][0] + v[2] * r33[2][0]; - TMAT(i, 1) = v[0] * r33[0][1] + v[1] * r33[1][1] + v[2] * r33[2][1]; - TMAT(i, 2) = v[0] * r33[0][2] + v[1] * r33[1][2] + v[2] * r33[2][2]; -#else - TMAT(i, 0) = v[0] * r33[0][0] + v[1] * r33[0][1] + v[2] * r33[0][2]; - TMAT(i, 1) = v[0] * r33[1][0] + v[1] * r33[1][1] + v[2] * r33[1][2]; - TMAT(i, 2) = v[0] * r33[2][0] + v[1] * r33[2][1] + v[2] * r33[2][2]; -#endif - } - - // apply translation - TMAT(3, 0) = pos.GetX(); - TMAT(3, 1) = pos.GetY(); - TMAT(3, 2) = pos.GetZ(); - } - - - // init from pos/rot/scale - void Matrix::InitFromPosRotScale(const AZ::Vector3& pos, const AZ::Quaternion& rot, const AZ::Vector3& scale) - { - // init on a scale + translation matrix - TMAT(0, 0) = scale.GetX(); - TMAT(0, 1) = 0.0f; - TMAT(0, 2) = 0.0f; - TMAT(0, 3) = 0.0f; - TMAT(1, 0) = 0.0f; - TMAT(1, 1) = scale.GetY(); - TMAT(1, 2) = 0.0f; - TMAT(1, 3) = 0.0f; - TMAT(2, 0) = 0.0f; - TMAT(2, 1) = 0.0f; - TMAT(2, 2) = scale.GetZ(); - TMAT(2, 3) = 0.0f; - TMAT(3, 0) = pos.GetX(); - TMAT(3, 1) = pos.GetY(); - TMAT(3, 2) = pos.GetZ(); - TMAT(3, 3) = 1.0f; - - // multiply it with a rotation matrix built from the AZ::Quaternion - // don't rotate the translation part - const float xx = rot.GetX() * rot.GetX(); - const float xy = rot.GetX() * rot.GetY(), yy = rot.GetY() * rot.GetY(); - const float xz = rot.GetX() * rot.GetZ(), yz = rot.GetY() * rot.GetZ(), zz = rot.GetZ() * rot.GetZ(); - const float xw = rot.GetX() * rot.GetW(), yw = rot.GetY() * rot.GetW(), zw = rot.GetZ() * rot.GetW(), ww = rot.GetW() * rot.GetW(); - - float r33[3][3]; - #ifdef MCORE_MATRIX_ROWMAJOR - r33[0][0] = +xx - yy - zz + ww; - r33[0][1] = +xy + zw + xy + zw; - r33[0][2] = +xz - yw + xz - yw; - r33[1][0] = +xy - zw + xy - zw; - r33[1][1] = -xx + yy - zz + ww; - r33[1][2] = +yz + xw + yz + xw; - r33[2][0] = +xz + yw + xz + yw; - r33[2][1] = +yz - xw + yz - xw; - r33[2][2] = -xx - yy + zz + ww; - #else - r33[0][0] = +xx - yy - zz + ww; - r33[1][0] = +xy + zw + xy + zw; - r33[2][0] = +xz - yw + xz - yw; - r33[0][1] = +xy - zw + xy - zw; - r33[1][1] = -xx + yy - zz + ww; - r33[2][1] = +yz + xw + yz + xw; - r33[0][2] = +xz + yw + xz + yw; - r33[1][2] = +yz - xw + yz - xw; - r33[2][2] = -xx - yy + zz + ww; - #endif - - // perform the matrix mul - float v[3]; - for (uint32 i = 0; i < 3; ++i) - { - v[0] = TMAT(i, 0); - v[1] = TMAT(i, 1); - v[2] = TMAT(i, 2); - - #ifdef MCORE_MATRIX_ROWMAJOR - TMAT(i, 0) = v[0] * r33[0][0] + v[1] * r33[1][0] + v[2] * r33[2][0]; - TMAT(i, 1) = v[0] * r33[0][1] + v[1] * r33[1][1] + v[2] * r33[2][1]; - TMAT(i, 2) = v[0] * r33[0][2] + v[1] * r33[1][2] + v[2] * r33[2][2]; - #else - TMAT(i, 0) = v[0] * r33[0][0] + v[1] * r33[0][1] + v[2] * r33[0][2]; - TMAT(i, 1) = v[0] * r33[1][0] + v[1] * r33[1][1] + v[2] * r33[1][2]; - TMAT(i, 2) = v[0] * r33[2][0] + v[1] * r33[2][1] + v[2] * r33[2][2]; - #endif - } - } - - - // init from pos/rot/scale with parent scale compensation - void Matrix::InitFromNoScaleInherit(const AZ::Vector3& pos, const AZ::Quaternion& rot, const AZ::Vector3& scale, const AZ::Vector3& invParentScale) - { - // init on a scale + translation matrix - TMAT(0, 0) = scale.GetX(); - TMAT(0, 1) = 0.0f; - TMAT(0, 2) = 0.0f; - TMAT(0, 3) = 0.0f; - TMAT(1, 0) = 0.0f; - TMAT(1, 1) = scale.GetY(); - TMAT(1, 2) = 0.0f; - TMAT(1, 3) = 0.0f; - TMAT(2, 0) = 0.0f; - TMAT(2, 1) = 0.0f; - TMAT(2, 2) = scale.GetZ(); - TMAT(2, 3) = 0.0f; - TMAT(3, 0) = pos.GetX(); - TMAT(3, 1) = pos.GetY(); - TMAT(3, 2) = pos.GetZ(); - TMAT(3, 3) = 1.0f; - - // multiply it with a rotation matrix built from the AZ::Quaternion - // don't rotate the translation part - const float xx = rot.GetX() * rot.GetX(); - const float xy = rot.GetX() * rot.GetY(), yy = rot.GetY() * rot.GetY(); - const float xz = rot.GetX() * rot.GetZ(), yz = rot.GetY() * rot.GetZ(), zz = rot.GetZ() * rot.GetZ(); - const float xw = rot.GetX() * rot.GetW(), yw = rot.GetY() * rot.GetW(), zw = rot.GetZ() * rot.GetW(), ww = rot.GetW() * rot.GetW(); - - float r33[3][3]; - #ifdef MCORE_MATRIX_ROWMAJOR - r33[0][0] = +xx - yy - zz + ww; - r33[0][1] = +xy + zw + xy + zw; - r33[0][2] = +xz - yw + xz - yw; - r33[1][0] = +xy - zw + xy - zw; - r33[1][1] = -xx + yy - zz + ww; - r33[1][2] = +yz + xw + yz + xw; - r33[2][0] = +xz + yw + xz + yw; - r33[2][1] = +yz - xw + yz - xw; - r33[2][2] = -xx - yy + zz + ww; - #else - r33[0][0] = +xx - yy - zz + ww; - r33[1][0] = +xy + zw + xy + zw; - r33[2][0] = +xz - yw + xz - yw; - r33[0][1] = +xy - zw + xy - zw; - r33[1][1] = -xx + yy - zz + ww; - r33[2][1] = +yz + xw + yz + xw; - r33[0][2] = +xz + yw + xz + yw; - r33[1][2] = +yz - xw + yz - xw; - r33[2][2] = -xx - yy + zz + ww; - #endif - - // perform the matrix mul - float v[3]; - for (uint32 i = 0; i < 3; ++i) - { - v[0] = TMAT(i, 0); - v[1] = TMAT(i, 1); - v[2] = TMAT(i, 2); - - #ifdef MCORE_MATRIX_ROWMAJOR - TMAT(i, 0) = v[0] * r33[0][0] + v[1] * r33[1][0] + v[2] * r33[2][0]; - TMAT(i, 1) = v[0] * r33[0][1] + v[1] * r33[1][1] + v[2] * r33[2][1]; - TMAT(i, 2) = v[0] * r33[0][2] + v[1] * r33[1][2] + v[2] * r33[2][2]; - #else - TMAT(i, 0) = v[0] * r33[0][0] + v[1] * r33[0][1] + v[2] * r33[0][2]; - TMAT(i, 1) = v[0] * r33[1][0] + v[1] * r33[1][1] + v[2] * r33[1][2]; - TMAT(i, 2) = v[0] * r33[2][0] + v[1] * r33[2][1] + v[2] * r33[2][2]; - #endif - } - - // multiply this with the 3x3 scale inverse parent scale matrix - TMAT(0, 0) *= invParentScale.GetX(); - TMAT(0, 1) *= invParentScale.GetY(); - TMAT(0, 2) *= invParentScale.GetZ(); - TMAT(1, 0) *= invParentScale.GetX(); - TMAT(1, 1) *= invParentScale.GetY(); - TMAT(1, 2) *= invParentScale.GetZ(); - TMAT(2, 0) *= invParentScale.GetX(); - TMAT(2, 1) *= invParentScale.GetY(); - TMAT(2, 2) *= invParentScale.GetZ(); - } - - - void Matrix::InitFromPosRot(const AZ::Vector3& pos, const AZ::Quaternion& rot) - { - const float xx = rot.GetX() * rot.GetX(); - const float xy = rot.GetX() * rot.GetY(), yy = rot.GetY() * rot.GetY(); - const float xz = rot.GetX() * rot.GetZ(), yz = rot.GetY() * rot.GetZ(), zz = rot.GetZ() * rot.GetZ(); - const float xw = rot.GetX() * rot.GetW(), yw = rot.GetY() * rot.GetW(), zw = rot.GetZ() * rot.GetW(), ww = rot.GetW() * rot.GetW(); - - TMAT(0, 0) = +xx - yy - zz + ww; - TMAT(0, 1) = +xy + zw + xy + zw; - TMAT(0, 2) = +xz - yw + xz - yw; - TMAT(0, 3) = 0.0f; - TMAT(1, 0) = +xy - zw + xy - zw; - TMAT(1, 1) = -xx + yy - zz + ww; - TMAT(1, 2) = +yz + xw + yz + xw; - TMAT(1, 3) = 0.0f; - TMAT(2, 0) = +xz + yw + xz + yw; - TMAT(2, 1) = +yz - xw + yz - xw; - TMAT(2, 2) = -xx - yy + zz + ww; - TMAT(2, 3) = 0.0f; - TMAT(3, 0) = pos.GetX(); - TMAT(3, 1) = pos.GetY(); - TMAT(3, 2) = pos.GetZ(); - TMAT(3, 3) = 1.0f; - } - - /* - // optimized routine for handling scale rotation, rotation, scale and translation - void Matrix::Set(const AZ::Quaternion& scaleRot, const AZ::Quaternion& rotation, const Vector3& scale, const Vector3& translation) - { - float xx=scaleRot.x*scaleRot.x; - float xy=scaleRot.x*scaleRot.y, yy=scaleRot.y*scaleRot.y; - float xz=scaleRot.x*scaleRot.z, yz=scaleRot.y*scaleRot.z, zz=scaleRot.z*scaleRot.z; - float xw=scaleRot.x*scaleRot.w, yw=scaleRot.y*scaleRot.w, zw=scaleRot.z*scaleRot.w, ww=scaleRot.w*scaleRot.w; - - // init on the inversed scale rotation - TMAT(0,0) = +xx-yy-zz+ww; TMAT(1,0) = +xy+zw+xy+zw; TMAT(2,0) = +xz-yw+xz-yw; // translation part not initialized - TMAT(0,1) = +xy-zw+xy-zw; TMAT(1,1) = -xx+yy-zz+ww; TMAT(2,1) = +yz+xw+yz+xw; - TMAT(0,2) = +xz+yw+xz+yw; TMAT(1,2) = +yz-xw+yz-xw; TMAT(2,2) = -xx-yy+zz+ww; - TMAT(0,3) = 0.0f; TMAT(1,3) = 0.0f; TMAT(2,3) = 0.0f; TMAT(3,3) = 1.0f; - - // copy the 3x3 part into a temp buffer, so that we have the inverse scale rotation, before scaling applied to it - float r33[3][3]; - uint32 i; - for (i=0; i<3; ++i) - { - #ifdef MCORE_MATRIX_ROWMAJOR - r33[i][0] = TMAT(i,0); - r33[i][1] = TMAT(i,1); - r33[i][2] = TMAT(i,2); - #else - r33[0][i] = TMAT(i,0); - r33[1][i] = TMAT(i,1); - r33[2][i] = TMAT(i,2); - #endif - } - - // apply scaling - TMAT(0,0) *= scale.x; - TMAT(0,1) *= scale.y; - TMAT(0,2) *= scale.z; - TMAT(1,0) *= scale.x; - TMAT(1,1) *= scale.y; - TMAT(1,2) *= scale.z; - TMAT(2,0) *= scale.x; - TMAT(2,1) *= scale.y; - TMAT(2,2) *= scale.z; - - // undo the scale rotation - float v[3]; - for (i=0; i<3; ++i) - { - v[0] = TMAT(i,0); - v[1] = TMAT(i,1); - v[2] = TMAT(i,2); - - #ifdef MCORE_MATRIX_ROWMAJOR - TMAT(i,0) = v[0]*r33[0][0] + v[1]*r33[0][1] + v[2]*r33[0][2]; // transposed multiply - TMAT(i,1) = v[0]*r33[1][0] + v[1]*r33[1][1] + v[2]*r33[1][2]; - TMAT(i,2) = v[0]*r33[2][0] + v[1]*r33[2][1] + v[2]*r33[2][2]; - #else - TMAT(i,0) = v[0]*r33[0][0] + v[1]*r33[1][0] + v[2]*r33[2][0]; // transposed multiply - TMAT(i,1) = v[0]*r33[0][1] + v[1]*r33[1][1] + v[2]*r33[2][1]; - TMAT(i,2) = v[0]*r33[0][2] + v[1]*r33[1][2] + v[2]*r33[2][2]; - #endif - } - - // apply regular rotation - xx=rotation.x*rotation.x; - xy=rotation.x*rotation.y; yy=rotation.y*rotation.y; - xz=rotation.x*rotation.z; yz=rotation.y*rotation.z; zz=rotation.z*rotation.z; - xw=rotation.x*rotation.w; yw=rotation.y*rotation.w; zw=rotation.z*rotation.w; ww=rotation.w*rotation.w; - - #ifdef MCORE_MATRIX_ROWMAJOR - r33[0][0] = +xx-yy-zz+ww; r33[0][1] = +xy+zw+xy+zw; r33[0][2] = +xz-yw+xz-yw; - r33[1][0] = +xy-zw+xy-zw; r33[1][1] = -xx+yy-zz+ww; r33[1][2] = +yz+xw+yz+xw; - r33[2][0] = +xz+yw+xz+yw; r33[2][1] = +yz-xw+yz-xw; r33[2][2] = -xx-yy+zz+ww; - #else - r33[0][0] = +xx-yy-zz+ww; r33[1][0] = +xy+zw+xy+zw; r33[2][0] = +xz-yw+xz-yw; - r33[0][1] = +xy-zw+xy-zw; r33[1][1] = -xx+yy-zz+ww; r33[2][1] = +yz+xw+yz+xw; - r33[0][2] = +xz+yw+xz+yw; r33[1][2] = +yz-xw+yz-xw; r33[2][2] = -xx-yy+zz+ww; - #endif - - // mult 3x3 matrix - for (i=0; i<3; ++i) - { - v[0] = TMAT(i,0); - v[1] = TMAT(i,1); - v[2] = TMAT(i,2); - - #ifdef MCORE_MATRIX_ROWMAJOR - TMAT(i,0) = v[0]*r33[0][0] + v[1]*r33[1][0] + v[2]*r33[2][0]; - TMAT(i,1) = v[0]*r33[0][1] + v[1]*r33[1][1] + v[2]*r33[2][1]; - TMAT(i,2) = v[0]*r33[0][2] + v[1]*r33[1][2] + v[2]*r33[2][2]; - #else - TMAT(i,0) = v[0]*r33[0][0] + v[1]*r33[0][1] + v[2]*r33[0][2]; - TMAT(i,1) = v[0]*r33[1][0] + v[1]*r33[1][1] + v[2]*r33[1][2]; - TMAT(i,2) = v[0]*r33[2][0] + v[1]*r33[2][1] + v[2]*r33[2][2]; - #endif - } - - // apply translation - TMAT(3,0) = translation.x; - TMAT(3,1) = translation.y; - TMAT(3,2) = translation.z; - } - */ - - - void Matrix::MultMatrix4x3(const Matrix& right) - { - #if (AZ_TRAIT_USE_PLATFORM_SIMD_SSE && defined(MCORE_MATRIX_ROWMAJOR)) - const float* m = right.m_m16; - const float* n = m_m16; - float* t = this->m_m16; - - __m128 x0; - __m128 x1; - __m128 x2; - __m128 x3; - __m128 x4; - __m128 x5; - __m128 x6; - __m128 x7; - x0 = _mm_loadu_ps(&m[0]); - x1 = _mm_loadu_ps(&m[4]); - x2 = _mm_loadu_ps(&m[8]); - x3 = _mm_loadu_ps(&m[12]); - x4 = _mm_load_ps1(&n[0]); - x5 = _mm_load_ps1(&n[1]); - x6 = _mm_load_ps1(&n[2]); - x7 = _mm_load_ps1(&n[3]); - x4 = _mm_mul_ps(x4, x0); - x5 = _mm_mul_ps(x5, x1); - x6 = _mm_mul_ps(x6, x2); - x7 = _mm_mul_ps(x7, x3); - x4 = _mm_add_ps(x4, x5); - x6 = _mm_add_ps(x6, x7); - x4 = _mm_add_ps(x4, x6); - x5 = _mm_load_ps1(&n[4]); - x6 = _mm_load_ps1(&n[5]); - x7 = _mm_load_ps1(&n[6]); - x5 = _mm_mul_ps(x5, x0); - x6 = _mm_mul_ps(x6, x1); - x7 = _mm_mul_ps(x7, x2); - x5 = _mm_add_ps(x5, x6); - x5 = _mm_add_ps(x5, x7); - x6 = _mm_load_ps1(&n[7]); - x6 = _mm_mul_ps(x6, x3); - x5 = _mm_add_ps(x5, x6); - x6 = _mm_load_ps1(&n[8]); - x7 = _mm_load_ps1(&n[9]); - x6 = _mm_mul_ps(x6, x0); - x7 = _mm_mul_ps(x7, x1); - x6 = _mm_add_ps(x6, x7); - x7 = _mm_load_ps1(&n[10]); - x7 = _mm_mul_ps(x7, x2); - x6 = _mm_add_ps(x6, x7); - x7 = _mm_load_ps1(&n[11]); - x7 = _mm_mul_ps(x7, x3); - x6 = _mm_add_ps(x6, x7); - x7 = _mm_load_ps1(&n[12]); - x0 = _mm_mul_ps(x0, x7); - x7 = _mm_load_ps1(&n[13]); - x1 = _mm_mul_ps(x1, x7); - x7 = _mm_load_ps1(&n[14]); - x2 = _mm_mul_ps(x2, x7); - x7 = _mm_load_ps1(&n[15]); - x3 = _mm_mul_ps(x3, x7); - x0 = _mm_add_ps(x0, x1); - x2 = _mm_add_ps(x2, x3); - x0 = _mm_add_ps(x0, x2); - - //store result - _mm_storeu_ps(&t[0], x4); - _mm_storeu_ps(&t[4], x5); - _mm_storeu_ps(&t[8], x6); - _mm_storeu_ps(&t[12], x0); - #else - float v[3]; - - for (uint32 i = 0; i < 4; ++i) - { - v[0] = TMAT(i, 0); - v[1] = TMAT(i, 1); - v[2] = TMAT(i, 2); - TMAT(i, 0) = v[0] * MMAT(right, 0, 0) + v[1] * MMAT(right, 1, 0) + v[2] * MMAT(right, 2, 0); - TMAT(i, 1) = v[0] * MMAT(right, 0, 1) + v[1] * MMAT(right, 1, 1) + v[2] * MMAT(right, 2, 1); - TMAT(i, 2) = v[0] * MMAT(right, 0, 2) + v[1] * MMAT(right, 1, 2) + v[2] * MMAT(right, 2, 2); - } - - TMAT(3, 0) += MMAT(right, 3, 0); - TMAT(3, 1) += MMAT(right, 3, 1); - TMAT(3, 2) += MMAT(right, 3, 2); - #endif - } - - - // *this = left * right - void Matrix::MultMatrix(const Matrix& left, const Matrix& right) - { - #if (AZ_TRAIT_USE_PLATFORM_SIMD_SSE && defined(MCORE_MATRIX_ROWMAJOR)) - const float* m = right.m_m16; - const float* n = left.m_m16; - float* t = this->m_m16; - - __m128 x0; - __m128 x1; - __m128 x2; - __m128 x3; - __m128 x4; - __m128 x5; - __m128 x6; - __m128 x7; - x0 = _mm_loadu_ps(&m[0]); - x1 = _mm_loadu_ps(&m[4]); - x2 = _mm_loadu_ps(&m[8]); - x3 = _mm_loadu_ps(&m[12]); - x4 = _mm_load_ps1(&n[0]); - x5 = _mm_load_ps1(&n[1]); - x6 = _mm_load_ps1(&n[2]); - x7 = _mm_load_ps1(&n[3]); - x4 = _mm_mul_ps(x4, x0); - x5 = _mm_mul_ps(x5, x1); - x6 = _mm_mul_ps(x6, x2); - x7 = _mm_mul_ps(x7, x3); - x4 = _mm_add_ps(x4, x5); - x6 = _mm_add_ps(x6, x7); - x4 = _mm_add_ps(x4, x6); - x5 = _mm_load_ps1(&n[4]); - x6 = _mm_load_ps1(&n[5]); - x7 = _mm_load_ps1(&n[6]); - x5 = _mm_mul_ps(x5, x0); - x6 = _mm_mul_ps(x6, x1); - x7 = _mm_mul_ps(x7, x2); - x5 = _mm_add_ps(x5, x6); - x5 = _mm_add_ps(x5, x7); - x6 = _mm_load_ps1(&n[7]); - x6 = _mm_mul_ps(x6, x3); - x5 = _mm_add_ps(x5, x6); - x6 = _mm_load_ps1(&n[8]); - x7 = _mm_load_ps1(&n[9]); - x6 = _mm_mul_ps(x6, x0); - x7 = _mm_mul_ps(x7, x1); - x6 = _mm_add_ps(x6, x7); - x7 = _mm_load_ps1(&n[10]); - x7 = _mm_mul_ps(x7, x2); - x6 = _mm_add_ps(x6, x7); - x7 = _mm_load_ps1(&n[11]); - x7 = _mm_mul_ps(x7, x3); - x6 = _mm_add_ps(x6, x7); - x7 = _mm_load_ps1(&n[12]); - x0 = _mm_mul_ps(x0, x7); - x7 = _mm_load_ps1(&n[13]); - x1 = _mm_mul_ps(x1, x7); - x7 = _mm_load_ps1(&n[14]); - x2 = _mm_mul_ps(x2, x7); - x7 = _mm_load_ps1(&n[15]); - x3 = _mm_mul_ps(x3, x7); - x0 = _mm_add_ps(x0, x1); - x2 = _mm_add_ps(x2, x3); - x0 = _mm_add_ps(x0, x2); - - //store result - _mm_storeu_ps(&t[0], x4); - _mm_storeu_ps(&t[4], x5); - _mm_storeu_ps(&t[8], x6); - _mm_storeu_ps(&t[12], x0); - #else - float v[4]; - for (uint32 i = 0; i < 4; ++i) - { - v[0] = MMAT(left, i, 0); - v[1] = MMAT(left, i, 1); - v[2] = MMAT(left, i, 2); - v[3] = MMAT(left, i, 3); - TMAT(i, 0) = v[0] * MMAT(right, 0, 0) + v[1] * MMAT(right, 1, 0) + v[2] * MMAT(right, 2, 0) + v[3] * MMAT(right, 3, 0); - TMAT(i, 1) = v[0] * MMAT(right, 0, 1) + v[1] * MMAT(right, 1, 1) + v[2] * MMAT(right, 2, 1) + v[3] * MMAT(right, 3, 1); - TMAT(i, 2) = v[0] * MMAT(right, 0, 2) + v[1] * MMAT(right, 1, 2) + v[2] * MMAT(right, 2, 2) + v[3] * MMAT(right, 3, 2); - TMAT(i, 3) = v[0] * MMAT(right, 0, 3) + v[1] * MMAT(right, 1, 3) + v[2] * MMAT(right, 2, 3) + v[3] * MMAT(right, 3, 3); - } - #endif - } - - - - void Matrix::MultMatrix4x3(const Matrix& left, const Matrix& right) - { - #if (AZ_TRAIT_USE_PLATFORM_SIMD_SSE && defined(MCORE_MATRIX_ROWMAJOR)) - const float* m = right.m_m16; - const float* n = left.m_m16; - float* t = this->m_m16; - - __m128 x0; - __m128 x1; - __m128 x2; - __m128 x3; - __m128 x4; - __m128 x5; - __m128 x6; - __m128 x7; - x0 = _mm_loadu_ps(&m[0]); - x1 = _mm_loadu_ps(&m[4]); - x2 = _mm_loadu_ps(&m[8]); - x3 = _mm_loadu_ps(&m[12]); - x4 = _mm_load_ps1(&n[0]); - x5 = _mm_load_ps1(&n[1]); - x6 = _mm_load_ps1(&n[2]); - x7 = _mm_load_ps1(&n[3]); - x4 = _mm_mul_ps(x4, x0); - x5 = _mm_mul_ps(x5, x1); - x6 = _mm_mul_ps(x6, x2); - x7 = _mm_mul_ps(x7, x3); - x4 = _mm_add_ps(x4, x5); - x6 = _mm_add_ps(x6, x7); - x4 = _mm_add_ps(x4, x6); - x5 = _mm_load_ps1(&n[4]); - x6 = _mm_load_ps1(&n[5]); - x7 = _mm_load_ps1(&n[6]); - x5 = _mm_mul_ps(x5, x0); - x6 = _mm_mul_ps(x6, x1); - x7 = _mm_mul_ps(x7, x2); - x5 = _mm_add_ps(x5, x6); - x5 = _mm_add_ps(x5, x7); - x6 = _mm_load_ps1(&n[7]); - x6 = _mm_mul_ps(x6, x3); - x5 = _mm_add_ps(x5, x6); - x6 = _mm_load_ps1(&n[8]); - x7 = _mm_load_ps1(&n[9]); - x6 = _mm_mul_ps(x6, x0); - x7 = _mm_mul_ps(x7, x1); - x6 = _mm_add_ps(x6, x7); - x7 = _mm_load_ps1(&n[10]); - x7 = _mm_mul_ps(x7, x2); - x6 = _mm_add_ps(x6, x7); - x7 = _mm_load_ps1(&n[11]); - x7 = _mm_mul_ps(x7, x3); - x6 = _mm_add_ps(x6, x7); - x7 = _mm_load_ps1(&n[12]); - x0 = _mm_mul_ps(x0, x7); - x7 = _mm_load_ps1(&n[13]); - x1 = _mm_mul_ps(x1, x7); - x7 = _mm_load_ps1(&n[14]); - x2 = _mm_mul_ps(x2, x7); - x7 = _mm_load_ps1(&n[15]); - x3 = _mm_mul_ps(x3, x7); - x0 = _mm_add_ps(x0, x1); - x2 = _mm_add_ps(x2, x3); - x0 = _mm_add_ps(x0, x2); - - //store result - _mm_storeu_ps(&t[0], x4); - _mm_storeu_ps(&t[4], x5); - _mm_storeu_ps(&t[8], x6); - _mm_storeu_ps(&t[12], x0); - #else - float v[3]; - for (uint32 i = 0; i < 4; ++i) - { - v[0] = MMAT(left, i, 0); - v[1] = MMAT(left, i, 1); - v[2] = MMAT(left, i, 2); - TMAT(i, 0) = v[0] * MMAT(right, 0, 0) + v[1] * MMAT(right, 1, 0) + v[2] * MMAT(right, 2, 0); - TMAT(i, 1) = v[0] * MMAT(right, 0, 1) + v[1] * MMAT(right, 1, 1) + v[2] * MMAT(right, 2, 1); - TMAT(i, 2) = v[0] * MMAT(right, 0, 2) + v[1] * MMAT(right, 1, 2) + v[2] * MMAT(right, 2, 2); - } - - TMAT(0, 3) = 0.0f; - TMAT(1, 3) = 0.0f; - TMAT(2, 3) = 0.0f; - TMAT(3, 3) = 1.0f; - TMAT(3, 0) += MMAT(right, 3, 0); - TMAT(3, 1) += MMAT(right, 3, 1); - TMAT(3, 2) += MMAT(right, 3, 2); - #endif - } - - - void Matrix::MultMatrix3x3(const Matrix& right) - { - float v[3]; - for (uint32 i = 0; i < 4; ++i) - { - v[0] = TMAT(i, 0); - v[1] = TMAT(i, 1); - v[2] = TMAT(i, 2); - TMAT(i, 0) = v[0] * MMAT(right, 0, 0) + v[1] * MMAT(right, 1, 0) + v[2] * MMAT(right, 2, 0); - TMAT(i, 1) = v[0] * MMAT(right, 0, 1) + v[1] * MMAT(right, 1, 1) + v[2] * MMAT(right, 2, 1); - TMAT(i, 2) = v[0] * MMAT(right, 0, 2) + v[1] * MMAT(right, 1, 2) + v[2] * MMAT(right, 2, 2); - } - } - - - void Matrix::Transpose() - { - Matrix v; - - MMAT(v, 0, 0) = TMAT(0, 0); - MMAT(v, 0, 1) = TMAT(1, 0); - MMAT(v, 0, 2) = TMAT(2, 0); - MMAT(v, 0, 3) = TMAT(3, 0); - MMAT(v, 1, 0) = TMAT(0, 1); - MMAT(v, 1, 1) = TMAT(1, 1); - MMAT(v, 1, 2) = TMAT(2, 1); - MMAT(v, 1, 3) = TMAT(3, 1); - MMAT(v, 2, 0) = TMAT(0, 2); - MMAT(v, 2, 1) = TMAT(1, 2); - MMAT(v, 2, 2) = TMAT(2, 2); - MMAT(v, 2, 3) = TMAT(3, 2); - MMAT(v, 3, 0) = TMAT(0, 3); - MMAT(v, 3, 1) = TMAT(1, 3); - MMAT(v, 3, 2) = TMAT(2, 3); - MMAT(v, 3, 3) = TMAT(3, 3); - - *this = v; - } - - - void Matrix::TransposeTranslation() - { - AZ::Vector3 temp; - - temp.SetX(TMAT(3, 0)); - temp.SetY(TMAT(3, 1)); - temp.SetZ(TMAT(3, 2)); - - TMAT(3, 0) = TMAT(0, 3); - TMAT(3, 1) = TMAT(1, 3); - TMAT(3, 2) = TMAT(2, 3); - - TMAT(0, 3) = temp.GetX(); - TMAT(1, 3) = temp.GetY(); - TMAT(2, 3) = temp.GetZ(); - } - - - - void Matrix::Adjoint() - { - Matrix v; - - MMAT(v, 0, 0) = TMAT(1, 1) * TMAT(2, 2) - TMAT(1, 2) * TMAT(2, 1); - MMAT(v, 0, 1) = TMAT(2, 1) * TMAT(0, 2) - TMAT(2, 2) * TMAT(0, 1); - MMAT(v, 0, 2) = TMAT(0, 1) * TMAT(1, 2) - TMAT(0, 2) * TMAT(1, 1); - MMAT(v, 0, 3) = TMAT(0, 3); - MMAT(v, 1, 0) = TMAT(1, 2) * TMAT(2, 0) - TMAT(1, 0) * TMAT(2, 2); - MMAT(v, 1, 1) = TMAT(2, 2) * TMAT(0, 0) - TMAT(2, 0) * TMAT(0, 2); - MMAT(v, 1, 2) = TMAT(0, 2) * TMAT(1, 0) - TMAT(0, 0) * TMAT(1, 2); - MMAT(v, 1, 3) = TMAT(1, 3); - MMAT(v, 2, 0) = TMAT(1, 0) * TMAT(2, 1) - TMAT(1, 1) * TMAT(2, 0); - MMAT(v, 2, 1) = TMAT(2, 0) * TMAT(0, 1) - TMAT(2, 1) * TMAT(0, 0); - MMAT(v, 2, 2) = TMAT(0, 0) * TMAT(1, 1) - TMAT(0, 1) * TMAT(1, 0); - MMAT(v, 2, 3) = TMAT(2, 3); - MMAT(v, 3, 0) = -(TMAT(0, 0) * TMAT(3, 0) + TMAT(1, 0) * TMAT(3, 1) + TMAT(2, 0) * TMAT(3, 2)); - MMAT(v, 3, 1) = -(TMAT(0, 1) * TMAT(3, 0) + TMAT(1, 1) * TMAT(3, 1) + TMAT(2, 1) * TMAT(3, 2)); - MMAT(v, 3, 2) = -(TMAT(0, 2) * TMAT(3, 0) + TMAT(1, 2) * TMAT(3, 1) + TMAT(2, 2) * TMAT(3, 2)); - MMAT(v, 3, 3) = TMAT(3, 3); - - *this = v; - } - - - - AZ::Vector3 Matrix::InverseRot(const AZ::Vector3& v) - { - Matrix m(*this); - m.Inverse(); - m.SetTranslation(0.0f, 0.0f, 0.0f); - return v * m; - } - - - - void Matrix::Inverse() - { - Matrix v; - - const float s = 1.0f / CalcDeterminant(); - MMAT(v, 0, 0) = (TMAT(1, 1) * TMAT(2, 2) - TMAT(1, 2) * TMAT(2, 1)) * s; - MMAT(v, 0, 1) = (TMAT(2, 1) * TMAT(0, 2) - TMAT(2, 2) * TMAT(0, 1)) * s; - MMAT(v, 0, 2) = (TMAT(0, 1) * TMAT(1, 2) - TMAT(0, 2) * TMAT(1, 1)) * s; - MMAT(v, 0, 3) = TMAT(0, 3); - MMAT(v, 1, 0) = (TMAT(1, 2) * TMAT(2, 0) - TMAT(1, 0) * TMAT(2, 2)) * s; - MMAT(v, 1, 1) = (TMAT(2, 2) * TMAT(0, 0) - TMAT(2, 0) * TMAT(0, 2)) * s; - MMAT(v, 1, 2) = (TMAT(0, 2) * TMAT(1, 0) - TMAT(0, 0) * TMAT(1, 2)) * s; - MMAT(v, 1, 3) = TMAT(1, 3); - MMAT(v, 2, 0) = (TMAT(1, 0) * TMAT(2, 1) - TMAT(1, 1) * TMAT(2, 0)) * s; - MMAT(v, 2, 1) = (TMAT(2, 0) * TMAT(0, 1) - TMAT(2, 1) * TMAT(0, 0)) * s; - MMAT(v, 2, 2) = (TMAT(0, 0) * TMAT(1, 1) - TMAT(0, 1) * TMAT(1, 0)) * s; - MMAT(v, 2, 3) = TMAT(2, 3); - MMAT(v, 3, 0) = -(MMAT(v, 0, 0) * TMAT(3, 0) + MMAT(v, 1, 0) * TMAT(3, 1) + MMAT(v, 2, 0) * TMAT(3, 2)); - MMAT(v, 3, 1) = -(MMAT(v, 0, 1) * TMAT(3, 0) + MMAT(v, 1, 1) * TMAT(3, 1) + MMAT(v, 2, 1) * TMAT(3, 2)); - MMAT(v, 3, 2) = -(MMAT(v, 0, 2) * TMAT(3, 0) + MMAT(v, 1, 2) * TMAT(3, 1) + MMAT(v, 2, 2) * TMAT(3, 2)); - MMAT(v, 3, 3) = TMAT(3, 3); - - *this = v; - } - - - - void Matrix::OrthoNormalize() - { - AZ::Vector3 x = GetRight(); - AZ::Vector3 y = GetUp(); - //Vector3 z = GetForward(); - - x.Normalize(); - y -= x * x.Dot(y); - y.Normalize(); - AZ::Vector3 z = x.Cross(y); - - SetRight(x); - SetUp(y); - SetForward(z); - } - - - - void Matrix::Mirror(const Matrix& transform, const PlaneEq& plane) - { - // components - AZ::Vector3 x = transform.GetRight(); - AZ::Vector3 y = transform.GetForward(); - AZ::Vector3 z = transform.GetUp(); - AZ::Vector3 t = transform.GetTranslation(); - AZ::Vector3 n = plane.GetNormal(); - AZ::Vector3 n2 = n * -2.0f; - float d = plane.GetDist(); - - // mirror translation - AZ::Vector3 mt = t + n2 * (t.Dot(n) - d); - - // mirror x rotation - x += t; - x += n2 * (x.Dot(n) - d); - x -= mt; - - // mirror y rotation - y += t; - y += n2 * (y.Dot(n) - d); - y -= mt; - - // mirror z rotation - z += t; - z += n2 * (z.Dot(n) - d); - z -= mt; - - // write result - SetRight(x); - SetForward(y); - SetUp(z); - SetTranslation(mt); - - TMAT(0, 3) = 0; - TMAT(1, 3) = 0; - TMAT(2, 3) = 0; - TMAT(3, 3) = 1; - } - - - void Matrix::LookAt(const AZ::Vector3& view, const AZ::Vector3& target, const AZ::Vector3& up) - { - const AZ::Vector3 z = (target - view).GetNormalized(); - const AZ::Vector3 x = (up.Cross(z)).GetNormalized(); - const AZ::Vector3 y = z.Cross(x); - - TMAT(0, 0) = x.GetX(); - TMAT(0, 1) = y.GetX(); - TMAT(0, 2) = z.GetX(); - TMAT(0, 3) = 0.0f; - TMAT(1, 0) = x.GetY(); - TMAT(1, 1) = y.GetY(); - TMAT(1, 2) = z.GetY(); - TMAT(1, 3) = 0.0f; - TMAT(2, 0) = x.GetZ(); - TMAT(2, 1) = y.GetZ(); - TMAT(2, 2) = z.GetZ(); - TMAT(2, 3) = 0.0f; - TMAT(3, 0) = -x.Dot(view); - TMAT(3, 1) = -y.Dot(view); - TMAT(3, 2) = -z.Dot(view); - TMAT(3, 3) = 1.0f; - - // DirectX: - // zaxis = normal(cameraTarget - cameraPosition) - // xaxis = normal(cross(cameraUpVector, zaxis)) - // yaxis = cross(zaxis, xaxis) - // xaxis.x yaxis.x zaxis.x 0 - // xaxis.y yaxis.y zaxis.y 0 - // xaxis.z yaxis.z zaxis.z 0 - // -dot(xaxis, cameraPosition) -dot(yaxis, cameraPosition) -dot(zaxis, cameraPosition) 1 - } - - - void Matrix::LookAtRH(const AZ::Vector3& view, const AZ::Vector3& target, const AZ::Vector3& up) - { - const AZ::Vector3 z = (view - target).GetNormalized(); - const AZ::Vector3 x = (up.Cross(z)).GetNormalized(); - const AZ::Vector3 y = z.Cross(x); - - TMAT(0, 0) = x.GetX(); - TMAT(0, 1) = y.GetX(); - TMAT(0, 2) = z.GetX(); - TMAT(0, 3) = 0.0f; - TMAT(1, 0) = x.GetY(); - TMAT(1, 1) = y.GetY(); - TMAT(1, 2) = z.GetY(); - TMAT(1, 3) = 0.0f; - TMAT(2, 0) = x.GetZ(); - TMAT(2, 1) = y.GetZ(); - TMAT(2, 2) = z.GetZ(); - TMAT(2, 3) = 0.0f; - TMAT(3, 0) = -x.Dot(view); - TMAT(3, 1) = -y.Dot(view); - TMAT(3, 2) = -z.Dot(view); - TMAT(3, 3) = 1.0f; - - // DirectX: - // zaxis = normal(cameraPosition - cameraTarget) - // xaxis = normal(cross(cameraUpVector, zaxis)) - // yaxis = cross(zaxis, xaxis) - // xaxis.x yaxis.x zaxis.x 0 - // xaxis.y yaxis.y zaxis.y 0 - // xaxis.z yaxis.z zaxis.z 0 - // -dot(xaxis, cameraPosition) -dot(yaxis, cameraPosition) -dot(zaxis, cameraPosition) 1 - } - - // ortho projection matrix - void Matrix::OrthoOffCenter(float left, float right, float top, float bottom, float znear, float zfar) - { - TMAT(0, 0) = 2.0f / (right - left); - TMAT(0, 1) = 0.0f; - TMAT(0, 2) = 0.0f; - TMAT(0, 3) = 0.0f; - TMAT(1, 0) = 0.0f; - TMAT(1, 1) = 2.0f / (top - bottom); - TMAT(1, 2) = 0.0f; - TMAT(1, 3) = 0.0f; - TMAT(2, 0) = 0.0f; - TMAT(2, 1) = 0.0f; - TMAT(2, 2) = 1.0f / (zfar - znear); - TMAT(2, 3) = 0.0f; - TMAT(3, 0) = (left + right) / (left - right); - TMAT(3, 1) = (top + bottom) / (bottom - top); - TMAT(3, 2) = znear / (znear - zfar); - TMAT(3, 3) = 1.0f; - - // DirectX: - // 2/(right-l) 0 0 0 - // 0 2/(top-bottom) 0 0 - // 0 0 1/(zfarPlane-znearPlane) 0 - // (l+right)/(l-right) (top+bottom)/(bottom-top) znearPlane/(znearPlane-zfarPlane) 1 - } - - - // ortho projection matrix - void Matrix::OrthoOffCenterRH(float left, float right, float top, float bottom, float znear, float zfar) - { - TMAT(0, 0) = 2.0f / (right - left); - TMAT(0, 1) = 0.0f; - TMAT(0, 2) = 0.0f; - TMAT(0, 3) = 0.0f; - TMAT(1, 0) = 0.0f; - TMAT(1, 1) = 2.0f / (top - bottom); - TMAT(1, 2) = 0.0f; - TMAT(1, 3) = 0.0f; - TMAT(2, 0) = 0.0f; - TMAT(2, 1) = 0.0f; - TMAT(2, 2) = 1.0f / (znear - zfar); - TMAT(2, 3) = 0.0f; - TMAT(3, 0) = (left + right) / (left - right); - TMAT(3, 1) = (top + bottom) / (bottom - top); - TMAT(3, 2) = znear / (znear - zfar); - TMAT(3, 3) = 1.0f; - - // DirectX: - // 2/(right-left) 0 0 0 - // 0 2/(top-bottom) 0 0 - // 0 0 1/(znearPlane-zfarPlane) 0 - // (l+right)/(l-rright) (top+bottom)/(bottom-top) znearPlane/(znearPlane-zfarPlane) 1 - } - - - // ortho projection matrix - void Matrix::Ortho(float left, float right, float top, float bottom, float znear, float zfar) - { - TMAT(0, 0) = 2.0f / (right - left); - TMAT(0, 1) = 0.0f; - TMAT(0, 2) = 0.0f; - TMAT(0, 3) = 0.0f; - TMAT(1, 0) = 0.0f; - TMAT(1, 1) = 2.0f / (top - bottom); - TMAT(1, 2) = 0.0f; - TMAT(1, 3) = 0.0f; - TMAT(2, 0) = 0.0f; - TMAT(2, 1) = 0.0f; - TMAT(2, 2) = 1.0f / (zfar - znear); - TMAT(2, 3) = 0.0f; - TMAT(3, 0) = 0.0f; - TMAT(3, 1) = 0.0f; - TMAT(3, 2) = znear / (znear - zfar); - TMAT(3, 3) = 1.0f; - - // DirectX: - // 2/width 0 0 0 - // 0 2/height 0 0 - // 0 0 1/(zfarPlane-znearPlane) 0 - // 0 0 znearPlane/(znearPlane-zfarPlane) 1 - } - - - // ortho projection matrix, right handed - void Matrix::OrthoRH(float left, float right, float top, float bottom, float znear, float zfar) - { - TMAT(0, 0) = 2.0f / (right - left); - TMAT(0, 1) = 0.0f; - TMAT(0, 2) = 0.0f; - TMAT(0, 3) = 0.0f; - TMAT(1, 0) = 0.0f; - TMAT(1, 1) = 2.0f / (top - bottom); - TMAT(1, 2) = 0.0f; - TMAT(1, 3) = 0.0f; - TMAT(2, 0) = 0.0f; - TMAT(2, 1) = 0.0f; - TMAT(2, 2) = 1.0f / (znear - zfar); - TMAT(2, 3) = 0.0f; - TMAT(3, 0) = 0.0f; - TMAT(3, 1) = 0.0f; - TMAT(3, 2) = znear / (znear - zfar); - TMAT(3, 3) = 1.0f; - - // DirectX: - // 2/width 0 0 0 - // 0 2/height 0 0 - // 0 0 1/(znearPlane-zfarPlane) 0 - // 0 0 znearPlane/(znearPlane-zfarPlane) 1 - } - - - // frustum matrix - void Matrix::Frustum(float left, float right, float top, float bottom, float znear, float zfar) - { - TMAT(0, 0) = 2.0f * znear / (right - left); - TMAT(1, 0) = 0.0f; - TMAT(2, 0) = (right + left) / (right - left); - TMAT(3, 0) = 0.0f; - TMAT(0, 1) = 0.0f; - TMAT(1, 1) = 2.0f * znear / (top - bottom); - TMAT(2, 1) = (top + bottom) / (top - bottom); - TMAT(3, 1) = 0.0f; - TMAT(0, 2) = 0.0f; - TMAT(1, 2) = 0.0f; - TMAT(2, 2) = (zfar + znear) / (zfar - znear); - TMAT(3, 2) = 2.0f * zfar * znear / (zfar - znear); - TMAT(0, 3) = 0.0f; - TMAT(1, 3) = 0.0f; - TMAT(2, 3) = -1.0f; - TMAT(3, 3) = 0.0f; - } - - - // setup perspective projection matrix - void Matrix::Perspective(float fov, float aspect, float zNear, float zFar) - { - const float yScale = 1.0f / Math::Tan(fov * 0.5f); - const float xScale = yScale / aspect; - const float d = zFar / (zFar - zNear); - - MCore::MemSet(m44, 0, 16 * sizeof(float)); - TMAT(0, 0) = xScale; - TMAT(1, 1) = yScale; - TMAT(2, 2) = d; - TMAT(2, 3) = 1.0f; - TMAT(3, 2) = -zNear * d; - } - - - // setup perspective projection matrix, right handed - void Matrix::PerspectiveRH(float fov, float aspect, float zNear, float zFar) - { - const float yScale = 1.0f / Math::Tan(fov * 0.5f); - const float xScale = yScale / aspect; - const float d = zFar / (zNear - zFar); - - MCore::MemSet(m44, 0, 16 * sizeof(float)); - TMAT(0, 0) = xScale; - TMAT(1, 1) = yScale; - TMAT(2, 2) = d; - TMAT(2, 3) = -1.0f; - TMAT(3, 2) = zNear * d; - } - - - // check if the matrix is symmetric or not - bool Matrix::CheckIfIsSymmetric(float tolerance) const - { - // if no tolerance check is needed - if (MCore::Math::IsFloatZero(tolerance)) - { - if (TMAT(1, 0) != TMAT(0, 1)) - { - return false; - } - if (TMAT(2, 0) != TMAT(0, 2)) - { - return false; - } - if (TMAT(2, 1) != TMAT(1, 2)) - { - return false; - } - if (TMAT(3, 0) != TMAT(0, 3)) - { - return false; - } - if (TMAT(3, 1) != TMAT(1, 3)) - { - return false; - } - if (TMAT(3, 2) != TMAT(2, 3)) - { - return false; - } - } - else // tolerance check needed - { - if (Math::Abs(TMAT(1, 0) - TMAT(0, 1)) > tolerance) - { - return false; - } - if (Math::Abs(TMAT(2, 0) - TMAT(0, 2)) > tolerance) - { - return false; - } - if (Math::Abs(TMAT(2, 1) - TMAT(1, 2)) > tolerance) - { - return false; - } - if (Math::Abs(TMAT(3, 0) - TMAT(0, 3)) > tolerance) - { - return false; - } - if (Math::Abs(TMAT(3, 1) - TMAT(1, 3)) > tolerance) - { - return false; - } - if (Math::Abs(TMAT(3, 2) - TMAT(2, 3)) > tolerance) - { - return false; - } - } - - // yeah, we have a symmetric matrix here - return true; - } - - - // check if this matrix is a diagonal matrix or not. - bool Matrix::CheckIfIsDiagonal(float tolerance) const - { - if (tolerance <= Math::epsilon) - { - // for all entries - for (uint32 y = 0; y < 4; ++y) - { - for (uint32 x = 0; x < 4; ++x) - { - // if we are on the diagonal - if (x == y) - { - if (TMAT(y, x) == 0) - { - return false; // if this entry on the diagonal is 0, we have no diagonal matrix - } - } - else // we are not on the diagonal - if (TMAT(y, x) != 0) - { - return false; // if the entry isn't equal to 0, it isn't a diagonal matrix - } - } - } - } - else - { - // for all entries - for (uint32 y = 0; y < 4; ++y) - { - for (uint32 x = 0; x < 4; ++x) - { - // if we are on the diagonal - if (x == y) - { - if (Math::Abs(TMAT(y, x)) < tolerance) - { - return false; // if this entry on the diagonal is 0, we have no diagonal matrix - } - } - else // we are not on the diagonal - { - if (Math::Abs(TMAT(y, x)) > tolerance) - { - return false; // if the entry isn't equal to 0, it isn't a diagonal matrix - } - } - } - } - } - - // yeaaah, we have a diagonal matrix here - return true; - } - - - // prints the matrix into the logfile or debug output, using MCore::LOG() - void Matrix::Log() const - { - MCore::LogDetailedInfo(""); - MCore::LogDetailedInfo("(%.8f, %.8f, %.8f, %.8f)", m_m16[0], m_m16[1], m_m16[2], m_m16[3]); - MCore::LogDetailedInfo("(%.8f, %.8f, %.8f, %.8f)", m_m16[4], m_m16[5], m_m16[6], m_m16[7]); - MCore::LogDetailedInfo("(%.8f, %.8f, %.8f, %.8f)", m_m16[8], m_m16[9], m_m16[10], m_m16[11]); - MCore::LogDetailedInfo("(%.8f, %.8f, %.8f, %.8f)", m_m16[12], m_m16[13], m_m16[14], m_m16[15]); - MCore::LogDetailedInfo(""); - } - - - // check if the matrix is orthogonal or not - bool Matrix::CheckIfIsOrthogonal(float tolerance) const - { - // get the matrix vectors - AZ::Vector3 right = GetRight(); - AZ::Vector3 up = GetUp(); - AZ::Vector3 forward = GetForward(); - - // check if the vectors form an orthonormal set - if (Math::Abs(right.Dot(up)) > tolerance) - { - return false; - } - if (Math::Abs(right.Dot(forward)) > tolerance) - { - return false; - } - if (Math::Abs(forward.Dot(up)) > tolerance) - { - return false; - } - - // the vector set is not orthonormal, so the matrix is not an orthogonal one - return true; - } - - - // check if the matrix is an identity matrix or not - bool Matrix::CheckIfIsIdentity(float tolerance) const - { - // for all entries - for (uint32 y = 0; y < 4; ++y) - { - for (uint32 x = 0; x < 4; ++x) - { - // if we are on the diagonal - if (x == y) - { - if (Math::Abs(1.0f - TMAT(y, x)) > tolerance) - { - return false; // if this entry on the diagonal not 1, we have no identity matrix - } - } - else // we are not on the diagonal - { - if (Math::Abs(TMAT(y, x)) > tolerance) - { - return false; // if the entry isn't equal to 0, it isn't an identity matrix - } - } - } - } - - // yup, we have an identity matrix here :) - return true; - } - - - // calculate the handedness of the matrix - float Matrix::CalcHandedness() const - { - // get the matrix vectors - AZ::Vector3 right = GetRight(); - AZ::Vector3 up = GetUp(); - AZ::Vector3 forward = GetForward(); - - // calculate the handedness (negative result means left handed, positive means right handed) - return (right.Cross(up)).Dot(forward); - } - - - // check if the matrix is right handed or not - bool Matrix::CheckIfIsRightHanded() const - { - return (CalcHandedness() <= 0.0f); - } - - - // check if the matrix is right handed or not - - bool Matrix::CheckIfIsLeftHanded() const - { - return (CalcHandedness() > 0.0f); - } - - - // check if this matrix is a pure rotation matrix or not - bool Matrix::CheckIfIsPureRotationMatrix(float tolerance) const - { - return (Math::Abs(1.0f - CalcDeterminant()) < tolerance); - } - - - // check if the matrix is reflected (mirrored) or not - bool Matrix::CheckIfIsReflective() const - { - float determinant = CalcDeterminant(); - return (determinant < 0.0f); - //return ((determinant > (-1.0 - tolerance)) && (determinant < (-1.0 + tolerance))); // if the determinant is near -1, it will reflect - } - - - // calculate the inverse transpose - void Matrix::InverseTranspose() - { - Inverse(); - Transpose(); - } - - - // return the inverse transposed version of this matrix - Matrix Matrix::InverseTransposed() const - { - Matrix result(*this); - result.InverseTranspose(); - return result; - } - - - // normalize a matrix - void Matrix::Normalize() - { - // get the current vectors - AZ::Vector3 right = GetRight(); - AZ::Vector3 up = GetUp(); - AZ::Vector3 forward = GetForward(); - - // normalize them - right.Normalize(); - up.Normalize(); - forward.Normalize(); - - // update them again with the normalized versions - SetRight(right); - SetUp(up); - SetForward(forward); - } - - - // creates a shear matrix - void Matrix::SetShearMatrix(const AZ::Vector3& s) - { - TMAT(0, 0) = 1; - TMAT(0, 1) = s.GetX(); - TMAT(0, 2) = s.GetY(); - TMAT(0, 3) = 0; - TMAT(1, 0) = 0; - TMAT(1, 1) = 1; - TMAT(1, 2) = s.GetZ(); - TMAT(1, 3) = 0; - TMAT(2, 0) = 0; - TMAT(2, 1) = 0; - TMAT(2, 2) = 1; - TMAT(2, 3) = 0; - TMAT(3, 0) = 0; - TMAT(3, 1) = 0; - TMAT(3, 2) = 0; - TMAT(3, 3) = 1; - } - - - - void Matrix::SetRotationMatrix(const AZ::Quaternion& rotation) - { - const float xx = rotation.GetX() * rotation.GetX(); - const float xy = rotation.GetX() * rotation.GetY(), yy = rotation.GetY() * rotation.GetY(); - const float xz = rotation.GetX() * rotation.GetZ(), yz = rotation.GetY() * rotation.GetZ(), zz = rotation.GetZ() * rotation.GetZ(); - const float xw = rotation.GetX() * rotation.GetW(), yw = rotation.GetY() * rotation.GetW(), zw = rotation.GetZ() * rotation.GetW(), ww = rotation.GetW() * rotation.GetW(); - - TMAT(0, 0) = +xx - yy - zz + ww; - TMAT(0, 1) = +xy + zw + xy + zw; - TMAT(0, 2) = +xz - yw + xz - yw; - TMAT(0, 3) = 0.0f; - TMAT(1, 0) = +xy - zw + xy - zw; - TMAT(1, 1) = -xx + yy - zz + ww; - TMAT(1, 2) = +yz + xw + yz + xw; - TMAT(1, 3) = 0.0f; - TMAT(2, 0) = +xz + yw + xz + yw; - TMAT(2, 1) = +yz - xw + yz - xw; - TMAT(2, 2) = -xx - yy + zz + ww; - TMAT(2, 3) = 0.0f; - TMAT(3, 0) = 0.0f; - TMAT(3, 1) = 0.0f; - TMAT(3, 2) = 0.0f; - TMAT(3, 3) = 1.0f; - } - - - // calculate a rotation matrix from two vectors - void Matrix::SetRotationMatrixTwoVectors(const AZ::Vector3& from, const AZ::Vector3& to) - { - // calculate intermediate values - const float lengths = SafeLength(to) * SafeLength(from); - const float D = (lengths > Math::epsilon) ? 1.0f / lengths : 0.0f; - const float C = (to.GetX() * from.GetX() + to.GetY() * from.GetY() + to.GetZ() * from.GetZ()) * D; - const float vzwy = (to.GetY() * from.GetZ()) - (to.GetZ() * from.GetY()); - const float wxuz = (to.GetZ() * from.GetX()) - (to.GetX() * from.GetZ()); - const float uyvx = (to.GetX() * from.GetY()) - (to.GetY() * from.GetX()); - const float A = vzwy * vzwy + wxuz * wxuz + uyvx * uyvx; - - // return identity if the cross product of the two vectors is small - if (A < Math::epsilon) - { - Identity(); - return; - } - - // set the components of the rotation matrix - const float t = (1.0f - C) / A; - TMAT(0, 0) = t * vzwy * vzwy + C; - TMAT(1, 1) = t * wxuz * wxuz + C; - TMAT(2, 2) = t * uyvx * uyvx + C; - TMAT(3, 3) = 1.0f; - TMAT(0, 1) = t * vzwy * wxuz + D * uyvx; - TMAT(0, 2) = t * vzwy * uyvx - D * wxuz; - TMAT(1, 2) = t * wxuz * uyvx + D * vzwy; - TMAT(1, 0) = t * vzwy * wxuz - D * uyvx; - TMAT(2, 0) = t * vzwy * uyvx + D * wxuz; - TMAT(2, 1) = t * wxuz * uyvx - D * vzwy; - TMAT(0, 3) = 0.0f; - TMAT(1, 3) = 0.0f; - TMAT(2, 3) = 0.0f; - TMAT(3, 0) = 0.0f; - TMAT(3, 1) = 0.0f; - TMAT(3, 2) = 0.0f; - } - - - - // output: x=pitch, y=yaw, z=roll - // reconstruction: roll*pitch*yaw (zxy) - AZ::Vector3 Matrix::CalcPitchYawRoll() const - { - const float pitch = Math::ASin(-TMAT(2, 1)); - const float cosPitch = Math::Cos(pitch); - const float threshold = 0.0001f; - float roll; - float yaw; - - if (cosPitch > threshold) - { - roll = Math::ATan2(TMAT(0, 1), TMAT(1, 1)); - yaw = Math::ATan2(TMAT(2, 0), TMAT(2, 2)); - } - else - { - roll = Math::ATan2(-TMAT(1, 0), TMAT(0, 0)); - yaw = 0.0f; - } - - return AZ::Vector3(pitch, yaw, roll); - } - - - - // init the matrix from a yaw/pitch/roll angle set - void Matrix::SetRotationMatrixPitchYawRoll(float pitch, float yaw, float roll) - { - const float cosX = Math::Cos(pitch); - const float cosY = Math::Cos(yaw); - const float cosZ = Math::Cos(roll); - const float sinX = Math::Sin(pitch); - const float sinY = Math::Sin(yaw); - const float sinZ = Math::Sin(roll); - - TMAT(0, 0) = cosZ * cosY + sinZ * sinX * sinY; - TMAT(0, 1) = sinZ * cosX; - TMAT(0, 2) = cosZ * -sinY + sinZ * sinX * cosY; - TMAT(0, 3) = 0.0f; - TMAT(1, 0) = -sinZ * cosY + cosZ * sinX * sinY; - TMAT(1, 1) = cosZ * cosX; - TMAT(1, 2) = sinZ * sinY + cosZ * sinX * cosY; - TMAT(1, 3) = 0.0f; - TMAT(2, 0) = cosX * sinY; - TMAT(2, 1) = -sinX; - TMAT(2, 2) = cosX * cosY; - TMAT(2, 3) = 0.0f; - TMAT(3, 0) = 0.0f; - TMAT(3, 1) = 0.0f; - TMAT(3, 2) = 0.0f; - TMAT(3, 3) = 1.0f; - } - - - - - // - void Matrix::DecomposeQRGramSchmidt(AZ::Vector3& translation, Matrix& rot, AZ::Vector3& scale, AZ::Vector3& shear) const - { - // build orthogonal matrix Q - float invLength = Math::InvSqrt(TMAT(0, 0) * TMAT(0, 0) + TMAT(1, 0) * TMAT(1, 0) + TMAT(2, 0) * TMAT(2, 0)); - MMAT(rot, 0, 0) = TMAT(0, 0) * invLength; - MMAT(rot, 1, 0) = TMAT(1, 0) * invLength; - MMAT(rot, 2, 0) = TMAT(2, 0) * invLength; - - float fDot = MMAT(rot, 0, 0) * TMAT(0, 1) + MMAT(rot, 1, 0) * TMAT(1, 1) + MMAT(rot, 2, 0) * TMAT(2, 1); - MMAT(rot, 0, 1) = TMAT(0, 1) - fDot * MMAT(rot, 0, 0); - MMAT(rot, 1, 1) = TMAT(1, 1) - fDot * MMAT(rot, 1, 0); - MMAT(rot, 2, 1) = TMAT(2, 1) - fDot * MMAT(rot, 2, 0); - invLength = Math::InvSqrt(MMAT(rot, 0, 1) * MMAT(rot, 0, 1) + MMAT(rot, 1, 1) * MMAT(rot, 1, 1) + MMAT(rot, 2, 1) * MMAT(rot, 2, 1)); - MMAT(rot, 0, 1) *= invLength; - MMAT(rot, 1, 1) *= invLength; - MMAT(rot, 2, 1) *= invLength; - - fDot = MMAT(rot, 0, 0) * TMAT(0, 2) + MMAT(rot, 1, 0) * TMAT(1, 2) + MMAT(rot, 2, 0) * TMAT(2, 2); - MMAT(rot, 0, 2) = TMAT(0, 2) - fDot * MMAT(rot, 0, 0); - MMAT(rot, 1, 2) = TMAT(1, 2) - fDot * MMAT(rot, 1, 0); - MMAT(rot, 2, 2) = TMAT(2, 2) - fDot * MMAT(rot, 2, 0); - fDot = MMAT(rot, 0, 1) * TMAT(0, 2) + MMAT(rot, 1, 1) * TMAT(1, 2) + MMAT(rot, 2, 1) * TMAT(2, 2); - MMAT(rot, 0, 2) -= fDot * MMAT(rot, 0, 1); - MMAT(rot, 1, 2) -= fDot * MMAT(rot, 1, 1); - MMAT(rot, 2, 2) -= fDot * MMAT(rot, 2, 1); - invLength = Math::InvSqrt(MMAT(rot, 0, 2) * MMAT(rot, 0, 2) + MMAT(rot, 1, 2) * MMAT(rot, 1, 2) + MMAT(rot, 2, 2) * MMAT(rot, 2, 2)); - MMAT(rot, 0, 2) *= invLength; - MMAT(rot, 1, 2) *= invLength; - MMAT(rot, 2, 2) *= invLength; - - // guarantee that orthogonal matrix has determinant 1 (no reflections) - float fDet = MMAT(rot, 0, 0) * MMAT(rot, 1, 1) * MMAT(rot, 2, 2) + MMAT(rot, 0, 1) * MMAT(rot, 1, 2) * MMAT(rot, 2, 0) + - MMAT(rot, 0, 2) * MMAT(rot, 1, 0) * MMAT(rot, 2, 1) - MMAT(rot, 0, 2) * MMAT(rot, 1, 1) * MMAT(rot, 2, 0) - - MMAT(rot, 0, 1) * MMAT(rot, 1, 0) * MMAT(rot, 2, 2) - MMAT(rot, 0, 0) * MMAT(rot, 1, 2) * MMAT(rot, 2, 1); - - if (fDet < 0.0f) - { - for (uint32 r = 0; r < 3; ++r) - { - for (uint32 c = 0; c < 3; ++c) - { - MMAT(rot, r, c) = -MMAT(rot, r, c); - } - } - } - - // build "right" matrix R - Matrix R; - MMAT(R, 0, 0) = MMAT(rot, 0, 0) * TMAT(0, 0) + MMAT(rot, 1, 0) * TMAT(1, 0) + MMAT(rot, 2, 0) * TMAT(2, 0); - MMAT(R, 0, 1) = MMAT(rot, 0, 0) * TMAT(0, 1) + MMAT(rot, 1, 0) * TMAT(1, 1) + MMAT(rot, 2, 0) * TMAT(2, 1); - MMAT(R, 1, 1) = MMAT(rot, 0, 1) * TMAT(0, 1) + MMAT(rot, 1, 1) * TMAT(1, 1) + MMAT(rot, 2, 1) * TMAT(2, 1); - MMAT(R, 0, 2) = MMAT(rot, 0, 0) * TMAT(0, 2) + MMAT(rot, 1, 0) * TMAT(1, 2) + MMAT(rot, 2, 0) * TMAT(2, 2); - MMAT(R, 1, 2) = MMAT(rot, 0, 1) * TMAT(0, 2) + MMAT(rot, 1, 1) * TMAT(1, 2) + MMAT(rot, 2, 1) * TMAT(2, 2); - MMAT(R, 2, 2) = MMAT(rot, 0, 2) * TMAT(0, 2) + MMAT(rot, 1, 2) * TMAT(1, 2) + MMAT(rot, 2, 2) * TMAT(2, 2); - - // the scaling component - scale.SetX(MMAT(R, 0, 0)); - scale.SetY(MMAT(R, 1, 1)); - scale.SetZ(MMAT(R, 2, 2)); - - // the shear component - const float invScaleX = 1.0f / scale.GetX(); - shear.SetX(MMAT(R, 0, 1) * invScaleX); - shear.SetY(MMAT(R, 0, 2) * invScaleX); - shear.SetZ(MMAT(R, 1, 2) / scale.GetY()); - - translation = GetTranslation(); - } - - - // - void Matrix::DecomposeQRGramSchmidt(AZ::Vector3& translation, Matrix& rot, AZ::Vector3& scale) const - { - // build orthogonal matrix Q - float invLength = Math::InvSqrt(TMAT(0, 0) * TMAT(0, 0) + TMAT(1, 0) * TMAT(1, 0) + TMAT(2, 0) * TMAT(2, 0)); - MMAT(rot, 0, 0) = TMAT(0, 0) * invLength; - MMAT(rot, 1, 0) = TMAT(1, 0) * invLength; - MMAT(rot, 2, 0) = TMAT(2, 0) * invLength; - - float fDot = MMAT(rot, 0, 0) * TMAT(0, 1) + MMAT(rot, 1, 0) * TMAT(1, 1) + MMAT(rot, 2, 0) * TMAT(2, 1); - MMAT(rot, 0, 1) = TMAT(0, 1) - fDot * MMAT(rot, 0, 0); - MMAT(rot, 1, 1) = TMAT(1, 1) - fDot * MMAT(rot, 1, 0); - MMAT(rot, 2, 1) = TMAT(2, 1) - fDot * MMAT(rot, 2, 0); - invLength = Math::InvSqrt(MMAT(rot, 0, 1) * MMAT(rot, 0, 1) + MMAT(rot, 1, 1) * MMAT(rot, 1, 1) + MMAT(rot, 2, 1) * MMAT(rot, 2, 1)); - MMAT(rot, 0, 1) *= invLength; - MMAT(rot, 1, 1) *= invLength; - MMAT(rot, 2, 1) *= invLength; - - fDot = MMAT(rot, 0, 0) * TMAT(0, 2) + MMAT(rot, 1, 0) * TMAT(1, 2) + MMAT(rot, 2, 0) * TMAT(2, 2); - MMAT(rot, 0, 2) = TMAT(0, 2) - fDot * MMAT(rot, 0, 0); - MMAT(rot, 1, 2) = TMAT(1, 2) - fDot * MMAT(rot, 1, 0); - MMAT(rot, 2, 2) = TMAT(2, 2) - fDot * MMAT(rot, 2, 0); - fDot = MMAT(rot, 0, 1) * TMAT(0, 2) + MMAT(rot, 1, 1) * TMAT(1, 2) + MMAT(rot, 2, 1) * TMAT(2, 2); - MMAT(rot, 0, 2) -= fDot * MMAT(rot, 0, 1); - MMAT(rot, 1, 2) -= fDot * MMAT(rot, 1, 1); - MMAT(rot, 2, 2) -= fDot * MMAT(rot, 2, 1); - invLength = Math::InvSqrt(MMAT(rot, 0, 2) * MMAT(rot, 0, 2) + MMAT(rot, 1, 2) * MMAT(rot, 1, 2) + MMAT(rot, 2, 2) * MMAT(rot, 2, 2)); - MMAT(rot, 0, 2) *= invLength; - MMAT(rot, 1, 2) *= invLength; - MMAT(rot, 2, 2) *= invLength; - - // guarantee that orthogonal matrix has determinant 1 (no reflections) - float fDet = MMAT(rot, 0, 0) * MMAT(rot, 1, 1) * MMAT(rot, 2, 2) + MMAT(rot, 0, 1) * MMAT(rot, 1, 2) * MMAT(rot, 2, 0) + - MMAT(rot, 0, 2) * MMAT(rot, 1, 0) * MMAT(rot, 2, 1) - MMAT(rot, 0, 2) * MMAT(rot, 1, 1) * MMAT(rot, 2, 0) - - MMAT(rot, 0, 1) * MMAT(rot, 1, 0) * MMAT(rot, 2, 2) - MMAT(rot, 0, 0) * MMAT(rot, 1, 2) * MMAT(rot, 2, 1); - - if (fDet < 0.0f) - { - for (uint32 r = 0; r < 3; ++r) - { - for (uint32 c = 0; c < 3; ++c) - { - MMAT(rot, r, c) = -MMAT(rot, r, c); - } - } - } - - // build "right" matrix R - Matrix R; - MMAT(R, 0, 0) = MMAT(rot, 0, 0) * TMAT(0, 0) + MMAT(rot, 1, 0) * TMAT(1, 0) + MMAT(rot, 2, 0) * TMAT(2, 0); - MMAT(R, 0, 1) = MMAT(rot, 0, 0) * TMAT(0, 1) + MMAT(rot, 1, 0) * TMAT(1, 1) + MMAT(rot, 2, 0) * TMAT(2, 1); - MMAT(R, 1, 1) = MMAT(rot, 0, 1) * TMAT(0, 1) + MMAT(rot, 1, 1) * TMAT(1, 1) + MMAT(rot, 2, 1) * TMAT(2, 1); - MMAT(R, 0, 2) = MMAT(rot, 0, 0) * TMAT(0, 2) + MMAT(rot, 1, 0) * TMAT(1, 2) + MMAT(rot, 2, 0) * TMAT(2, 2); - MMAT(R, 1, 2) = MMAT(rot, 0, 1) * TMAT(0, 2) + MMAT(rot, 1, 1) * TMAT(1, 2) + MMAT(rot, 2, 1) * TMAT(2, 2); - MMAT(R, 2, 2) = MMAT(rot, 0, 2) * TMAT(0, 2) + MMAT(rot, 1, 2) * TMAT(1, 2) + MMAT(rot, 2, 2) * TMAT(2, 2); - - // the scaling component - scale.SetX(MMAT(R, 0, 0)); - scale.SetY(MMAT(R, 1, 1)); - scale.SetZ(MMAT(R, 2, 2)); - - translation = GetTranslation(); - } - - - // decompose into translation and rotation - void Matrix::DecomposeQRGramSchmidt(AZ::Vector3& translation, Matrix& rot) const - { - // build orthogonal matrix Q - float invLength = Math::InvSqrt(TMAT(0, 0) * TMAT(0, 0) + TMAT(1, 0) * TMAT(1, 0) + TMAT(2, 0) * TMAT(2, 0)); - MMAT(rot, 0, 0) = TMAT(0, 0) * invLength; - MMAT(rot, 1, 0) = TMAT(1, 0) * invLength; - MMAT(rot, 2, 0) = TMAT(2, 0) * invLength; - - float fDot = MMAT(rot, 0, 0) * TMAT(0, 1) + MMAT(rot, 1, 0) * TMAT(1, 1) + MMAT(rot, 2, 0) * TMAT(2, 1); - MMAT(rot, 0, 1) = TMAT(0, 1) - fDot * MMAT(rot, 0, 0); - MMAT(rot, 1, 1) = TMAT(1, 1) - fDot * MMAT(rot, 1, 0); - MMAT(rot, 2, 1) = TMAT(2, 1) - fDot * MMAT(rot, 2, 0); - invLength = Math::InvSqrt(MMAT(rot, 0, 1) * MMAT(rot, 0, 1) + MMAT(rot, 1, 1) * MMAT(rot, 1, 1) + MMAT(rot, 2, 1) * MMAT(rot, 2, 1)); - MMAT(rot, 0, 1) *= invLength; - MMAT(rot, 1, 1) *= invLength; - MMAT(rot, 2, 1) *= invLength; - - fDot = MMAT(rot, 0, 0) * TMAT(0, 2) + MMAT(rot, 1, 0) * TMAT(1, 2) + MMAT(rot, 2, 0) * TMAT(2, 2); - MMAT(rot, 0, 2) = TMAT(0, 2) - fDot * MMAT(rot, 0, 0); - MMAT(rot, 1, 2) = TMAT(1, 2) - fDot * MMAT(rot, 1, 0); - MMAT(rot, 2, 2) = TMAT(2, 2) - fDot * MMAT(rot, 2, 0); - fDot = MMAT(rot, 0, 1) * TMAT(0, 2) + MMAT(rot, 1, 1) * TMAT(1, 2) + MMAT(rot, 2, 1) * TMAT(2, 2); - MMAT(rot, 0, 2) -= fDot * MMAT(rot, 0, 1); - MMAT(rot, 1, 2) -= fDot * MMAT(rot, 1, 1); - MMAT(rot, 2, 2) -= fDot * MMAT(rot, 2, 1); - invLength = Math::InvSqrt(MMAT(rot, 0, 2) * MMAT(rot, 0, 2) + MMAT(rot, 1, 2) * MMAT(rot, 1, 2) + MMAT(rot, 2, 2) * MMAT(rot, 2, 2)); - MMAT(rot, 0, 2) *= invLength; - MMAT(rot, 1, 2) *= invLength; - MMAT(rot, 2, 2) *= invLength; - - // guarantee that orthogonal matrix has determinant 1 (no reflections) - float fDet = MMAT(rot, 0, 0) * MMAT(rot, 1, 1) * MMAT(rot, 2, 2) + MMAT(rot, 0, 1) * MMAT(rot, 1, 2) * MMAT(rot, 2, 0) + - MMAT(rot, 0, 2) * MMAT(rot, 1, 0) * MMAT(rot, 2, 1) - MMAT(rot, 0, 2) * MMAT(rot, 1, 1) * MMAT(rot, 2, 0) - - MMAT(rot, 0, 1) * MMAT(rot, 1, 0) * MMAT(rot, 2, 2) - MMAT(rot, 0, 0) * MMAT(rot, 1, 2) * MMAT(rot, 2, 1); - - if (fDet < 0.0f) - { - for (uint32 r = 0; r < 3; ++r) - { - for (uint32 c = 0; c < 3; ++c) - { - MMAT(rot, r, c) = -MMAT(rot, r, c); - } - } - } - - translation = GetTranslation(); - } - - /* - // init from pos/rot/scale/shear - void Matrix::Set(const Vector3& translation, const AZ::Quaternion& rotation, const Vector3& scale, const Vector3& shear) - { - // convert quat to matrix - const float xx=rotation.x*rotation.x; - const float xy=rotation.x*rotation.y, yy=rotation.y*rotation.y; - const float xz=rotation.x*rotation.z, yz=rotation.y*rotation.z, zz=rotation.z*rotation.z; - const float xw=rotation.x*rotation.w, yw=rotation.y*rotation.w, zw=rotation.z*rotation.w, ww=rotation.w*rotation.w; - TMAT(0,0) = +xx-yy-zz+ww; TMAT(0,1) = +xy+zw+xy+zw; TMAT(0,2) = +xz-yw+xz-yw; TMAT(0,3) = 0.0f; - TMAT(1,0) = +xy-zw+xy-zw; TMAT(1,1) = -xx+yy-zz+ww; TMAT(1,2) = +yz+xw+yz+xw; TMAT(1,3) = 0.0f; - TMAT(2,0) = +xz+yw+xz+yw; TMAT(2,1) = +yz-xw+yz-xw; TMAT(2,2) = -xx-yy+zz+ww; TMAT(2,3) = 0.0f; - TMAT(3,0) = translation.x; TMAT(3,1) = translation.y; TMAT(3,2) = translation.z; TMAT(3,3) = 1.0f; - - // scale - TMAT(0,0) *= scale.x; - TMAT(0,1) *= scale.y; - TMAT(0,2) *= scale.z; - TMAT(1,0) *= scale.x; - TMAT(1,1) *= scale.y; - TMAT(1,2) *= scale.z; - TMAT(2,0) *= scale.x; - TMAT(2,1) *= scale.y; - TMAT(2,2) *= scale.z; - - // multiply with the shear matrix - float v[3]; - v[0] = TMAT(0,0); - v[1] = TMAT(0,1); - v[2] = TMAT(0,2); - TMAT(0,1) = v[0]*shear.x + v[1]; - TMAT(0,2) = v[0]*shear.y + v[1]*shear.z + v[2]; - - v[0] = TMAT(1,0); - v[1] = TMAT(1,1); - v[2] = TMAT(1,2); - TMAT(1,1) = v[0]*shear.x + v[1]; - TMAT(1,2) = v[0]*shear.y + v[1]*shear.z + v[2]; - - v[0] = TMAT(2,0); - v[1] = TMAT(2,1); - v[2] = TMAT(2,2); - TMAT(2,1) = v[0]*shear.x + v[1]; - TMAT(2,2) = v[0]*shear.y + v[1]*shear.z + v[2]; - - // translation - TMAT(3,0) = translation.x; - TMAT(3,1) = translation.y; - TMAT(3,2) = translation.z; - TMAT(3,3) = 1.0f; - } - */ - - //------------------------------------------------------- - /* - // decompose using QR decomposition (householder) - void Matrix::DecomposeQRHouseHolder(Vector3& outTranslation, AZ::Quaternion& outRotation, Vector3& outScale, Vector3& outShear) - { - // extract translation - outTranslation = GetTranslation(); - SetTranslation( Vector3(0.0f, 0.0f, 0.0f) ); - - // decompose into the two matrices first - Matrix Q; - Matrix R; - DecomposeQRHouseHolder(Q, R); - SetTranslation( outTranslation ); - - // extract scale - outScale.Set( MMAT(R,0,0), MMAT(R,1,1), MMAT(R,2,2) ); - - // extract shear - const float invScaleX = 1.0f / outScale.x; // TODO: handle 0 scale? - outShear.x = MMAT(R, 0, 1) * invScaleX; - outShear.y = MMAT(R, 0, 2) * invScaleX; - outShear.z = MMAT(R, 1, 2) / outScale.y; - - // convert the rotation into a AZ::Quaternion - outRotation.FromMatrix( Q ); - } - - - - // decompose using QR decomposition - void Matrix::DecomposeQRHouseHolder(Vector3& outTranslation, AZ::Quaternion& outRotation, Vector3& outScale) - { - // extract translation - outTranslation = GetTranslation(); - SetTranslation( Vector3(0.0f, 0.0f, 0.0f) ); - - // decompose into the two matrices first - Matrix Q; - Matrix R; - DecomposeQRHouseHolder(Q, R); - SetTranslation( outTranslation ); - - // extract scale - outScale.Set( MMAT(R,0,0), MMAT(R,1,1), MMAT(R,2,2) ); - - // convert the rotation into a AZ::Quaternion - outRotation.FromMatrix( Q ); - } - - - // decompose using QR decomposition - void Matrix::DecomposeQRHouseHolder(Vector3& outTranslation, AZ::Quaternion& outRotation) - { - // extract translation - outTranslation = GetTranslation(); - SetTranslation( Vector3(0.0f, 0.0f, 0.0f) ); - - // decompose into the two matrices first - Matrix Q; - Matrix R; - DecomposeQRHouseHolder(Q, R); - SetTranslation( outTranslation ); - - // convert the rotation into a AZ::Quaternion - outRotation.FromMatrix( Q ); - } - - - // decompose into Q (rotation) and R (scale/shear/translation) matrices - void Matrix::DecomposeQRHouseHolder(Matrix& Q, Matrix& R) - { - float mag; - float alpha; - Vector4 u; - Vector4 v; - Matrix P; - Matrix I; - - I.Identity(); - P.Identity(); - - Q.Identity(); - R = *this; - - for (uint32 i=0; i<4; i++) - { - u.Zero(); - v.Zero(); - - mag = 0.0f; - for (uint32 j=i; j<4; ++j) - { - u[j] = MMAT(R, j, i); - mag += u[j] * u[j]; - } - - mag = Math::SafeSqrt(mag); - alpha = u[i] < 0 ? mag : -mag; - - mag = 0.0f; - for (uint32 j=i; j<4; ++j) - { - v[j] = (j == i) ? u[j] + alpha : u[j]; - mag += v[j] * v[j]; - } - - mag = Math::SafeSqrt(mag); - if (mag < Math::epsilon) - continue; - - const float invMag = 1.0f / mag; - for (uint32 j=i; j<4; j++) - v[j] *= invMag; - - //P = I - (v * v.Transpose()) * 2.0; - P = I - OuterProduct(v, v) * 2.0f; - - //R = P * R; - //Q = Q * P; - R.MultMatrix(P, R); - Q.MultMatrix(P); - } - } - //------------------------------------------------------- - */ - - // basically does (vecA * vecB.Transposed()) and results in a 4x4 matrix - Matrix Matrix::OuterProduct(const AZ::Vector4& column, const AZ::Vector4& row) - { - Matrix result; - - for (uint32 r = 0; r < 4; ++r) - { - for (uint32 c = 0; c < 4; ++c) - { - MMAT(result, r, c) = column.GetElement(r) * row.GetElement(c); - } - } - - return result; - } -} // namespace MCore diff --git a/Gems/EMotionFX/Code/MCore/Source/Matrix4.h b/Gems/EMotionFX/Code/MCore/Source/Matrix4.h deleted file mode 100644 index 5d6da79bf5..0000000000 --- a/Gems/EMotionFX/Code/MCore/Source/Matrix4.h +++ /dev/null @@ -1,917 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - -#pragma once - -// includes -#include -#include "StandardHeaders.h" -#include "Vector.h" -#include "PlaneEq.h" -#include "LogManager.h" -#include -#include -#include - -// matrix order -#define MCORE_MATRIX_ROWMAJOR - -// matrix element access -#ifdef MCORE_MATRIX_ROWMAJOR - #define MMAT(matrix, row, col) matrix.m44[row][col] - #define TMAT(row, col) m44[row][col] -#else - #define MMAT(matrix, row, col) matrix.m44[col][row] - #define TMAT(row, col) m44[col][row] -#endif - - -namespace AZ { class Quaternion; } - -namespace MCore -{ - /** - * Depracated. Please use AZ::Transform instead. - * A 4x4 matrix class. - * Matrices can for example be used to transform points or vectors. - * Transforming means moving to another coordinate system. With matrices you can do things like: translate (move), rotate and scale. - * One single matrix can store a translation, rotation and scale. If we have only a rotation inside the matrix, this means that if we - * multiply the matrix with a vector, the vector will rotate by the rotation inside the matrix! The cool thing is that you can also - * concatenate matrices. In other words, you can multiply matrices with eachother. If you have a rotation matrix, like described above, and - * also have a translation matrix, then multiplying these two matrices with eachother will result in a new matrix, which contains both the - * rotation and the translation! So when you multiply this resulting matrix with a vector, it will both translate and rotate. - * But, does it first rotate and then translate in the rotated space? Or does it first translate and then rotate? - * For example if you want to rotate a planet, while it's moving, you want to rotate it in it's local coordinate system. Like when you spin - * a globe you can have on your desk. So where it spins around it's own center. However, if the planet is at location (10,10,10) in 3D space for example - * it is also possible that rotates around the origin in world space (0,0,0). The order of multiplication between matrices matters. - * This means that (matrixA * matrixB) does not have to not result in the same as (matrixB * matrixA). - * - * Here is some information about how the matrices are stored internally: - * - * [00 01 02 03] // m16 offsets
- * [04 05 06 07]
- * [08 09 10 11]
- * [12 13 14 15]
- * - * [00 01 02 03] // m44 offsets --> [row][column]
- * [10 11 12 13]
- * [20 21 22 23]
- * [30 31 32 33]
- * - * [Xx Xy Xz 0] // right
- * [Yx Yy Yz 0] // up
- * [Zx Zy Zz 0] // forward
- * [Tx Ty Tz 1] // translation
- * - */ - class MCORE_API alignas(16) Matrix - { - public: - /** - * Default constructor. - * This leaves the matrix uninitialized. - */ - MCORE_INLINE Matrix() {} - - /** - * Init the matrix using given float data. - * The number of elements stored at the float pointer location that is used as parameter must be at least 16 floats in size. - * @param elementData A pointer to the matrix float data, which must be 16 floats in size, or more, although only the first 16 floats are used. - */ - MCORE_INLINE explicit Matrix(const float* elementData) { MCore::MemCopy(m_m16, elementData, sizeof(float) * 16); } - - /** - * Copy constructor. - * @param m The matrix to copy the data from. - */ - MCORE_INLINE Matrix(const Matrix& m); - - MCORE_INLINE Matrix(const AZ::Matrix4x4& m) - { - TMAT(0, 0) = m.GetElement(0, 0); - TMAT(0, 1) = m.GetElement(0, 1); - TMAT(0, 2) = m.GetElement(0, 2); - TMAT(0, 3) = m.GetElement(0, 3); - TMAT(1, 0) = m.GetElement(1, 0); - TMAT(1, 1) = m.GetElement(1, 1); - TMAT(1, 2) = m.GetElement(1, 2); - TMAT(1, 3) = m.GetElement(1, 3); - TMAT(2, 0) = m.GetElement(2, 0); - TMAT(2, 1) = m.GetElement(2, 1); - TMAT(2, 2) = m.GetElement(2, 2); - TMAT(2, 3) = m.GetElement(2, 3); - TMAT(3, 0) = m.GetElement(3, 0); - TMAT(3, 1) = m.GetElement(3, 1); - TMAT(3, 2) = m.GetElement(3, 2); - TMAT(3, 3) = m.GetElement(3, 3); - } - - void InitFromPosRot(const AZ::Vector3& pos, const AZ::Quaternion& rot); - void InitFromPosRotScale(const AZ::Vector3& pos, const AZ::Quaternion& rot, const AZ::Vector3& scale); - void InitFromNoScaleInherit(const AZ::Vector3& translation, const AZ::Quaternion& rotation, const AZ::Vector3& scale, const AZ::Vector3& invParentScale); - void InitFromPosRotScaleScaleRot(const AZ::Vector3& pos, const AZ::Quaternion& rot, const AZ::Vector3& scale, const AZ::Quaternion& scaleRot); - void InitFromPosRotScaleShear(const AZ::Vector3& pos, const AZ::Quaternion& rot, const AZ::Vector3& scale, const AZ::Vector3& shear); - - /** - * Sets the matrix to identity. - * When a matrix is an identity matrix it will have no influence. - */ - void Identity(); - - /** - * Makes the matrix a scaling matrix. - * Values of 1.0 would have no influence on the scale. Values of for example 2.0 would scale up by a factor of two. - * @param s The vector containing the scale values for each axis. - */ - void SetScaleMatrix(const AZ::Vector3& s); - - /** - * Makes this matrix a shear matrix from three different shear matrices: XY, XZ and YZ. - * The multiplication order is YZ * XZ * XY. - * @param s The shear values (x=XY, y=XZ, z=YZ) - */ - void SetShearMatrix(const AZ::Vector3& s); - - /** - * Makes this matrix a translation matrix. - * @param t The translation value. - */ - void SetTranslationMatrix(const AZ::Vector3& t); - - /** - * Initialize this matrix into a rotation matrix from a AZ::Quaternion. - * @param rotation The AZ::Quaternion representing the rotatation. - */ - void SetRotationMatrix(const AZ::Quaternion& rotation); - - /** - * Makes the matrix an rotation matrix along the x-axis. - * @param angle The angle to rotate around this axis, in radians. - */ - void SetRotationMatrixX(float angle); - - /** - * Makes the matrix a rotation matrix along the y-axis. - * @param angle The angle to rotate around this axis, in radians. - */ - void SetRotationMatrixY(float angle); - - /** - * Makes the matrix a rotation matrix along the z-axis. - * @param angle The angle to rotate around this axis, in radians. - */ - void SetRotationMatrixZ(float angle); - - /** - * Makes the matrix a rotation matrix around a given axis with a given angle. - * @param axis The axis to rotate around. - * @param angle The angle to rotate around this axis, in radians. - */ - void SetRotationMatrixAxisAngle(const AZ::Vector3& axis, float angle); - - /** - * Makes the matrix a rotation matrix given the euler angles. - * The multiplication order is RotMatrix(v.z) * RotMatrix(v.y) * RotMatrix(v.x). - * @param anglevec The vector containing the angles for each axis, in radians, so (pitch, yaw, roll) as (x,y,z). - */ - void SetRotationMatrixEulerZYX(const AZ::Vector3& anglevec); - - /** - * Initialize the matrix from a yaw, pitch and roll. - * Pitch is the rotation around the x-axis. - * Yaw is the rotation aroudn the y-axis. - * Roll is the rotation around the z-axis. - * All angles are in radians. - * @param pitch The pitch angle (rotation around x-axis), in radians. - * @param yaw The yaw angle (rotation around y-axis), in radians. - * @param roll The roll angle (rotation around z-axis), in radians. - */ - void SetRotationMatrixPitchYawRoll(float pitch, float yaw, float roll); - - /** - * Initialize the matrix from a yaw, pitch and roll. - * Pitch is the rotation around the x-axis. - * Yaw is the rotation aroudn the y-axis. - * Roll is the rotation around the z-axis. - * All angles are in radians. - * @param angles The angle for each axis, in radians. - */ - MCORE_INLINE void SetRotationMatrixPitchYawRoll(const AZ::Vector3& angles) { SetRotationMatrixPitchYawRoll(angles.GetX(), angles.GetY(), angles.GetZ()); } - - /** - * Makes the matrix a rotation matrix given the euler angles. - * The multiplication order is RotMatrix(v.x) * RotMatrix(v.y) * RotMatrix(v.z). - * @param anglevec The vector containing the angles for each axis, in radians, so (pitch, yaw, roll) as (x,y,z). - */ - void SetRotationMatrixEulerXYZ(const AZ::Vector3& anglevec); - - /** - * Inverse rotate a vector with this matrix. - * This means that the vector will be multiplied with the inverse rotation of this matrix. - * @param v The vector to rotate. - * @result The rotated vector. - */ - AZ::Vector3 InverseRot(const AZ::Vector3& v); - - /** - * Multiply this matrix with another matrix and stores the result in itself. - * @param right The matrix to multiply with. - */ - void MultMatrix(const Matrix& right); - - /** - * Multiply this matrix with another matrix, but only multiply the 4x3 part. - * So treat the other matrix as 4x3 matrix instead of 4x4 matrix. Stores the result in itself. - * @param right The matrix to multiply with. - */ - void MultMatrix4x3(const Matrix& right); - - /** - * Multiply two matrices together, but only the 4x3 part, and store the result in itself. - * @param left The left matrix. - * @param right The right matrix. - */ - void MultMatrix4x3(const Matrix& left, const Matrix& right); - - /** - * Multiply the left matrix with the right matrix and store the result in this matrix object. - * So basically this is a fast version of:
- *
-         * Matrix result = left * right;    // where left and right are also Matrix objects
-         * 
- * - * @param left The left matrix of the matrix multiply. - * @param right The right matrix of the matrix multiply. - */ - void MultMatrix(const Matrix& left, const Matrix& right); - - /** - * Multiply this matrix with the 3x3 rotation part of the other given matrix, and modify itself. - * @param right The matrix to multiply with. - */ - void MultMatrix3x3(const Matrix& right); - - MCORE_INLINE void Skin(const AZ::Vector3* inPos, const AZ::Vector3* inNormal, AZ::Vector3* outPos, AZ::Vector3* outNormal, float weight); - MCORE_INLINE void Skin(const AZ::Vector3* inPos, const AZ::Vector3* inNormal, const AZ::Vector4* inTangent, AZ::Vector3* outPos, AZ::Vector3* outNormal, AZ::Vector4* outTangent, float weight); - MCORE_INLINE void Skin(const AZ::Vector3* inPos, const AZ::Vector3* inNormal, const AZ::Vector4* inTangent, const AZ::Vector3* inBitangent, AZ::Vector3* outPos, AZ::Vector3* outNormal, AZ::Vector4* outTangent, AZ::Vector3* outBitangent, float weight); - - /** - * Perform skinning on an input vertex, and add the result to the output, weighted by a weight value. - * The calculation performed is: - * - *
-         * out += (in * thisMatrix) * weight;
-         * 
- * - * Only the 4x3 part of the matrix is used during the matrix multiply. - * So this should be used when skinning for example positions. - * @param in The input vector to skin. - * @param out The output vector. Keep in mind that the result will be added to the output vector. - * @param weight The weight value. - */ - MCORE_INLINE void Skin4x3(const AZ::Vector3& in, AZ::Vector3& out, float weight); - - /** - * Perform skinning on an input vertex, and add the result to the output, weighted by a weight value. - * The calculation performed is: - * - *
-         * out += (in * thisMatrix) * weight;
-         * 
- * - * Only the 3x3 part of the matrix is used during the matrix multiply. - * So this should be used to skin normals and tangents. - * @param in The input vector to skin. - * @param out The output vector. Keep in mind that the result will be added to the output vector. - * @param weight The weight value. - */ - MCORE_INLINE void Skin3x3(const AZ::Vector3& in, AZ::Vector3& out, float weight); - - /** - * Transpose the matrix (swap rows with columns). - */ - void Transpose(); - - /** - * Transpose the translation 1x3 translation part. - * Leaves the rotation in tact. - */ - void TransposeTranslation(); - - /** - * Adjoint this matrix. - */ - void Adjoint(); - - /** - * Inverse this matrix. - */ - void Inverse(); - - /** - * Makes this the inverse tranpose version of this matrix. - * The inverse transpose is the transposed version of the inverse. - */ - MCORE_INLINE void InverseTranspose(); - - /** - * Returns the inverse transposed version of this matrix. - * The inverse transpose is the transposed version of the inverse. - * @result The inverse transposed version of this matrix. - */ - MCORE_INLINE Matrix InverseTransposed() const; - - /** - * Orthonormalize this matrix (to prevent skewing or other errors). - * This normalizes the x, y and z vectors of the matrix. - * It makes sure that the axis vectors are perpendicular to eachother. - */ - void OrthoNormalize(); - - /** - * Normalizes the matrix, which means that all axis vectors (right, up, forward) - * will be made of unit length. - */ - void Normalize(); - - /** - * Returns a normalized version of this matrix. - * @result The normalized version of this matrix, where the right, up and forward vectors are of unit length. - */ - MCORE_INLINE Matrix Normalized() const; - - /** - * Scale this matrix. - * @param scale The scale factors for each axis. - */ - MCORE_INLINE void Scale(const AZ::Vector3& scale); - - /** - * Scale only the upper left 3x3 part of this matrix. - * So this doesn't scale the translation part. - * @param scale The scale factors for each axis. - */ - void Scale3x3(const AZ::Vector3& scale); - - AZ::Vector3 ExtractScale(); - - /** - * Rotate this matrix around the x-axis. - * @param angle The rotation in radians. - */ - void RotateX(float angle); - - /** - * Rotate this matrix around the y-axis. - * @param angle The rotation in radians. - */ - void RotateY(float angle); - - /** - * Rotate this matrix around the z-axis. - * @param angle The rotation in radians. - */ - void RotateZ(float angle); - - /** - * Initialize the matrix as a rotation matrix given two vectors. The resulting matrix rotates the vector 'from' such that it points - * in the same direction as the vector 'to'. - * @param from The vector that the resulting matrix rotates from. - * @param to The vector that the resulting matrix rotates to. - */ - void SetRotationMatrixTwoVectors(const AZ::Vector3& from, const AZ::Vector3& to); - - /** - * Multiply a vector with the 3x3 rotation part of this matrix. - * @param v The vector to transform. - * @result The transformed (rotated) vector. - */ - MCORE_INLINE AZ::Vector3 Mul3x3(const AZ::Vector3& v) const; - - /** - * Returns the inversed version of this matrix. - * @result The inversed version of this matrix. - */ - MCORE_INLINE Matrix Inversed() const { Matrix m(*this); m.Inverse(); return m; } - - /** - * Returns the transposed version of this matrix. - * @result The transposed version of this matrix. - */ - MCORE_INLINE Matrix Transposed() const { Matrix m(*this); m.Transpose(); return m; } - - /** - * Returns the adjointed version of this matrix. - * @result The adjointed version of this matrix. - */ - MCORE_INLINE Matrix Adjointed() const { Matrix m(*this); m.Adjoint(); return m; } - - /** - * Translate the matrix. - * @param x The number of units to add to the current translation along the x-axis. - * @param y The number of units to add to the current translation along the y-axis. - * @param z The number of units to add to the current translation along the z-axis. - */ - MCORE_INLINE void Translate(float x, float y, float z) { TMAT(3, 0) += x; TMAT(3, 1) += y; TMAT(3, 2) += z; } - - /** - * Translate the matrix. - * @param t The vector containing the translation to add to the current translation of the matrix. - */ - MCORE_INLINE void Translate(const AZ::Vector3& t) { TMAT(3, 0) += t.GetX(); TMAT(3, 1) += t.GetY(); TMAT(3, 2) += t.GetZ(); } - - /** - * Set the values for a given row, using a 3D vector. - * Only the first 3 values on the row will be touched, so the 4th value will remain untouched inside the specified row of the matrix. - * @param row A zero-based index of the row. - * @param value The values to set in the row. - */ - MCORE_INLINE void SetRow(uint32 row, const AZ::Vector3& value) { TMAT(row, 0) = value.GetX(); TMAT(row, 1) = value.GetY(); TMAT(row, 2) = value.GetZ(); } - - /** - * Set the values in the given row, using a 4D vector. - * @param row A zero-based index of the row. - * @param value The values to set in the row. - */ - MCORE_INLINE void SetRow(uint32 row, const AZ::Vector4& value) { TMAT(row, 0) = value.GetX(); TMAT(row, 1) = value.GetY(); TMAT(row, 2) = value.GetZ(); TMAT(row, 3) = value.GetW(); } - - /** - * Set the values for a given column, using a 3D vector. - * Only the first 3 values on the column will be touched, so the 4th value will remain untouched inside the specified column of the matrix. - * @param column A zero-based index of the column. - * @param value The values to set in the column. - */ - MCORE_INLINE void SetColumn(uint32 column, const AZ::Vector3& value) { TMAT(0, column) = value.GetX(); TMAT(1, column) = value.GetY(); TMAT(2, column) = value.GetZ(); } - - /** - * Set the values for a given column, using a 4D vector. - * @param column A zero-based index of the column. - * @param value The values to set in the column. - */ - MCORE_INLINE void SetColumn(uint32 column, const AZ::Vector4& value) { TMAT(0, column) = value.GetX(); TMAT(1, column) = value.GetY(); TMAT(2, column) = value.GetZ(); TMAT(3, column) = value.GetW(); } - - /** - * Get the values of a given row as 3D vector. - * @param row A zero-based index of the row number ot get. - * @result The vector containing the values of the specified row. - */ - MCORE_INLINE AZ::Vector3 GetRow(uint32 row) const { return AZ::Vector3(TMAT(row, 0), TMAT(row, 1), TMAT(row, 2)); } - - /** - * Get the values of a given row as 4D vector. - * @param column A zero-based index of the row number ot get. - * @result The vector containing the values of the specified row. - */ - MCORE_INLINE AZ::Vector3 GetColumn(uint32 column) const { return AZ::Vector3(TMAT(0, column), TMAT(1, column), TMAT(2, column)); } - - /** - * Get the values of a given column as 3D vector. - * @param row A zero-based index of the column number ot get. - * @result The vector containing the values of the specified column. - */ - MCORE_INLINE AZ::Vector4 GetRow4D(uint32 row) const { return AZ::Vector4(TMAT(row, 0), TMAT(row, 1), TMAT(row, 2), TMAT(row, 3)); } - - /** - * Get the values of a given column as 4D vector. - * @param column A zero-based index of the column number ot get. - * @result The vector containing the values of the specified column. - */ - MCORE_INLINE AZ::Vector4 GetColumn4D(uint32 column) const { return AZ::Vector4(TMAT(0, column), TMAT(1, column), TMAT(2, column), TMAT(3, column)); } - - /** - * Set the right vector (must be normalized). - * @param xx The x component of the right vector. - * @param xy The y component of the right vector. - * @param xz The z component of the right vector. - */ - MCORE_INLINE void SetRight(float xx, float xy, float xz); - - /** - * Set the right vector. - * @param x The right vector, must be normalized. - */ - MCORE_INLINE void SetRight(const AZ::Vector3& x); - - /** - * Set the up vector (must be normalized). - * @param yx The x component of the up vector. - * @param yy The y component of the up vector. - * @param yz The z component of the up vector. - */ - MCORE_INLINE void SetUp(float yx, float yy, float yz); - - /** - * Set the up vector (must be normalized). - * @param y The up vector. - */ - MCORE_INLINE void SetUp(const AZ::Vector3& y); - - /** - * Set the forward vector (must be normalized). - * @param zx The x component of the forward vector. - * @param zy The y component of the forward vector. - * @param zz The z component of the forward vector. - */ - MCORE_INLINE void SetForward(float zx, float zy, float zz); - - /** - * Set the forward vector (must be normalized). - * @param z The forward vector. - */ - MCORE_INLINE void SetForward(const AZ::Vector3& z); - - /** - * Set the translation part of the matrix. - * @param tx The translation along the x-axis. - * @param ty The translation along the y-axis. - * @param tz The translation along the z-axis. - */ - MCORE_INLINE void SetTranslation(float tx, float ty, float tz); - - /** - * Set the translation part of the matrix. - * @param t The translation vector. - */ - MCORE_INLINE void SetTranslation(const AZ::Vector3& t); - - /** - * Get the right vector. - * @result The right vector (x-axis). - */ - MCORE_INLINE AZ::Vector3 GetRight() const; - - /** - * Get the up vector. - * @result The up vector (z-axis). - */ - MCORE_INLINE AZ::Vector3 GetUp() const; - - /** - * Get the forward vector. - * @result The forward vector (y-axis). - */ - MCORE_INLINE AZ::Vector3 GetForward() const; - - /** - * Get the translation part of the matrix. - * @result The vector containing the translation. - */ - MCORE_INLINE AZ::Vector3 GetTranslation() const; - - /** - * Calculates the determinant of the matrix. - * @result The determinant. - */ - float CalcDeterminant() const; - - /** - * Calculates the euler angles. - * @result The euler angles, describing the rotation along each axis, in radians. - */ - AZ::Vector3 CalcEulerAngles() const; - - /** - * Calculate the pitch, yaw and roll. - * Pitch is the rotation around the x axis. - * Yaw is the rotation around the y axis. - * Roll is the rotation around the z axis. - * All angles returned are in radians. - * @result The vector containing the rotation around each axis (x=pitch, y=yaw, z=roll). - */ - AZ::Vector3 CalcPitchYawRoll() const; - - /** - * Makes this matrix a mirrored version of a specified matrix. - * After executing this operation this matrix is the mirrored version of the specified matrix. - * @param transform The transformation matrix to mirror (so the original matrix). - * @param plane The plane to use as mirror. - */ - void Mirror(const Matrix& transform, const PlaneEq& plane); - - /** - * Makes this matrix a lookat matrix (also known as camera or view matrix). - * @param view The view position, so the position of the camera. - * @param target The target position, so where the camera is looking at. - * @param up The up vector, describing the roll of the camera, where (0,1,0) would mean the camera is straight up and has no roll and - * where (0,-1,0) would mean the camera is upside down, etc. - */ - void LookAt(const AZ::Vector3& view, const AZ::Vector3& target, const AZ::Vector3& up); - - /** - * Makes this matrix a lookat matrix (also known as camera or view matrix), in right handed mode. - * @param view The view position, so the position of the camera. - * @param target The target position, so where the camera is looking at. - * @param up The up vector, describing the roll of the camera, where (0,1,0) would mean the camera is straight up and has no roll and - * where (0,-1,0) would mean the camera is upside down, etc. - */ - void LookAtRH(const AZ::Vector3& view, const AZ::Vector3& target, const AZ::Vector3& up); - - /** - * Makes this matrix a perspective projection matrix. - * @param fov The field of view, in radians. - * @param aspect The aspect ratio which is the width divided by height. - * @param zNear The distance to the near plane. - * @param zFar The distance to the far plane. - */ - void Perspective(float fov, float aspect, float zNear, float zFar); - - /** - * Makes this matrix a perspective projection matrix, in right handed mode. - * @param fov The field of view, in radians. - * @param aspect The aspect ratio which is the width divided by height. - * @param zNear The distance to the near plane. - * @param zFar The distance to the far plane. - */ - void PerspectiveRH(float fov, float aspect, float zNear, float zFar); - - /** - * Makes this matrix an ortho projection matrix, so without perspective. - * @param left The left of the image plane. - * @param right The right of the image plane. - * @param top The top of the image plane. - * @param bottom The bottom of the image plane. - * @param znear The distance to the near plane. - * @param zfar The distance to the far plane. - */ - void Ortho(float left, float right, float top, float bottom, float znear, float zfar); - - /** - * Makes this matrix an ortho projection matrix, so without perspective. - * @param left The left of the image plane. - * @param right The right of the image plane. - * @param top The top of the image plane. - * @param bottom The bottom of the image plane. - * @param znear The distance to the near plane. - * @param zfar The distance to the far plane. - */ - void OrthoRH(float left, float right, float top, float bottom, float znear, float zfar); - - /** - * Makes this matrix an ortho projection matrix, so without perspective. - * @param left The left of the image plane. - * @param right The right of the image plane. - * @param top The top of the image plane. - * @param bottom The bottom of the image plane. - * @param znear The distance to the near plane. - * @param zfar The distance to the far plane. - */ - void OrthoOffCenter(float left, float right, float top, float bottom, float znear, float zfar); - - /** - * Makes this matrix an ortho projection matrix, so without perspective. - * @param left The left of the image plane. - * @param right The right of the image plane. - * @param top The top of the image plane. - * @param bottom The bottom of the image plane. - * @param znear The distance to the near plane. - * @param zfar The distance to the far plane. - */ - void OrthoOffCenterRH(float left, float right, float top, float bottom, float znear, float zfar); - - /** - * Makes this matrix a frustum matrix. - * @param left The left of the image plane. - * @param right The right of the image plane. - * @param top The top of the image plane. - * @param bottom The bottom of the image plane. - * @param znear The distance to the near plane. - * @param zfar The distance to the far plane. - */ - void Frustum(float left, float right, float top, float bottom, float znear, float zfar); - - - // QR Gram-Schmidt decomposition - void DecomposeQRGramSchmidt(AZ::Vector3& translation, Matrix& rot) const; - void DecomposeQRGramSchmidt(AZ::Vector3& translation, Matrix& rot, AZ::Vector3& scale) const; - void DecomposeQRGramSchmidt(AZ::Vector3& translation, Matrix& rot, AZ::Vector3& scale, AZ::Vector3& shear) const; - - static Matrix OuterProduct(const AZ::Vector4& column, const AZ::Vector4& row); - - /** - * Get the handedness of the matrix, which described if the matrix is left- or right-handed. - * The value returned by this method is the dot product between the forward vector and the result of the - * cross product between the right and up vector. So: DotProduct( Cross(right, up), forward ); - * If the value returned by this method is positive we are dealing with a matrix which is in a right-handed - * coordinate system, otherwise we are dealing with a left-handed coordinate system. - * Performing an odd number of reflections reverses the handedness. An even number of reflections is always - * equivalent to a rotation, so any series of reflections can always be regarded as a single rotation followed - * by at most one reflection. - * If a reflection is present (think of a mirror) the handedness will be reversed. A reflection can be detected - * by looking at the determinant of the matrix. If the determinant is negative, then a reflection is present. - * @result The handedness of the matrix. If this value is positive we are dealing with a matrix in a right handed - * coordinate system. Otherwise we are dealing with one in a left-handed coordinate system. - * @see IsRightHanded() - * @see IsLeftHanded() - */ - float CalcHandedness() const; - - /** - * Check if this matrix is symmetric or not. - * A materix is said to be symmetric if and only if M(i, j) = M(j, i). - * That is, a matrix whose entries are symmetric about the main diagonal. - * @param tolerance The maximum difference tolerance between the M(i, j) and M(j, i) entries. - * The reason for having this tolerance is of course floating point inaccuracy which might have - * caused some entries to be a bit different. - * @result Returns true when the matrix is symmetric, or false when not. - */ - bool CheckIfIsSymmetric(float tolerance = 0.00001f) const; - - /** - * Check if this matrix is a diagonal matrix or not. - * A matrix is said to be a diagonal matrix when only the entries on the diagonal contain non-zero values. - * The tolerance value is needed because of possible floating point inaccuracies. - * @param tolerance The maximum difference between 0 and the entry on the diagonal. - * @result Returns true when the matrix is a diagonal matrix, otherwise false is returned. - */ - bool CheckIfIsDiagonal(float tolerance = 0.00001f) const; - - /** - * Check if the matrix is orthogonal or not. - * A matrix is orthogonal if the vectors in the matrix form an orthonormal set. - * This is when the vectors (right, up and forward) are perpendicular to eachother. - * If a matrix is orthogonal, the inverse of the matrix is equal to the transpose of the matrix. - * This assumption can be used to optimize specific calculations, since the inverse is slower to calculate than - * the transpose of the matrix. Also it can speed up by transforming normals with the matrix. - * In that example instead of having to use the inverse transpose matrix, you could just use the transpose of the matrix. - * @param tolerance The maximum tolerance in the orthonormal test. - * @result Returns true when the matrix is orthogonal, otherwise false is returned. - */ - bool CheckIfIsOrthogonal(float tolerance = 0.00001f) const; - - /** - * Check if the matrix is an identity matrix or not. - * @param tolerance The maximum error value per entry in the matrix. - * @result Returns true if this matrix is an identity matrix, otherwise false is returned. - */ - bool CheckIfIsIdentity(float tolerance = 0.00001f) const; - - /** - * Check if the matrix is left handed or not. - * @result Returns true when the matrix is left handed, otherwise false is returned (so then it is right handed). - */ - bool CheckIfIsLeftHanded() const; - - /** - * Check if the matrix is right handed or not. - * @result Returns true when the matrix is right handed, otherwise false is returned (so then it is left handed). - */ - bool CheckIfIsRightHanded() const; - - /** - * Check if this matrix is a pure rotation matrix or not. - * @param tolerance The maximum error in the measurement. - * @result Returns true when the matrix represents only a rotation, otherwise false is returned. - */ - bool CheckIfIsPureRotationMatrix(float tolerance = 0.00001f) const; - - /** - * Check if this matrix contains a reflection or not. - * @result Returns true when the matrix represents a reflection, otherwise false is returned. - */ - bool CheckIfIsReflective() const; - - AZ::Matrix4x4 ToAzMatrix() const - { -#ifdef MCORE_MATRIX_ROWMAJOR - return AZ::Matrix4x4::CreateFromRowMajorFloat16(m_m16); -#else - return AZ::Matrix4x4::CreateFromColumnMajorFloat16(m16); -#endif - } - - /** - * Prints the matrix into the logfile or debug output, using MCore::LogDetailedInfo(). - * Please note that the values are printed using floats or doubles. So it is not possible - * to use this method for printing matrices of vectors or something other than real numbers. - */ - void Log() const; - - /** - * Returns a translation matrix. - * @param v The translation of the matrix. - * @result The translation matrix having the specified translation. - */ - static MCORE_INLINE Matrix TranslationMatrix(const AZ::Vector3& v) { Matrix m; m.SetTranslationMatrix(v); return m; } - - /** - * Returns a rotation matrix from a AZ::Quaternion. - * @param rot The AZ::Quaternion that represents the rotation. - * @result A rotation matrix. - */ - static MCORE_INLINE Matrix RotationMatrix(const AZ::Quaternion& rot) { Matrix m; m.SetRotationMatrix(rot); return m; } - - /** - * Returns a rotation matrix, including a translation, where the rotation is represented by a AZ::Quaternion. - * @param rot The AZ::Quaternion that represents the rotation. - * @param trans The translation of the matrix. - * @result The rotation matrix, that includes a translation as well. - */ - static MCORE_INLINE Matrix RotationTranslationMatrix(const AZ::Quaternion& rot, const AZ::Vector3& trans) { Matrix m; m.InitFromPosRot(trans, rot); return m; } - - /** - * Returns a rotation matrix along the x-axis. - * @param rad The angle of rotation, in radians. - * @result A rotation matrix. - */ - static MCORE_INLINE Matrix RotationMatrixX(float rad) { Matrix m; m.SetRotationMatrixX(rad); return m; } - - /** - * Returns a rotation matrix along the y-axis. - * @param rad The angle of rotation, in radians. - * @result A rotation matrix. - */ - static MCORE_INLINE Matrix RotationMatrixY(float rad) { Matrix m; m.SetRotationMatrixY(rad); return m; } - - /** - * Returns a rotation matrix along the z-axis. - * @param rad The angle of rotation, in radians. - * @result A rotation matrix. - */ - static MCORE_INLINE Matrix RotationMatrixZ(float rad) { Matrix m; m.SetRotationMatrixZ(rad); return m; } - - /** - * Returns a rotation matrix along the x, y and z-axis. - * The multiplication order is RotMatrix(v.x) * RotMatrix(v.y) * RotMatrix(v.z). - * @param eulerAngles The euler angles in radians. - * @result A rotation matrix. - */ - static MCORE_INLINE Matrix RotationMatrixEulerXYZ(const AZ::Vector3& eulerAngles) { Matrix m; m.SetRotationMatrixEulerXYZ(eulerAngles); return m; } - - /** - * Returns a rotation matrix along the x, y and z-axis. - * The multiplication order is RotMatrix(v.z) * RotMatrix(v.y) * RotMatrix(v.x). - * @param eulerAngles The euler angles in radians. - * @result A rotation matrix. - */ - static MCORE_INLINE Matrix RotationMatrixEulerZYX(const AZ::Vector3& eulerAngles) { Matrix m; m.SetRotationMatrixEulerZYX(eulerAngles); return m; } - - /** - * Returns a rotation matrix given a pitch, yaw and roll. - * Pitch is the rotation around the x-axis. - * Yaw is the rotation aroudn the y-axis. - * Roll is the rotation around the z-axis. - * @param angles The rotation angles for each axis, in radians. - * @result A rotation matrix. - */ - static MCORE_INLINE Matrix RotationMatrixPitchYawRoll(const AZ::Vector3& angles) { Matrix m; m.SetRotationMatrixPitchYawRoll(angles); return m; } - - /** - * Constructs a rotation matrix given two vectors. The resulting matrix rotates the vector 'from' such that it points - * in the same direction as the vector 'to'. - * @param from The vector that the resulting matrix rotates to. - * @param to The vector that the resulting matrix rotates from. - * @result The rotation matrix that rotates the vector 'from' into the vector 'to'. - */ - static MCORE_INLINE Matrix RotationMatrixTwoVectors(const AZ::Vector3& from, const AZ::Vector3& to) { Matrix m; m.SetRotationMatrixTwoVectors(from, to); return m; } - - /** - * Returns a rotation matrix from a given axis and angle. - * @param axis The axis to rotate around. - * @param angle The angle of rotation, in radians. - * @result A rotation matrix. - */ - static MCORE_INLINE Matrix RotationMatrixAxisAngle(const AZ::Vector3& axis, float angle) { Matrix m; m.SetRotationMatrixAxisAngle(axis, angle); return m; } - - /** - * Returns a scale matrix from a given scaling factor. - * @param s The vector containing the scaling factors for each axis. - * @result A scaling matrix. - */ - static MCORE_INLINE Matrix ScaleMatrix(const AZ::Vector3& s) { Matrix m; m.SetScaleMatrix(s); return m; } - - /** - * Returns a shear matrix created from three different shear matrices: XY, XZ and YZ. - * The multiplication order is YZ * XZ * XY. - * @param s The shear values (x=XY, y=XZ, z=YZ) - * @result The shear matrix. - */ - static MCORE_INLINE Matrix ShearMatrix(const AZ::Vector3& s) { Matrix m; m.SetShearMatrix(s); return m; } - - // operators - Matrix operator + (const Matrix& right) const; - Matrix operator - (const Matrix& right) const; - Matrix operator * (const Matrix& right) const; - Matrix operator * (float value) const; - Matrix& operator += (const Matrix& right); - Matrix& operator -= (const Matrix& right); - Matrix& operator *= (const Matrix& right); - Matrix& operator *= (float value); - MCORE_INLINE void operator = (const Matrix& right); - - // attributes - union - { - float m_m16[16]; // 16 floats as 1D array - float m44[4][4]; // as 2D array - }; - }; - - - // include inline code -#include "Matrix4.inl" -} // namespace MCore diff --git a/Gems/EMotionFX/Code/MCore/Source/Matrix4.inl b/Gems/EMotionFX/Code/MCore/Source/Matrix4.inl deleted file mode 100644 index 99900abcee..0000000000 --- a/Gems/EMotionFX/Code/MCore/Source/Matrix4.inl +++ /dev/null @@ -1,330 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - -MCORE_INLINE Matrix::Matrix(const Matrix& m) -{ - MCore::MemCopy(m_m16, m.m_m16, sizeof(Matrix)); -} - - -MCORE_INLINE void Matrix::operator = (const Matrix& right) -{ - MCore::MemCopy(m_m16, right.m_m16, sizeof(Matrix)); -} - - - -MCORE_INLINE void Matrix::SetRight(float xx, float xy, float xz) -{ - TMAT(0, 0) = xx; - TMAT(0, 1) = xy; - TMAT(0, 2) = xz; -} - - - -MCORE_INLINE void Matrix::SetUp(float yx, float yy, float yz) -{ - TMAT(1, 0) = yx; - TMAT(1, 1) = yy; - TMAT(1, 2) = yz; -} - - - -MCORE_INLINE void Matrix::SetForward(float zx, float zy, float zz) -{ - TMAT(2, 0) = zx; - TMAT(2, 1) = zy; - TMAT(2, 2) = zz; -} - - - -MCORE_INLINE void Matrix::SetTranslation(float tx, float ty, float tz) -{ - TMAT(3, 0) = tx; - TMAT(3, 1) = ty; - TMAT(3, 2) = tz; -} - - - -MCORE_INLINE void Matrix::SetRight(const AZ::Vector3& x) -{ - TMAT(0, 0) = x.GetX(); - TMAT(0, 1) = x.GetY(); - TMAT(0, 2) = x.GetZ(); -} - - - -MCORE_INLINE void Matrix::SetUp(const AZ::Vector3& y) -{ - TMAT(1, 0) = y.GetX(); - TMAT(1, 1) = y.GetY(); - TMAT(1, 2) = y.GetZ(); -} - - - -MCORE_INLINE void Matrix::SetForward(const AZ::Vector3& z) -{ - TMAT(2, 0) = z.GetX(); - TMAT(2, 1) = z.GetY(); - TMAT(2, 2) = z.GetZ(); -} - - - -MCORE_INLINE void Matrix::SetTranslation(const AZ::Vector3& t) -{ - TMAT(3, 0) = t.GetX(); - TMAT(3, 1) = t.GetY(); - TMAT(3, 2) = t.GetZ(); -} - - - -MCORE_INLINE AZ::Vector3 Matrix::GetRight() const -{ - //return *reinterpret_cast( m16/* + 0*/); - return AZ::Vector3(TMAT(0, 0), TMAT(0, 1), TMAT(0, 2)); -} - - - -MCORE_INLINE AZ::Vector3 Matrix::GetForward() const -{ - // return *reinterpret_cast(m16+4); - return AZ::Vector3(TMAT(1, 0), TMAT(1, 1), TMAT(1, 2)); -} - - - -MCORE_INLINE AZ::Vector3 Matrix::GetUp() const -{ - // return *reinterpret_cast(m16+8); - return AZ::Vector3(TMAT(2, 0), TMAT(2, 1), TMAT(2, 2)); -} - - - -MCORE_INLINE AZ::Vector3 Matrix::GetTranslation() const -{ - //return *reinterpret_cast(m16+12); - return AZ::Vector3(TMAT(3, 0), TMAT(3, 1), TMAT(3, 2)); -} - - - -MCORE_INLINE AZ::Vector3 Matrix::Mul3x3(const AZ::Vector3& v) const -{ - return AZ::Vector3( - v.GetX() * TMAT(0, 0) + v.GetY() * TMAT(1, 0) + v.GetZ() * TMAT(2, 0), - v.GetX() * TMAT(0, 1) + v.GetY() * TMAT(1, 1) + v.GetZ() * TMAT(2, 1), - v.GetX() * TMAT(0, 2) + v.GetY() * TMAT(1, 2) + v.GetZ() * TMAT(2, 2)); -} - - - -MCORE_INLINE void operator *= (AZ::Vector3& v, const Matrix& m) -{ - v = AZ::Vector3( - v.GetX() * MMAT(m, 0, 0) + v.GetY() * MMAT(m, 1, 0) + v.GetZ() * MMAT(m, 2, 0) + MMAT(m, 3, 0), - v.GetX() * MMAT(m, 0, 1) + v.GetY() * MMAT(m, 1, 1) + v.GetZ() * MMAT(m, 2, 1) + MMAT(m, 3, 1), - v.GetX() * MMAT(m, 0, 2) + v.GetY() * MMAT(m, 1, 2) + v.GetZ() * MMAT(m, 2, 2) + MMAT(m, 3, 2)); -} - - - -MCORE_INLINE void operator *= (AZ::Vector4& v, const Matrix& m) -{ - v = AZ::Vector4( - v.GetX() * MMAT(m, 0, 0) + v.GetY() * MMAT(m, 1, 0) + v.GetZ() * MMAT(m, 2, 0) + v.GetW() * MMAT(m, 3, 0), - v.GetX() * MMAT(m, 0, 1) + v.GetY() * MMAT(m, 1, 1) + v.GetZ() * MMAT(m, 2, 1) + v.GetW() * MMAT(m, 3, 1), - v.GetX() * MMAT(m, 0, 2) + v.GetY() * MMAT(m, 1, 2) + v.GetZ() * MMAT(m, 2, 2) + v.GetW() * MMAT(m, 3, 2), - v.GetX() * MMAT(m, 0, 3) + v.GetY() * MMAT(m, 1, 3) + v.GetZ() * MMAT(m, 2, 3) + v.GetW() * MMAT(m, 3, 3)); -} - - - -MCORE_INLINE AZ::Vector3 operator * (const AZ::Vector3& v, const Matrix& m) -{ - return AZ::Vector3( - v.GetX() * MMAT(m, 0, 0) + v.GetY() * MMAT(m, 1, 0) + v.GetZ() * MMAT(m, 2, 0) + MMAT(m, 3, 0), - v.GetX() * MMAT(m, 0, 1) + v.GetY() * MMAT(m, 1, 1) + v.GetZ() * MMAT(m, 2, 1) + MMAT(m, 3, 1), - v.GetX() * MMAT(m, 0, 2) + v.GetY() * MMAT(m, 1, 2) + v.GetZ() * MMAT(m, 2, 2) + MMAT(m, 3, 2)); -} - - - - -// skin a vertex position -MCORE_INLINE void Matrix::Skin4x3(const AZ::Vector3& in, AZ::Vector3& out, float weight) -{ - out.Set( - out.GetX() + (in.GetX() * TMAT(0, 0) + in.GetY() * TMAT(1, 0) + in.GetZ() * TMAT(2, 0) + TMAT(3, 0)) * weight, - out.GetY() + (in.GetX() * TMAT(0, 1) + in.GetY() * TMAT(1, 1) + in.GetZ() * TMAT(2, 1) + TMAT(3, 1)) * weight, - out.GetZ() + (in.GetX() * TMAT(0, 2) + in.GetY() * TMAT(1, 2) + in.GetZ() * TMAT(2, 2) + TMAT(3, 2)) * weight - ); -} - - -// skin a position and normal -MCORE_INLINE void Matrix::Skin(const AZ::Vector3* inPos, const AZ::Vector3* inNormal, AZ::Vector3* outPos, AZ::Vector3* outNormal, float weight) -{ - const float mat00 = TMAT(0, 0); - const float mat10 = TMAT(1, 0); - const float mat20 = TMAT(2, 0); - const float mat30 = TMAT(3, 0); - const float mat01 = TMAT(0, 1); - const float mat11 = TMAT(1, 1); - const float mat21 = TMAT(2, 1); - const float mat31 = TMAT(3, 1); - const float mat02 = TMAT(0, 2); - const float mat12 = TMAT(1, 2); - const float mat22 = TMAT(2, 2); - const float mat32 = TMAT(3, 2); - - outPos->Set( - outPos->GetX() + (inPos->GetX() * mat00 + inPos->GetY() * mat10 + inPos->GetZ() * mat20 + mat30) * weight, - outPos->GetY() + (inPos->GetX() * mat01 + inPos->GetY() * mat11 + inPos->GetZ() * mat21 + mat31) * weight, - outPos->GetZ() + (inPos->GetX() * mat02 + inPos->GetY() * mat12 + inPos->GetZ() * mat22 + mat32) * weight - ); - - outNormal->Set( - outNormal->GetX() + (inNormal->GetX() * mat00 + inNormal->GetY() * mat10 + inNormal->GetZ() * mat20) * weight, - outNormal->GetY() + (inNormal->GetX() * mat01 + inNormal->GetY() * mat11 + inNormal->GetZ() * mat21) * weight, - outNormal->GetZ() + (inNormal->GetX() * mat02 + inNormal->GetY() * mat12 + inNormal->GetZ() * mat22) * weight - ); -} - - -// skin a position, normal, and tangent -MCORE_INLINE void Matrix::Skin(const AZ::Vector3* inPos, const AZ::Vector3* inNormal, const AZ::Vector4* inTangent, AZ::Vector3* outPos, AZ::Vector3* outNormal, AZ::Vector4* outTangent, float weight) -{ - const float mat00 = TMAT(0, 0); - const float mat10 = TMAT(1, 0); - const float mat20 = TMAT(2, 0); - const float mat30 = TMAT(3, 0); - const float mat01 = TMAT(0, 1); - const float mat11 = TMAT(1, 1); - const float mat21 = TMAT(2, 1); - const float mat31 = TMAT(3, 1); - const float mat02 = TMAT(0, 2); - const float mat12 = TMAT(1, 2); - const float mat22 = TMAT(2, 2); - const float mat32 = TMAT(3, 2); - - outPos->Set( - outPos->GetX() + (inPos->GetX() * mat00 + inPos->GetY() * mat10 + inPos->GetZ() * mat20 + mat30) * weight, - outPos->GetY() + (inPos->GetX() * mat01 + inPos->GetY() * mat11 + inPos->GetZ() * mat21 + mat31) * weight, - outPos->GetZ() + (inPos->GetX() * mat02 + inPos->GetY() * mat12 + inPos->GetZ() * mat22 + mat32) * weight - ); - - outNormal->Set( - outNormal->GetX() + (inNormal->GetX() * mat00 + inNormal->GetY() * mat10 + inNormal->GetZ() * mat20) * weight, - outNormal->GetY() + (inNormal->GetX() * mat01 + inNormal->GetY() * mat11 + inNormal->GetZ() * mat21) * weight, - outNormal->GetZ() + (inNormal->GetX() * mat02 + inNormal->GetY() * mat12 + inNormal->GetZ() * mat22) * weight - ); - - outTangent->Set( - outTangent->GetX() + (inTangent->GetX() * mat00 + inTangent->GetY() * mat10 + inTangent->GetZ() * mat20) * weight, - outTangent->GetY() + (inTangent->GetX() * mat01 + inTangent->GetY() * mat11 + inTangent->GetZ() * mat21) * weight, - outTangent->GetZ() + (inTangent->GetX() * mat02 + inTangent->GetY() * mat12 + inTangent->GetZ() * mat22) * weight, - inTangent->GetW() - ); -} - -// skin a position, normal, and tangent and bitangent -MCORE_INLINE void Matrix::Skin(const AZ::Vector3* inPos, const AZ::Vector3* inNormal, const AZ::Vector4* inTangent, const AZ::Vector3* inBitangent, AZ::Vector3* outPos, AZ::Vector3* outNormal, AZ::Vector4* outTangent, AZ::Vector3* outBitangent, float weight) -{ - const float mat00 = TMAT(0, 0); - const float mat10 = TMAT(1, 0); - const float mat20 = TMAT(2, 0); - const float mat30 = TMAT(3, 0); - const float mat01 = TMAT(0, 1); - const float mat11 = TMAT(1, 1); - const float mat21 = TMAT(2, 1); - const float mat31 = TMAT(3, 1); - const float mat02 = TMAT(0, 2); - const float mat12 = TMAT(1, 2); - const float mat22 = TMAT(2, 2); - const float mat32 = TMAT(3, 2); - - outPos->Set( - outPos->GetX() + (inPos->GetX() * mat00 + inPos->GetY() * mat10 + inPos->GetZ() * mat20 + mat30) * weight, - outPos->GetY() + (inPos->GetX() * mat01 + inPos->GetY() * mat11 + inPos->GetZ() * mat21 + mat31) * weight, - outPos->GetZ() + (inPos->GetX() * mat02 + inPos->GetY() * mat12 + inPos->GetZ() * mat22 + mat32) * weight - ); - - outNormal->Set( - outNormal->GetX() + (inNormal->GetX() * mat00 + inNormal->GetY() * mat10 + inNormal->GetZ() * mat20) * weight, - outNormal->GetY() + (inNormal->GetX() * mat01 + inNormal->GetY() * mat11 + inNormal->GetZ() * mat21) * weight, - outNormal->GetZ() + (inNormal->GetX() * mat02 + inNormal->GetY() * mat12 + inNormal->GetZ() * mat22) * weight - ); - - outTangent->Set( - outTangent->GetX() + (inTangent->GetX() * mat00 + inTangent->GetY() * mat10 + inTangent->GetZ() * mat20) * weight, - outTangent->GetY() + (inTangent->GetX() * mat01 + inTangent->GetY() * mat11 + inTangent->GetZ() * mat21) * weight, - outTangent->GetZ() + (inTangent->GetX() * mat02 + inTangent->GetY() * mat12 + inTangent->GetZ() * mat22) * weight, - inTangent->GetW() - ); - - outBitangent->Set( - outBitangent->GetX() + (inBitangent->GetX() * mat00 + inBitangent->GetY() * mat10 + inBitangent->GetZ() * mat20) * weight, - outBitangent->GetY() + (inBitangent->GetX() * mat01 + inBitangent->GetY() * mat11 + inBitangent->GetZ() * mat21) * weight, - outBitangent->GetZ() + (inBitangent->GetX() * mat02 + inBitangent->GetY() * mat12 + inBitangent->GetZ() * mat22) * weight - ); -} - - -// skin a normal -MCORE_INLINE void Matrix::Skin3x3(const AZ::Vector3& in, AZ::Vector3& out, float weight) -{ - out.Set( - out.GetX() + (in.GetX() * TMAT(0, 0) + in.GetY() * TMAT(1, 0) + in.GetZ() * TMAT(2, 0)) * weight, - out.GetY() + (in.GetX() * TMAT(0, 1) + in.GetY() * TMAT(1, 1) + in.GetZ() * TMAT(2, 1)) * weight, - out.GetZ() + (in.GetX() * TMAT(0, 2) + in.GetY() * TMAT(1, 2) + in.GetZ() * TMAT(2, 2)) * weight - ); -} - - -// multiply by a float -MCORE_INLINE Matrix& Matrix::operator *= (float value) -{ - for (uint32 i = 0; i < 16; ++i) - { - m_m16[i] *= value; - } - - return *this; -} - - -// scale (uniform) -MCORE_INLINE void Matrix::Scale(const AZ::Vector3& scale) -{ - for (uint32 i = 0; i < 4; ++i) - { - TMAT(i, 0) *= scale.GetX(); - TMAT(i, 1) *= scale.GetY(); - TMAT(i, 2) *= scale.GetZ(); - } -} - - -// returns a normalized version of this matrix -Matrix Matrix::Normalized() const -{ - Matrix result(*this); - result.Normalize(); - return result; -} - diff --git a/Gems/EMotionFX/Code/MCore/mcore_files.cmake b/Gems/EMotionFX/Code/MCore/mcore_files.cmake index d33041eaf8..c1203cb72e 100644 --- a/Gems/EMotionFX/Code/MCore/mcore_files.cmake +++ b/Gems/EMotionFX/Code/MCore/mcore_files.cmake @@ -79,9 +79,6 @@ set(FILES Source/LogManager.cpp Source/LogManager.h Source/Macros.h - Source/Matrix4.cpp - Source/Matrix4.h - Source/Matrix4.inl Source/MCoreSystem.cpp Source/MCoreSystem.h Source/MemoryCategoriesCore.h diff --git a/Gems/EMotionFX/Code/Tests/Matchers.h b/Gems/EMotionFX/Code/Tests/Matchers.h index 9f7b9017ba..61370aafa0 100644 --- a/Gems/EMotionFX/Code/Tests/Matchers.h +++ b/Gems/EMotionFX/Code/Tests/Matchers.h @@ -14,7 +14,6 @@ #include #include #include -#include #include #include @@ -89,27 +88,3 @@ inline bool IsCloseMatcherP::gmock_Impl -template<> -inline bool IsCloseMatcherP::gmock_Impl::MatchAndExplain(const MCore::Matrix& arg, ::testing::MatchResultListener* result_listener) const -{ - using ::testing::FloatEq; - using ::testing::ExplainMatchResult; - return ExplainMatchResult(FloatEq(expected.m_m16[0]), arg.m_m16[0], result_listener) - && ExplainMatchResult(FloatEq(expected.m_m16[1]), arg.m_m16[1], result_listener) - && ExplainMatchResult(FloatEq(expected.m_m16[2]), arg.m_m16[2], result_listener) - && ExplainMatchResult(FloatEq(expected.m_m16[3]), arg.m_m16[3], result_listener) - && ExplainMatchResult(FloatEq(expected.m_m16[4]), arg.m_m16[4], result_listener) - && ExplainMatchResult(FloatEq(expected.m_m16[5]), arg.m_m16[5], result_listener) - && ExplainMatchResult(FloatEq(expected.m_m16[6]), arg.m_m16[6], result_listener) - && ExplainMatchResult(FloatEq(expected.m_m16[7]), arg.m_m16[7], result_listener) - && ExplainMatchResult(FloatEq(expected.m_m16[8]), arg.m_m16[8], result_listener) - && ExplainMatchResult(FloatEq(expected.m_m16[9]), arg.m_m16[9], result_listener) - && ExplainMatchResult(FloatEq(expected.m_m16[10]), arg.m_m16[10], result_listener) - && ExplainMatchResult(FloatEq(expected.m_m16[11]), arg.m_m16[11], result_listener) - && ExplainMatchResult(FloatEq(expected.m_m16[12]), arg.m_m16[12], result_listener) - && ExplainMatchResult(FloatEq(expected.m_m16[13]), arg.m_m16[13], result_listener) - && ExplainMatchResult(FloatEq(expected.m_m16[14]), arg.m_m16[14], result_listener) - && ExplainMatchResult(FloatEq(expected.m_m16[15]), arg.m_m16[15], result_listener); -} diff --git a/Gems/EMotionFX/Code/Tests/TransformUnitTests.cpp b/Gems/EMotionFX/Code/Tests/TransformUnitTests.cpp index b5f98bc5e8..bc63f6f9bd 100644 --- a/Gems/EMotionFX/Code/Tests/TransformUnitTests.cpp +++ b/Gems/EMotionFX/Code/Tests/TransformUnitTests.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include