[Enhancement] Add fix camera drift option to fixes menu (#1983)

This commit is contained in:
frizzle101101 2022-11-22 02:57:26 -05:00 committed by GitHub
parent aa16a5388e
commit c569a46933
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 7 deletions

View File

@ -944,6 +944,8 @@ void Environment_StopStormNatureAmbience(PlayState* play);
void Environment_WarpSongLeave(PlayState* play); void Environment_WarpSongLeave(PlayState* play);
f32 Math_CosS(s16 angle); f32 Math_CosS(s16 angle);
f32 Math_SinS(s16 angle); f32 Math_SinS(s16 angle);
f32 Math_AccurateCosS(s16 angle);
f32 Math_AccurateSinS(s16 angle);
s32 Math_ScaledStepToS(s16* pValue, s16 target, s16 step); s32 Math_ScaledStepToS(s16* pValue, s16 target, s16 step);
s32 Math_StepToS(s16* pValue, s16 target, s16 step); s32 Math_StepToS(s16* pValue, s16 target, s16 step);
s32 Math_StepToF(f32* pValue, f32 target, f32 step); s32 Math_StepToF(f32* pValue, f32 target, f32 step);

View File

@ -1201,6 +1201,8 @@ namespace GameMenuBar {
UIWidgets::Tooltip("Extend certain credits scenes so the music lines up properly with the visuals"); UIWidgets::Tooltip("Extend certain credits scenes so the music lines up properly with the visuals");
UIWidgets::PaddedEnhancementCheckbox("Fix Gerudo Warrior's clothing colors", "gGerudoWarriorClothingFix", true, false); UIWidgets::PaddedEnhancementCheckbox("Fix Gerudo Warrior's clothing colors", "gGerudoWarriorClothingFix", true, false);
UIWidgets::Tooltip("Prevent the Gerudo Warrior's clothes changing color when changing Link's tunic or using bombs in front of her"); UIWidgets::Tooltip("Prevent the Gerudo Warrior's clothes changing color when changing Link's tunic or using bombs in front of her");
UIWidgets::PaddedEnhancementCheckbox("Fix Camera Drift", "gFixCameraDrift", true, false);
UIWidgets::Tooltip("Fixes camera slightly drifting to the left when standing still due to a math error");
ImGui::EndMenu(); ImGui::EndMenu();
} }

View File

@ -1238,7 +1238,8 @@ f32 Camera_LERPClampDist(Camera* camera, f32 dist, f32 min, f32 max) {
} }
camera->rUpdateRateInv = Camera_LERPCeilF(rUpdateRateInvTarget, camera->rUpdateRateInv, PCT(OREG(25)), 0.1f); camera->rUpdateRateInv = Camera_LERPCeilF(rUpdateRateInvTarget, camera->rUpdateRateInv, PCT(OREG(25)), 0.1f);
return Camera_LERPCeilF(distTarget, camera->dist, 1.0f / camera->rUpdateRateInv, 0.2f); return Camera_LERPCeilF(distTarget, camera->dist, 1.0f / camera->rUpdateRateInv,
CVar_GetS32("gFixCameraDrift", 0) ? 0.0f : 0.2f);
} }
f32 Camera_ClampDist(Camera* camera, f32 dist, f32 minDist, f32 maxDist, s16 timer) { f32 Camera_ClampDist(Camera* camera, f32 dist, f32 minDist, f32 maxDist, s16 timer) {
@ -1260,7 +1261,8 @@ f32 Camera_ClampDist(Camera* camera, f32 dist, f32 minDist, f32 maxDist, s16 tim
} }
camera->rUpdateRateInv = Camera_LERPCeilF(rUpdateRateInvTarget, camera->rUpdateRateInv, PCT(OREG(25)), 0.1f); camera->rUpdateRateInv = Camera_LERPCeilF(rUpdateRateInvTarget, camera->rUpdateRateInv, PCT(OREG(25)), 0.1f);
return Camera_LERPCeilF(distTarget, camera->dist, 1.0f / camera->rUpdateRateInv, 0.2f); return Camera_LERPCeilF(distTarget, camera->dist, 1.0f / camera->rUpdateRateInv,
CVar_GetS32("gFixCameraDrift", 0) ? 0.0f : 0.2f);
} }
s16 Camera_CalcDefaultPitch(Camera* camera, s16 arg1, s16 arg2, s16 arg3) { s16 Camera_CalcDefaultPitch(Camera* camera, s16 arg1, s16 arg2, s16 arg3) {

View File

@ -1,4 +1,5 @@
#include "global.h" #include "global.h"
#include <math.h>
f32 Math_CosS(s16 angle) { f32 Math_CosS(s16 angle) {
return coss(angle) * SHT_MINV; return coss(angle) * SHT_MINV;
@ -8,6 +9,14 @@ f32 Math_SinS(s16 angle) {
return sins(angle) * SHT_MINV; return sins(angle) * SHT_MINV;
} }
f32 Math_AccurateCosS(s16 angle) {
return cosf(DEG_TO_RAD((f32)(angle & 0xFFFC) / SHT_MAX) * 180.0f);
}
f32 Math_AccurateSinS(s16 angle) {
return sinf(DEG_TO_RAD((f32)(angle & 0xFFFC) / SHT_MAX) * 180.0f);
}
/** /**
* Changes pValue by step (scaled by the update rate) towards target, setting it equal when the target is reached. * Changes pValue by step (scaled by the update rate) towards target, setting it equal when the target is reached.
* Returns true when target is reached, false otherwise. * Returns true when target is reached, false otherwise.

View File

@ -76,12 +76,22 @@ Vec3f* OLib_Vec3fDistNormalize(Vec3f* dest, Vec3f* a, Vec3f* b) {
Vec3f* OLib_VecSphToVec3f(Vec3f* dest, VecSph* sph) { Vec3f* OLib_VecSphToVec3f(Vec3f* dest, VecSph* sph) {
Vec3f v; Vec3f v;
f32 sinPitch; f32 sinPitch;
f32 cosPitch = Math_CosS(sph->pitch); f32 cosPitch;
f32 sinYaw; f32 sinYaw;
f32 cosYaw = Math_CosS(sph->yaw); f32 cosYaw;
if (CVar_GetS32("gFixCameraDrift", 0)) {
cosPitch = Math_AccurateCosS(sph->pitch);
cosYaw = Math_AccurateCosS(sph->yaw);
sinPitch = Math_AccurateSinS(sph->pitch);
sinYaw = Math_AccurateSinS(sph->yaw);
} else {
cosPitch = Math_CosS(sph->pitch);
cosYaw = Math_CosS(sph->yaw);
sinPitch = Math_SinS(sph->pitch);
sinYaw = Math_SinS(sph->yaw);
}
sinPitch = Math_SinS(sph->pitch);
sinYaw = Math_SinS(sph->yaw);
v.x = sph->r * sinPitch * sinYaw; v.x = sph->r * sinPitch * sinYaw;
v.y = sph->r * cosPitch; v.y = sph->r * cosPitch;