Skip to content

Commit ced83cd

Browse files
committed
Fix Underworld camera matrix and FOV
1 parent 0681039 commit ced83cd

File tree

6 files changed

+23
-0
lines changed

6 files changed

+23
-0
lines changed

src/cdc/math/Math.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Math.h"
2+
#include "util/Hooking.h"
23

34
cdc::Vector3 cdc::Mul3x3(Matrix* matA, Vector3* vecB)
45
{
@@ -26,4 +27,12 @@ cdc::Vector3 cdc::Mul3x4(Matrix* matA, Vector3* vecB)
2627
matA->col3.vec128)));
2728

2829
return result;
30+
}
31+
32+
void cdc::OrthonormalInverse3x4(cdc::Matrix* result, cdc::Matrix* m)
33+
{
34+
// Imagine doing all this math yourself
35+
auto addr = GET_ADDRESS(0x000000, 0x000000, 0x49BE10);
36+
37+
Hooking::Call(addr, result, m);
2938
}

src/cdc/math/Math.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ namespace cdc
77
{
88
Vector3 Mul3x3(Matrix* matA, Vector3* vecB);
99
Vector3 Mul3x4(Matrix* matA, Vector3* vecB);
10+
11+
void OrthonormalInverse3x4(cdc::Matrix* result, cdc::Matrix* m);
1012
}

src/cdc/math/Vector.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,8 @@ namespace cdc
4444
class Euler : public Vector
4545
{
4646
};
47+
48+
class Quat : public Vector
49+
{
50+
};
4751
}

src/game/Camera.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ struct Camera
2626
char pad1[16];
2727

2828
cdc::Matrix transform;
29+
cdc::Matrix invTransform;
30+
cdc::Vector3 position;
31+
cdc::Quat orientation;
32+
33+
float fov;
2934
};
3035
#endif
3136

src/modules/camera/Underworld.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void UnderworldCamera::ToggleMode()
3535
// Set the camera position to the player position
3636
auto camera = CAMERA_GetCamera();
3737
camera->transform.col3 = Game::GetPlayerInstance()->position;
38+
camera->fov = static_cast<float>(M_PI) / 2;
3839

3940
m_rotation = { static_cast<float>(M_PI) / -2.f, 0.f, 0.f };
4041
}
@@ -56,6 +57,8 @@ void UnderworldCamera::OnControl()
5657
// Apply the rotation and position
5758
camera->transform.Build(&m_rotation);
5859
camera->transform.col3 = m_position;
60+
61+
cdc::OrthonormalInverse3x4(&camera->invTransform, &camera->transform);
5962
}
6063

6164
void UnderworldCamera::Rotate(float x, float z)

src/resources/hook.rc

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)