Skip to content

Commit

Permalink
Add FOV slider to remaining games
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Sep 4, 2024
1 parent be0f545 commit 9526daf
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/game/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ void CAMERA_CalcPosition(cdc::Vector3* position, cdc::Vector3* base, cdc::Euler*
Hooking::Call(addr, position, base, rotation, distance);
}

void CAMERA_SetProjDistance(Camera* camera, float distance)
{
auto addr = GET_ADDRESS(0x48E540, 0x491FA0, 0x000000);

Hooking::Call(addr, camera, distance);
}

#ifdef TR8
void CAMERA_SetMode(int mode)
{
Expand Down
11 changes: 10 additions & 1 deletion src/game/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ struct CameraCore
cdc::Vector3 viewVolumeNormal[5];

cdc::Euler rotation;
char pad2[128];

char pad1[52];

float projDistance;
float newProjDistance;
float projDistanceSpd;

char pad2[64];
};

struct Camera : CameraCore
Expand All @@ -45,7 +52,9 @@ struct Camera
#endif

Camera* CAMERA_GetCamera();

void CAMERA_CalcPosition(cdc::Vector3* position, cdc::Vector3* base, cdc::Euler* rotation, float distance);
void CAMERA_SetProjDistance(Camera* camera, float distance);

#ifdef TR8
void CAMERA_SetMode(int mode);
Expand Down
10 changes: 8 additions & 2 deletions src/modules/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "file/FileSystem.h"
#include "modules/Log.h"
#include "game/Camera.h"
#include "util/Controls.h"

void MainMenu::OnDraw()
{
Expand Down Expand Up @@ -116,15 +117,20 @@ void MainMenu::OnDraw()
}
#endif

#ifdef TR8
// Camera
if (ImGui::CollapsingHeader("Camera"))
{
auto camera = CAMERA_GetCamera();

#ifdef TR8
ImGui::SliderFloat("Field of view", &camera->fov, 0.f, 3.f);
}
#else
if (SliderProjection("Field of view", &camera->projDistance, 0.f, 3.f))
{
CAMERA_SetProjDistance(camera, camera->projDistance);
}
#endif
}

ImGui::End();
}
Expand Down
12 changes: 12 additions & 0 deletions src/util/Controls.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "Controls.h"

#define _USE_MATH_DEFINES
#include <math.h>

bool SliderProjection(const char* label, float* proj, float v_min, float v_max, const char* format, ImGuiSliderFlags flags)
{
float fov = atanf(287.39136f / *proj) * 2.f;
bool value_changed = ImGui::SliderFloat(label, &fov, v_min, v_max, format, flags);
*proj = 287.39136f / tanf(fov * 0.5f);
return value_changed;
}
5 changes: 5 additions & 0 deletions src/util/Controls.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <imgui.h>

bool SliderProjection(const char* label, float* v, float v_min, float v_max, const char* format = "%.3f", ImGuiSliderFlags flags = 0);

0 comments on commit 9526daf

Please sign in to comment.