Skip to content

Commit

Permalink
VideoCommon: Add 'Active' state to FreelookCamera to future proof if …
Browse files Browse the repository at this point in the history
…we ever add multiple cameras
  • Loading branch information
iwubcode committed Dec 24, 2020
1 parent a37fd8c commit bcf63c4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Source/Core/VideoCommon/FreeLookCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,8 @@ void FreeLookCamera::SetClean()
{
m_dirty = false;
}

bool FreeLookCamera::IsActive() const
{
return FreeLook::GetActiveConfig().enabled;
}
3 changes: 3 additions & 0 deletions Source/Core/VideoCommon/FreeLookCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class FreeLookCamera
void ResetSpeed();
float GetSpeed() const;

bool IsActive() const;

private:
bool m_dirty = false;
float m_fov_x = 1.0f;
Expand All @@ -75,6 +77,7 @@ class FreeLookCamera

float m_fov_step_size = 0.025f;
float m_speed = 1.0f;
bool m_enabled = true;
};

extern FreeLookCamera g_freelook_camera;
4 changes: 2 additions & 2 deletions Source/Core/VideoCommon/VertexShaderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ void VertexShaderManager::SetConstants()
case GX_PERSPECTIVE:
{
const Common::Vec2 fov =
g_ActiveConfig.bFreeLook ? g_freelook_camera.GetFieldOfView() : Common::Vec2{1, 1};
g_freelook_camera.IsActive() ? g_freelook_camera.GetFieldOfView() : Common::Vec2{1, 1};
g_fProjectionMatrix[0] = rawProjection[0] * g_ActiveConfig.fAspectRatioHackW * fov.x;
g_fProjectionMatrix[1] = 0.0f;
g_fProjectionMatrix[2] = rawProjection[1] * g_ActiveConfig.fAspectRatioHackW * fov.x;
Expand Down Expand Up @@ -419,7 +419,7 @@ void VertexShaderManager::SetConstants()

auto corrected_matrix = s_viewportCorrection * Common::Matrix44::FromArray(g_fProjectionMatrix);

if (xfmem.projection.type == GX_PERSPECTIVE)
if (g_freelook_camera.IsActive() && xfmem.projection.type == GX_PERSPECTIVE)
corrected_matrix *= g_freelook_camera.GetView();

memcpy(constants.projection.data(), corrected_matrix.data.data(), 4 * sizeof(float4));
Expand Down

0 comments on commit bcf63c4

Please sign in to comment.