-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgravity_first_person_cam.cpp
More file actions
65 lines (49 loc) · 1.63 KB
/
gravity_first_person_cam.cpp
File metadata and controls
65 lines (49 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "gravity_first_person_cam.h"
bool FirstPersonCam::CanChangeField(const Player& player, const GravityField& newField) const
{
return !newField.IsTrivial();
}
bool FirstPersonCam::CalculateTransform(Matrix4x3& res, Camera& cam, Player& player)
{
if (!(cam.flags & Camera::ZOOMED_IN) || player.currState != &Player::ST_FIRST_PERSON)
valid = false;
if (valid)
{
if (!IsInterpolating())
{
angX += INPUT_ARR[0].dirZ.val >> 3;
angX = std::clamp<s16>(angX, -0x1c00, 0x1c00);
angY += player.ang.y - playerAngY - (INPUT_ARR[0].dirX.val >> 3);
}
cam.unk17e = angX;
cam.angY = angY;
const short angleDiff = player.ang.y - 180_deg - angY;
if (angleDiff < -45_deg) player.ang.y = angY + 135_deg;
if (angleDiff > 45_deg) player.ang.y = angY - 135_deg;
playerAngY = player.ang.y;
playerPos = player.pos;
}
const Vector3 lookAt = playerPos + 128._f * gravityMatrix.c1;
const s16 halfAngX = angX >> 1;
const s16 halfAngY = angY >> 1;
const Quaternion rotX = {Cos(halfAngX), Sin(halfAngX)*gravityMatrix.c0};
const Quaternion rotY = {Cos(halfAngY), Sin(halfAngY)*gravityMatrix.c1};
res.c2 = (rotY*rotX).RotateSafe(gravityMatrix.c2);
res.c0 = gravityMatrix.c1.Cross(res.c2).Normalized();
res.c1 = res.c2.Cross(res.c0);
Fix12i z = 0xb8'c80_f;
if (angX > 0x1400)
z -= 0x0'036_f * (angX - 0x1400);
res.c3 = lookAt + res.c2 * z;
return valid && !RUNNING_KUPPA_SCRIPT;
}
// Don't let the vanilla camera rotate the player in the first person state
asm(R"(
nsub_02009c5c:
push {r0, r2, r3}
bl _ZN7CamCtrl18IsVanillaCamActiveEv
cmp r0, #0
pop {r0, r2, r3}
strneh r3, [r5]
b 0x02009c60
)");