mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 21:01:37 +00:00
Replace camera aspect ratio/field of view logic.
This commit is contained in:
parent
0c2ff653e7
commit
c1e08f2bea
2 changed files with 27 additions and 32 deletions
|
|
@ -2,40 +2,37 @@
|
|||
#include <ui/game_window.h>
|
||||
#include <user/config.h>
|
||||
|
||||
constexpr float m_baseAspectRatio = 16.0f / 9.0f;
|
||||
static constexpr float ORIGINAL_ASPECT_RATIO = 4.0f / 3.0f;
|
||||
static constexpr float ORIGINAL_WIDESCREEN_ASPECT_RATIO = 16.0f / 9.0f;
|
||||
|
||||
bool CameraAspectRatioMidAsmHook(PPCRegister& r31)
|
||||
void CameraAspectRatioMidAsmHook(PPCRegister& r30, PPCRegister& r31)
|
||||
{
|
||||
auto pCamera = (SWA::CCamera*)g_memory.Translate(r31.u32);
|
||||
auto newAspectRatio = (float)GameWindow::s_width / (float)GameWindow::s_height;
|
||||
r30.u32 = 0;
|
||||
|
||||
auto camera = (SWA::CCamera*)g_memory.Translate(r31.u32);
|
||||
|
||||
// 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;
|
||||
camera->m_HorzAspectRatio = float(GameWindow::s_width) / float(GameWindow::s_height);
|
||||
}
|
||||
|
||||
bool CameraBoostAspectRatioMidAsmHook(PPCRegister& r31, PPCRegister& f0, PPCRegister& f10, PPCRegister& f12)
|
||||
void CameraFieldOfViewMidAsmHook(PPCRegister& r31, PPCRegister& f31)
|
||||
{
|
||||
auto pCamera = (SWA::CCamera*)g_memory.Translate(r31.u32);
|
||||
auto camera = (SWA::CCamera*)g_memory.Translate(r31.u32);
|
||||
|
||||
if (GameWindow::s_width < GameWindow::s_height)
|
||||
// Interpolate to the original 4:3 field of view for narrow aspect ratios.
|
||||
if (camera->m_HorzAspectRatio < ORIGINAL_WIDESCREEN_ASPECT_RATIO)
|
||||
{
|
||||
pCamera->m_VertFieldOfView = pCamera->m_HorzFieldOfView + f10.f64;
|
||||
}
|
||||
else
|
||||
{
|
||||
pCamera->m_VertFieldOfView = (f12.f64 / f0.f64) + f10.f64;
|
||||
}
|
||||
float factor = std::clamp((camera->m_HorzAspectRatio - ORIGINAL_ASPECT_RATIO) / (ORIGINAL_WIDESCREEN_ASPECT_RATIO - ORIGINAL_ASPECT_RATIO), 0.0f, 1.0f);
|
||||
factor = ORIGINAL_ASPECT_RATIO + (1.0f - ORIGINAL_ASPECT_RATIO) * factor;
|
||||
|
||||
return true;
|
||||
f31.f64 *= factor;
|
||||
|
||||
// For tall aspect ratios, use proper VERT+.
|
||||
if (camera->m_HorzAspectRatio < ORIGINAL_ASPECT_RATIO)
|
||||
{
|
||||
f31.f64 = 2.0 * atan(tan(0.5 * f31.f64) / camera->m_HorzAspectRatio * ORIGINAL_ASPECT_RATIO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PPC_FUNC_IMPL(__imp__sub_824697B0);
|
||||
|
|
|
|||
|
|
@ -91,16 +91,14 @@ registers = ["r11"]
|
|||
|
||||
[[midasm_hook]]
|
||||
name = "CameraAspectRatioMidAsmHook"
|
||||
address = 0x82468E84
|
||||
registers = ["r31"]
|
||||
jump_address_on_true = 0x82468E88
|
||||
jump_address_on_false = 0x82468EE0
|
||||
address = 0x82468E78
|
||||
registers = ["r30", "r31"]
|
||||
|
||||
[[midasm_hook]]
|
||||
name = "CameraBoostAspectRatioMidAsmHook"
|
||||
address = 0x8246BDA0
|
||||
registers = ["r31", "f0", "f10", "f12"]
|
||||
jump_address_on_true = 0x8246BDAC
|
||||
name = "CameraFieldOfViewMidAsmHook"
|
||||
address = 0x82468EDC
|
||||
registers = ["r31", "f31"]
|
||||
jump_address = 0x82468EE0
|
||||
|
||||
[[midasm_hook]]
|
||||
name = "ResetScoreOnRestartMidAsmHook"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue