Skip to content

Commit

Permalink
Fix Underworld camera matrix and FOV
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Aug 18, 2024
1 parent 0681039 commit ced83cd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/cdc/math/Math.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Math.h"
#include "util/Hooking.h"

cdc::Vector3 cdc::Mul3x3(Matrix* matA, Vector3* vecB)
{
Expand Down Expand Up @@ -26,4 +27,12 @@ cdc::Vector3 cdc::Mul3x4(Matrix* matA, Vector3* vecB)
matA->col3.vec128)));

return result;
}

void cdc::OrthonormalInverse3x4(cdc::Matrix* result, cdc::Matrix* m)
{
// Imagine doing all this math yourself
auto addr = GET_ADDRESS(0x000000, 0x000000, 0x49BE10);

Hooking::Call(addr, result, m);
}
2 changes: 2 additions & 0 deletions src/cdc/math/Math.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ namespace cdc
{
Vector3 Mul3x3(Matrix* matA, Vector3* vecB);
Vector3 Mul3x4(Matrix* matA, Vector3* vecB);

void OrthonormalInverse3x4(cdc::Matrix* result, cdc::Matrix* m);
}
4 changes: 4 additions & 0 deletions src/cdc/math/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ namespace cdc
class Euler : public Vector
{
};

class Quat : public Vector
{
};
}
5 changes: 5 additions & 0 deletions src/game/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ struct Camera
char pad1[16];

cdc::Matrix transform;
cdc::Matrix invTransform;
cdc::Vector3 position;
cdc::Quat orientation;

float fov;
};
#endif

Expand Down
3 changes: 3 additions & 0 deletions src/modules/camera/Underworld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void UnderworldCamera::ToggleMode()
// Set the camera position to the player position
auto camera = CAMERA_GetCamera();
camera->transform.col3 = Game::GetPlayerInstance()->position;
camera->fov = static_cast<float>(M_PI) / 2;

m_rotation = { static_cast<float>(M_PI) / -2.f, 0.f, 0.f };
}
Expand All @@ -56,6 +57,8 @@ void UnderworldCamera::OnControl()
// Apply the rotation and position
camera->transform.Build(&m_rotation);
camera->transform.col3 = m_position;

cdc::OrthonormalInverse3x4(&camera->invTransform, &camera->transform);
}

void UnderworldCamera::Rotate(float x, float z)
Expand Down
Binary file modified src/resources/hook.rc
Binary file not shown.

0 comments on commit ced83cd

Please sign in to comment.