diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2019-01-29 16:05:51 -0600 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2019-02-03 11:35:31 -0600 |
| commit | b9a00a40a9a61c3df5c774fd1cc9d04f57994a0c (patch) | |
| tree | a1e820e89ddb239846f6e2a1cb9458b3e3b8d535 /Source/Core/VideoCommon/VertexShaderManager.cpp | |
| parent | 3b4486bad3f0e44c3a572bba411879a634ece325 (diff) | |
Common: Move Matrix classes out of MathUtil into their own files and make their interface more friendly.
Diffstat (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/VertexShaderManager.cpp | 49 |
1 files changed, 19 insertions, 30 deletions
diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index fca6a420c5..b68534aa8e 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -13,7 +13,7 @@ #include "Common/CommonFuncs.h" #include "Common/CommonTypes.h" #include "Common/Logging/Log.h" -#include "Common/MathUtil.h" +#include "Common/Matrix.h" #include "Core/ConfigManager.h" #include "Core/Core.h" #include "VideoCommon/BPFunctions.h" @@ -86,7 +86,7 @@ static void ViewportCorrectionMatrix(Matrix44& result) float Wd = (X + intendedWd <= EFB_WIDTH) ? intendedWd : (EFB_WIDTH - X); float Ht = (Y + intendedHt <= EFB_HEIGHT) ? intendedHt : (EFB_HEIGHT - Y); - Matrix44::LoadIdentity(result); + result = Matrix44::Identity(); if (Wd == 0 || Ht == 0) return; @@ -121,7 +121,7 @@ void VertexShaderManager::Init() ResetView(); // TODO: should these go inside ResetView()? - Matrix44::LoadIdentity(s_viewportCorrection); + s_viewportCorrection = Matrix44::Identity(); memset(g_fProjectionMatrix, 0, sizeof(g_fProjectionMatrix)); for (int i = 0; i < 4; ++i) g_fProjectionMatrix[i * 5] = 1.0f; @@ -454,26 +454,19 @@ void VertexShaderManager::SetConstants() if (g_ActiveConfig.bFreeLook && xfmem.projection.type == GX_PERSPECTIVE) { - Matrix44 mtxA; - Matrix44 mtxB; - Matrix44 viewMtx; - - Matrix44::Translate(mtxA, s_fViewTranslationVector); - Matrix44::LoadMatrix33(mtxB, s_viewRotationMatrix); - Matrix44::Multiply(mtxB, mtxA, viewMtx); // view = rotation x translation - Matrix44::Set(mtxB, g_fProjectionMatrix); - Matrix44::Multiply(mtxB, viewMtx, mtxA); // mtxA = projection x view - Matrix44::Multiply(s_viewportCorrection, mtxA, mtxB); // mtxB = viewportCorrection x mtxA - memcpy(constants.projection.data(), mtxB.data, 4 * sizeof(float4)); + auto mtxA = Matrix44::Translate(s_fViewTranslationVector); + auto mtxB = Matrix44::FromMatrix33(s_viewRotationMatrix); + const auto viewMtx = mtxB * mtxA; // view = rotation x translation + + mtxA = Matrix44::FromArray(g_fProjectionMatrix) * viewMtx; // mtxA = projection x view + mtxB = s_viewportCorrection * mtxA; // mtxB = viewportCorrection x mtxA + memcpy(constants.projection.data(), mtxB.data.data(), 4 * sizeof(float4)); } else { - Matrix44 projMtx; - Matrix44::Set(projMtx, g_fProjectionMatrix); - - Matrix44 correctedMtx; - Matrix44::Multiply(s_viewportCorrection, projMtx, correctedMtx); - memcpy(constants.projection.data(), correctedMtx.data, 4 * sizeof(float4)); + const auto projMtx = Matrix44::FromArray(g_fProjectionMatrix); + const auto correctedMtx = s_viewportCorrection * projMtx; + memcpy(constants.projection.data(), correctedMtx.data.data(), 4 * sizeof(float4)); } dirty = true; @@ -677,16 +670,12 @@ void VertexShaderManager::RotateView(float x, float y) s_fViewRotation[0] += x; s_fViewRotation[1] += y; - Matrix33 mx; - Matrix33 my; - Matrix33::RotateX(mx, s_fViewRotation[1]); - Matrix33::RotateY(my, s_fViewRotation[0]); - Matrix33::Multiply(mx, my, s_viewRotationMatrix); + s_viewRotationMatrix = + Matrix33::RotateX(s_fViewRotation[1]) * Matrix33::RotateY(s_fViewRotation[0]); // reverse rotation - Matrix33::RotateX(mx, -s_fViewRotation[1]); - Matrix33::RotateY(my, -s_fViewRotation[0]); - Matrix33::Multiply(my, mx, s_viewInvRotationMatrix); + s_viewInvRotationMatrix = + Matrix33::RotateY(-s_fViewRotation[0]) * Matrix33::RotateX(-s_fViewRotation[1]); bProjectionChanged = true; } @@ -694,8 +683,8 @@ void VertexShaderManager::RotateView(float x, float y) void VertexShaderManager::ResetView() { memset(s_fViewTranslationVector, 0, sizeof(s_fViewTranslationVector)); - Matrix33::LoadIdentity(s_viewRotationMatrix); - Matrix33::LoadIdentity(s_viewInvRotationMatrix); + s_viewRotationMatrix = Matrix33::Identity(); + s_viewInvRotationMatrix = Matrix33::Identity(); s_fViewRotation[0] = s_fViewRotation[1] = 0.0f; bProjectionChanged = true; |
