mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 12:51:42 +00:00
camera_patches: implemented camera X/Y invert
This commit is contained in:
parent
7afe0f27de
commit
4d70dbd3b8
4 changed files with 55 additions and 34 deletions
|
|
@ -68,6 +68,7 @@ set(SWA_PATCHES_CXX_SOURCES
|
||||||
"patches/ui/CHudPause_patches.cpp"
|
"patches/ui/CHudPause_patches.cpp"
|
||||||
"patches/ui/CTitleMenu_patches.cpp"
|
"patches/ui/CTitleMenu_patches.cpp"
|
||||||
"patches/ui/frontend_listener.cpp"
|
"patches/ui/frontend_listener.cpp"
|
||||||
|
"patches/camera_patches.cpp"
|
||||||
"patches/fps_patches.cpp"
|
"patches/fps_patches.cpp"
|
||||||
"patches/misc_patches.cpp"
|
"patches/misc_patches.cpp"
|
||||||
"patches/object_patches.cpp"
|
"patches/object_patches.cpp"
|
||||||
|
|
|
||||||
51
UnleashedRecomp/patches/camera_patches.cpp
Normal file
51
UnleashedRecomp/patches/camera_patches.cpp
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
#include <cpu/guest_code.h>
|
||||||
|
#include <api/SWA.h>
|
||||||
|
#include <ui/window.h>
|
||||||
|
#include <cfg/config.h>
|
||||||
|
|
||||||
|
constexpr float m_baseAspectRatio = 16.0f / 9.0f;
|
||||||
|
|
||||||
|
bool CameraAspectRatioMidAsmHook(PPCRegister& r31)
|
||||||
|
{
|
||||||
|
auto pCamera = (SWA::CCamera*)g_memory.Translate(r31.u32);
|
||||||
|
auto newAspectRatio = (float)Window::s_width / (float)Window::s_height;
|
||||||
|
|
||||||
|
// Dynamically adjust horizontal aspect ratio to window dimensions.
|
||||||
|
pCamera->m_HorzAspectRatio = newAspectRatio;
|
||||||
|
|
||||||
|
if (auto s_pVertAspectRatio = (be<float>*)g_memory.Translate(0x82028FE0))
|
||||||
|
{
|
||||||
|
// Dynamically adjust vertical aspect ratio for VERT+.
|
||||||
|
*s_pVertAspectRatio = 2.0f * atan(tan(45.0f / 2.0f) * (m_baseAspectRatio / newAspectRatio));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Jump to 4:3 code for VERT+ adjustments if using a narrow aspect ratio.
|
||||||
|
return newAspectRatio < m_baseAspectRatio;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CameraBoostAspectRatioMidAsmHook(PPCRegister& r31, PPCRegister& f0)
|
||||||
|
{
|
||||||
|
auto pCamera = (SWA::CCamera*)g_memory.Translate(r31.u32);
|
||||||
|
|
||||||
|
if (Window::s_width < Window::s_height)
|
||||||
|
{
|
||||||
|
// Use horizontal FOV for narrow aspect ratios.
|
||||||
|
f0.f32 = pCamera->m_HorzFieldOfView;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Use vertical FOV for wide aspect ratios.
|
||||||
|
f0.f32 = pCamera->m_VertFieldOfView;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PPC_FUNC_IMPL(__imp__sub_824697B0);
|
||||||
|
PPC_FUNC(sub_824697B0)
|
||||||
|
{
|
||||||
|
auto pCamera = (SWA::CCamera*)g_memory.Translate(ctx.r3.u32);
|
||||||
|
|
||||||
|
pCamera->m_InvertX = Config::CameraXInvert;
|
||||||
|
pCamera->m_InvertY = Config::CameraYInvert;
|
||||||
|
|
||||||
|
__imp__sub_824697B0(ctx, base);
|
||||||
|
}
|
||||||
|
|
@ -3,42 +3,10 @@
|
||||||
#include <ui/window.h>
|
#include <ui/window.h>
|
||||||
#include <cfg/config.h>
|
#include <cfg/config.h>
|
||||||
|
|
||||||
|
// TODO: to be removed.
|
||||||
constexpr float m_baseAspectRatio = 16.0f / 9.0f;
|
constexpr float m_baseAspectRatio = 16.0f / 9.0f;
|
||||||
|
|
||||||
bool CameraAspectRatioMidAsmHook(PPCRegister& r31)
|
// TODO: to be removed.
|
||||||
{
|
|
||||||
auto pCamera = (SWA::CCamera*)g_memory.Translate(r31.u32);
|
|
||||||
auto newAspectRatio = (float)Window::s_width / (float)Window::s_height;
|
|
||||||
|
|
||||||
// Dynamically adjust horizontal aspect ratio to window dimensions.
|
|
||||||
pCamera->m_HorzAspectRatio = newAspectRatio;
|
|
||||||
|
|
||||||
if (auto s_pVertAspectRatio = (be<float>*)g_memory.Translate(0x82028FE0))
|
|
||||||
{
|
|
||||||
// Dynamically adjust vertical aspect ratio for VERT+.
|
|
||||||
*s_pVertAspectRatio = 2.0f * atan(tan(45.0f / 2.0f) * (m_baseAspectRatio / newAspectRatio));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Jump to 4:3 code for VERT+ adjustments if using a narrow aspect ratio.
|
|
||||||
return newAspectRatio < m_baseAspectRatio;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CameraBoostAspectRatioMidAsmHook(PPCRegister& r31, PPCRegister& f0)
|
|
||||||
{
|
|
||||||
auto pCamera = (SWA::CCamera*)g_memory.Translate(r31.u32);
|
|
||||||
|
|
||||||
if (Window::s_width < Window::s_height)
|
|
||||||
{
|
|
||||||
// Use horizontal FOV for narrow aspect ratios.
|
|
||||||
f0.f32 = pCamera->m_HorzFieldOfView;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Use vertical FOV for wide aspect ratios.
|
|
||||||
f0.f32 = pCamera->m_VertFieldOfView;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSDAspectRatioMidAsmHook(PPCRegister& f1, PPCRegister& f2)
|
void CSDAspectRatioMidAsmHook(PPCRegister& f1, PPCRegister& f2)
|
||||||
{
|
{
|
||||||
if (Config::UIScaleMode == EUIScaleMode::Stretch)
|
if (Config::UIScaleMode == EUIScaleMode::Stretch)
|
||||||
|
|
|
||||||
|
|
@ -793,6 +793,7 @@ void DrawInfoPanel()
|
||||||
auto size = Scale(26.0f);
|
auto size = Scale(26.0f);
|
||||||
auto textSize = g_seuratFont->CalcTextSizeA(size, FLT_MAX, 0.0f, desc.c_str());
|
auto textSize = g_seuratFont->CalcTextSizeA(size, FLT_MAX, 0.0f, desc.c_str());
|
||||||
|
|
||||||
|
// TODO: fix word wrap width not scaling to resolution.
|
||||||
drawList->AddText(
|
drawList->AddText(
|
||||||
g_seuratFont,
|
g_seuratFont,
|
||||||
size,
|
size,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue