Common: Move Matrix classes out of MathUtil into their own files and make their interface more friendly.

This commit is contained in:
Jordan Woyak 2019-01-29 16:05:51 -06:00
parent 3b4486bad3
commit b9a00a40a9
8 changed files with 272 additions and 193 deletions

View file

@ -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;
auto mtxA = Matrix44::Translate(s_fViewTranslationVector);
auto mtxB = Matrix44::FromMatrix33(s_viewRotationMatrix);
const auto viewMtx = mtxB * mtxA; // view = rotation x translation
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));
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;