-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfree_camera.cpp
More file actions
190 lines (148 loc) · 4 KB
/
free_camera.cpp
File metadata and controls
190 lines (148 loc) · 4 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Free camera for debugging; uncomment to enable
/*
#include <optional>
#include "SM64DS_PI.h"
static auto hasUnpaused = [prevPaused = false]() mutable -> bool
{
return std::exchange(prevPaused, GAME_PAUSED) && !GAME_PAUSED;
};
class FreeCamera
{
Vector3 pos;
short angleX, angleY;
bool fixed = false;
public:
constexpr FreeCamera(const Camera& cam):
pos(cam.pos),
angleX(cam.angle.z),
angleY(cam.angle.y)
{}
[[gnu::always_inline]]
auto ToMatrix() const
{
return Matrix4x3::Proxy([this]<bool resMayAlias>[[gnu::always_inline]](Matrix4x3& res)
{
res = Matrix4x3::RotationXYZ(angleX, angleY, 0);
res.c3 = pos >> 3;
});
}
bool Update()
{
if (fixed) return hasUnpaused();
Input& input = INPUT_ARR[0];
angleX += (input.dirZ * 0.15_f).val;
angleY -= (input.dirX * 0.15_f).val;
const Matrix4x3 matrix = Matrix4x3::RotationXYZ(angleX, angleY, 0);
const Fix12i speed = 500._f;
const bool a = input.buttonsHeld & Input::A;
const bool b = input.buttonsHeld & Input::B;
const bool x = input.buttonsHeld & Input::X;
const bool y = input.buttonsHeld & Input::Y;
const bool l = input.buttonsHeld & Input::L;
const bool r = input.buttonsHeld & Input::R;
pos += matrix.c0 * speed * (r - l) + matrix.c2 * speed * (b - a);
pos.y += speed * (x - y);
// Keep the player awake
if (Player* player = PLAYER_ARR[0])
if (player->currState == &Player::ST_WAIT)
player->stateTimer = 900;
input.buttonsPressed = 0;
input.buttonsHeld = 0;
input.magnitude = 0;
input.dirX = 0_fs;
input.dirZ = 0_fs;
input.angle = 0;
if (hasUnpaused()) fixed = true;
return false;
}
};
static std::optional<FreeCamera> freeCamera;
static SharedFilePtr modelFile;
static SharedFilePtr animFile;
static SharedFilePtr texSeqFile;
static ModelAnim* model = nullptr;
static ShadowModel* shadow = nullptr;
static TextureSequence* texSeq = nullptr;
alignas(ModelAnim) static std::byte modelStorage [sizeof(*model)];
alignas(ShadowModel) static std::byte shadowStorage[sizeof(*shadow)];
alignas(TextureSequence) static std::byte texSeqStorage[sizeof(*texSeq)];
unsigned repl_0202bbe0()
{
if (freeCamera)
{
if (freeCamera->Update())
freeCamera.reset();
}
else if (hasUnpaused() && CAMERA)
freeCamera.emplace(*CAMERA);
return 0x0209f300;
}
void repl_0200de68(Camera& cam)
{
if (!shadow)
{
shadow = new (shadowStorage) ShadowModel;
shadow->InitCylinder();
}
if (!model)
{
modelFile.FromOv0ID(0x02d7);
animFile.FromOv0ID(0x02d8);
BMD_File& modelData = modelFile.LoadBMD();
char* animData = Animation::LoadFile(animFile);
model = new (modelStorage) ModelAnim;
model->SetFile(modelData, 1, -1);
if (!texSeq)
{
texSeqFile.FromOv0ID(0x02d9);
char* texSeqData = TextureSequence::LoadFile(texSeqFile);
TextureSequence::Prepare(modelData, texSeqData);
texSeq = new (texSeqStorage) TextureSequence;
texSeq->SetFile(texSeqData, Animation::LOOP, 1._f, 0);
}
model->SetAnim(animData, Animation::LOOP, 1._f, 0);
}
if (freeCamera)
{
INV_VIEW_MATRIX_ASR_3 = freeCamera->ToMatrix();
VIEW_MATRIX_ASR_3 = INV_VIEW_MATRIX_ASR_3.Inverse();
model->mat4x3 = cam.camMat.Inverse();
model->mat4x3.c0 = -model->mat4x3.c0;
model->mat4x3.c2 = -model->mat4x3.c2;
const Vector3 modelPos = cam.pos - model->mat4x3.c2 * 143._f - model->mat4x3.c1 * 22._f;
model->mat4x3.c3 = modelPos >> 3;
model->Advance();
texSeq->Advance();
texSeq->Update(model->data);
model->Render(nullptr);
static Matrix4x3 shadowMatrix;
shadowMatrix.Linear() = Matrix3x3::Identity();
shadowMatrix.c3 = modelPos;
shadowMatrix.c3.y -= 56._f;
shadowMatrix.c3 >>= 3;
shadow->InitModel(&shadowMatrix, 70._f, 600._f, 70._f, 15);
}
else
cam.View::Render();
}
template<class T>
static void Delete(T*& ptr)
{
if (ptr)
{
ptr->~T();
ptr = nullptr;
}
}
int repl_0202cae0()
{
freeCamera.reset();
modelFile.Release();
animFile.Release();
texSeqFile.Release();
Delete(model);
Delete(shadow);
Delete(texSeq);
return 0x91c;
}
*/