Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MorsGames
GitHub Repository: MorsGames/sm64plus
Path: blob/master/src/game/camera.h
7858 views
1
#ifndef CAMERA_H
2
#define CAMERA_H
3
4
#include <PR/ultratypes.h>
5
6
#include "types.h"
7
#include "area.h"
8
#include "engine/geo_layout.h"
9
#include "engine/graph_node.h"
10
11
#include "level_table.h"
12
13
/**
14
* @file camera.h
15
* Constants, defines, and structs used by the camera system.
16
* @see camera.c
17
*/
18
19
#define ABS(x) ((x) > 0.f ? (x) : -(x))
20
#define ABS2(x) ((x) >= 0.f ? (x) : -(x))
21
22
/**
23
* Converts an angle in degrees to sm64's s16 angle units. For example, DEGREES(90) == 0x4000
24
* This should be used mainly to make camera code clearer at first glance.
25
*/
26
#define DEGREES(x) ((x) * 0x10000 / 360)
27
28
#define LEVEL_AREA_INDEX(levelNum, areaNum) (((levelNum) << 4) + (areaNum))
29
30
/**
31
* Helper macro for defining which areas of a level should zoom out the camera when the game is paused.
32
* Because a mask is used by two levels, the pattern will repeat when more than 4 areas are used by a level.
33
*/
34
#define ZOOMOUT_AREA_MASK(level1Area1, level1Area2, level1Area3, level1Area4, \
35
level2Area1, level2Area2, level2Area3, level2Area4) \
36
((level2Area4) << 7 | \
37
(level2Area3) << 6 | \
38
(level2Area2) << 5 | \
39
(level2Area1) << 4 | \
40
(level1Area4) << 3 | \
41
(level1Area3) << 2 | \
42
(level1Area2) << 1 | \
43
(level1Area1) << 0)
44
45
46
#define AREA_BBH LEVEL_AREA_INDEX(LEVEL_BBH, 1)
47
#define AREA_CCM_OUTSIDE LEVEL_AREA_INDEX(LEVEL_CCM, 1)
48
#define AREA_CCM_SLIDE LEVEL_AREA_INDEX(LEVEL_CCM, 2)
49
#define AREA_CASTLE_LOBBY LEVEL_AREA_INDEX(LEVEL_CASTLE, 1)
50
#define AREA_CASTLE_TIPPY LEVEL_AREA_INDEX(LEVEL_CASTLE, 2)
51
#define AREA_CASTLE_BASEMENT LEVEL_AREA_INDEX(LEVEL_CASTLE, 3)
52
#define AREA_HMC LEVEL_AREA_INDEX(LEVEL_HMC, 1)
53
#define AREA_SSL_OUTSIDE LEVEL_AREA_INDEX(LEVEL_SSL, 1)
54
#define AREA_SSL_PYRAMID LEVEL_AREA_INDEX(LEVEL_SSL, 2)
55
#define AREA_SSL_EYEROK LEVEL_AREA_INDEX(LEVEL_SSL, 3)
56
#define AREA_BOB LEVEL_AREA_INDEX(LEVEL_BOB, 1)
57
#define AREA_SL_OUTSIDE LEVEL_AREA_INDEX(LEVEL_SL, 1)
58
#define AREA_SL_IGLOO LEVEL_AREA_INDEX(LEVEL_SL, 2)
59
#define AREA_WDW_MAIN LEVEL_AREA_INDEX(LEVEL_WDW, 1)
60
#define AREA_WDW_TOWN LEVEL_AREA_INDEX(LEVEL_WDW, 2)
61
#define AREA_JRB_MAIN LEVEL_AREA_INDEX(LEVEL_JRB, 1)
62
#define AREA_JRB_SHIP LEVEL_AREA_INDEX(LEVEL_JRB, 2)
63
#define AREA_THI_HUGE LEVEL_AREA_INDEX(LEVEL_THI, 1)
64
#define AREA_THI_TINY LEVEL_AREA_INDEX(LEVEL_THI, 2)
65
#define AREA_THI_WIGGLER LEVEL_AREA_INDEX(LEVEL_THI, 3)
66
#define AREA_TTC LEVEL_AREA_INDEX(LEVEL_TTC, 1)
67
#define AREA_RR LEVEL_AREA_INDEX(LEVEL_RR, 1)
68
#define AREA_CASTLE_GROUNDS LEVEL_AREA_INDEX(LEVEL_CASTLE_GROUNDS, 1)
69
#define AREA_BITDW LEVEL_AREA_INDEX(LEVEL_BITDW, 1)
70
#define AREA_VCUTM LEVEL_AREA_INDEX(LEVEL_VCUTM, 1)
71
#define AREA_BITFS LEVEL_AREA_INDEX(LEVEL_BITFS, 1)
72
#define AREA_SA LEVEL_AREA_INDEX(LEVEL_SA, 1)
73
#define AREA_BITS LEVEL_AREA_INDEX(LEVEL_BITS, 1)
74
#define AREA_LLL_OUTSIDE LEVEL_AREA_INDEX(LEVEL_LLL, 1)
75
#define AREA_LLL_VOLCANO LEVEL_AREA_INDEX(LEVEL_LLL, 2)
76
#define AREA_DDD_WHIRLPOOL LEVEL_AREA_INDEX(LEVEL_DDD, 1)
77
#define AREA_DDD_SUB LEVEL_AREA_INDEX(LEVEL_DDD, 2)
78
#define AREA_WF LEVEL_AREA_INDEX(LEVEL_WF, 1)
79
#define AREA_ENDING LEVEL_AREA_INDEX(LEVEL_ENDING, 1)
80
#define AREA_COURTYARD LEVEL_AREA_INDEX(LEVEL_CASTLE_COURTYARD, 1)
81
#define AREA_PSS LEVEL_AREA_INDEX(LEVEL_PSS, 1)
82
#define AREA_COTMC LEVEL_AREA_INDEX(LEVEL_COTMC, 1)
83
#define AREA_TOTWC LEVEL_AREA_INDEX(LEVEL_TOTWC, 1)
84
#define AREA_BOWSER_1 LEVEL_AREA_INDEX(LEVEL_BOWSER_1, 1)
85
#define AREA_WMOTR LEVEL_AREA_INDEX(LEVEL_WMOTR, 1)
86
#define AREA_BOWSER_2 LEVEL_AREA_INDEX(LEVEL_BOWSER_2, 1)
87
#define AREA_BOWSER_3 LEVEL_AREA_INDEX(LEVEL_BOWSER_3, 1)
88
#define AREA_TTM_OUTSIDE LEVEL_AREA_INDEX(LEVEL_TTM, 1)
89
90
#define CAM_MODE_MARIO_ACTIVE 0x01
91
#define CAM_MODE_LAKITU_WAS_ZOOMED_OUT 0x02
92
#define CAM_MODE_MARIO_SELECTED 0x04
93
94
#define CAM_SELECTION_MARIO 1
95
#define CAM_SELECTION_FIXED 2
96
97
#define CAM_ANGLE_MARIO 1
98
#define CAM_ANGLE_LAKITU 2
99
100
#define CAMERA_MODE_NONE 0x00
101
#define CAMERA_MODE_RADIAL 0x01
102
#define CAMERA_MODE_OUTWARD_RADIAL 0x02
103
#define CAMERA_MODE_BEHIND_MARIO 0x03
104
#define CAMERA_MODE_CLOSE 0x04 // Inside Castle / Big Boo's Haunt
105
#define CAMERA_MODE_C_UP 0x06
106
#define CAMERA_MODE_WATER_SURFACE 0x08
107
#define CAMERA_MODE_SLIDE_HOOT 0x09
108
#define CAMERA_MODE_INSIDE_CANNON 0x0A
109
#define CAMERA_MODE_BOSS_FIGHT 0x0B
110
#define CAMERA_MODE_PARALLEL_TRACKING 0x0C
111
#define CAMERA_MODE_FIXED 0x0D
112
#define CAMERA_MODE_8_DIRECTIONS 0x0E // AKA Parallel Camera, Bowser Courses & Rainbow Ride
113
#define CAMERA_MODE_FREE_ROAM 0x10
114
#define CAMERA_MODE_SPIRAL_STAIRS 0x11
115
116
#define CAM_MOVE_RETURN_TO_MIDDLE 0x0001
117
#define CAM_MOVE_ZOOMED_OUT 0x0002
118
#define CAM_MOVE_ROTATE_RIGHT 0x0004
119
#define CAM_MOVE_ROTATE_LEFT 0x0008
120
#define CAM_MOVE_ENTERED_ROTATE_SURFACE 0x0010
121
#define CAM_MOVE_METAL_BELOW_WATER 0x0020
122
#define CAM_MOVE_FIX_IN_PLACE 0x0040
123
#define CAM_MOVE_UNKNOWN_8 0x0080
124
#define CAM_MOVING_INTO_MODE 0x0100
125
#define CAM_MOVE_STARTED_EXITING_C_UP 0x0200
126
#define CAM_MOVE_UNKNOWN_11 0x0400
127
#define CAM_MOVE_INIT_CAMERA 0x0800
128
#define CAM_MOVE_ALREADY_ZOOMED_OUT 0x1000
129
#define CAM_MOVE_C_UP_MODE 0x2000
130
#define CAM_MOVE_SUBMERGED 0x4000
131
#define CAM_MOVE_PAUSE_SCREEN 0x8000
132
133
#define CAM_MOVE_ROTATE /**/ (CAM_MOVE_ROTATE_RIGHT | CAM_MOVE_ROTATE_LEFT | CAM_MOVE_RETURN_TO_MIDDLE)
134
/// These flags force the camera to move a certain way
135
#define CAM_MOVE_RESTRICT /**/ (CAM_MOVE_ENTERED_ROTATE_SURFACE | CAM_MOVE_METAL_BELOW_WATER | CAM_MOVE_FIX_IN_PLACE | CAM_MOVE_UNKNOWN_8)
136
137
#define CAM_SOUND_C_UP_PLAYED 0x01
138
#define CAM_SOUND_MARIO_ACTIVE 0x02
139
#define CAM_SOUND_NORMAL_ACTIVE 0x04
140
#define CAM_SOUND_UNUSED_SELECT_MARIO 0x08
141
#define CAM_SOUND_UNUSED_SELECT_FIXED 0x10
142
#define CAM_SOUND_FIXED_ACTIVE 0x20
143
144
#define CAM_FLAG_SMOOTH_MOVEMENT 0x0001
145
#define CAM_FLAG_BLOCK_SMOOTH_MOVEMENT 0x0002
146
#define CAM_FLAG_FRAME_AFTER_CAM_INIT 0x0004
147
#define CAM_FLAG_CHANGED_PARTRACK_INDEX 0x0008
148
#define CAM_FLAG_CCM_SLIDE_SHORTCUT 0x0010
149
#define CAM_FLAG_CAM_NEAR_WALL 0x0020
150
#define CAM_FLAG_SLEEPING 0x0040
151
#define CAM_FLAG_UNUSED_7 0x0080
152
#define CAM_FLAG_UNUSED_8 0x0100
153
#define CAM_FLAG_COLLIDED_WITH_WALL 0x0200
154
#define CAM_FLAG_START_TRANSITION 0x0400
155
#define CAM_FLAG_TRANSITION_OUT_OF_C_UP 0x0800
156
#define CAM_FLAG_BLOCK_AREA_PROCESSING 0x1000
157
#define CAM_FLAG_UNUSED_13 0x2000
158
#define CAM_FLAG_UNUSED_CUTSCENE_ACTIVE 0x4000
159
#define CAM_FLAG_BEHIND_MARIO_POST_DOOR 0x8000
160
161
#define CAM_STATUS_NONE 0
162
#define CAM_STATUS_MARIO 1 << 0
163
#define CAM_STATUS_LAKITU 1 << 1
164
#define CAM_STATUS_FIXED 1 << 2
165
#define CAM_STATUS_C_DOWN 1 << 3
166
#define CAM_STATUS_C_UP 1 << 4
167
168
#define CAM_STATUS_MODE_GROUP (CAM_STATUS_MARIO | CAM_STATUS_LAKITU | CAM_STATUS_FIXED)
169
#define CAM_STATUS_C_MODE_GROUP (CAM_STATUS_C_DOWN | CAM_STATUS_C_UP)
170
171
#define SHAKE_ATTACK 1
172
#define SHAKE_GROUND_POUND 2
173
#define SHAKE_SMALL_DAMAGE 3
174
#define SHAKE_MED_DAMAGE 4
175
#define SHAKE_LARGE_DAMAGE 5
176
#define SHAKE_HIT_FROM_BELOW 8
177
#define SHAKE_FALL_DAMAGE 9
178
#define SHAKE_SHOCK 10
179
180
#define SHAKE_ENV_EXPLOSION 1
181
#define SHAKE_ENV_BOWSER_THROW_BOUNCE 2
182
#define SHAKE_ENV_BOWSER_JUMP 3
183
#define SHAKE_ENV_UNUSED_5 5
184
#define SHAKE_ENV_UNUSED_6 6
185
#define SHAKE_ENV_UNUSED_7 7
186
#define SHAKE_ENV_PYRAMID_EXPLODE 8
187
#define SHAKE_ENV_JRB_SHIP_DRAIN 9
188
#define SHAKE_ENV_FALLING_BITS_PLAT 10
189
190
#define SHAKE_FOV_SMALL 1
191
#define SHAKE_FOV_UNUSED 2
192
#define SHAKE_FOV_MEDIUM 3
193
#define SHAKE_FOV_LARGE 4
194
195
#define SHAKE_POS_SMALL 1
196
#define SHAKE_POS_MEDIUM 2
197
#define SHAKE_POS_LARGE 3
198
#define SHAKE_POS_BOWLING_BALL 4
199
200
#define CUTSCENE_DOOR_PULL 130
201
#define CUTSCENE_DOOR_PUSH 131
202
#define CUTSCENE_ENTER_CANNON 133
203
#define CUTSCENE_ENTER_PAINTING 134
204
#define CUTSCENE_DEATH_EXIT 135
205
#define CUTSCENE_DOOR_WARP 139
206
#define CUTSCENE_DOOR_PULL_MODE 140
207
#define CUTSCENE_DOOR_PUSH_MODE 141
208
#define CUTSCENE_INTRO_PEACH 142
209
#define CUTSCENE_DANCE_ROTATE 143
210
#define CUTSCENE_ENTER_BOWSER_ARENA 144
211
#define CUTSCENE_0F_UNUSED 145 // Never activated, stub cutscene functions
212
#define CUTSCENE_UNUSED_EXIT 147 // Never activated
213
#define CUTSCENE_SLIDING_DOORS_OPEN 149
214
#define CUTSCENE_PREPARE_CANNON 150
215
#define CUTSCENE_UNLOCK_KEY_DOOR 151
216
#define CUTSCENE_STANDING_DEATH 152
217
#define CUTSCENE_DEATH_ON_STOMACH 153
218
#define CUTSCENE_DEATH_ON_BACK 154
219
#define CUTSCENE_QUICKSAND_DEATH 155
220
#define CUTSCENE_SUFFOCATION_DEATH 156
221
#define CUTSCENE_EXIT_BOWSER_SUCC 157
222
#define CUTSCENE_EXIT_BOWSER_DEATH 158 // Never activated
223
#define CUTSCENE_WATER_DEATH 159 // Not in cutscene switch
224
#define CUTSCENE_EXIT_PAINTING_SUCC 160
225
#define CUTSCENE_CAP_SWITCH_PRESS 161
226
#define CUTSCENE_DIALOG 162
227
#define CUTSCENE_RACE_DIALOG 163
228
#define CUTSCENE_ENTER_PYRAMID_TOP 164
229
#define CUTSCENE_DANCE_FLY_AWAY 165
230
#define CUTSCENE_DANCE_CLOSEUP 166
231
#define CUTSCENE_KEY_DANCE 167
232
#define CUTSCENE_SSL_PYRAMID_EXPLODE 168 // Never activated
233
#define CUTSCENE_EXIT_SPECIAL_SUCC 169
234
#define CUTSCENE_NONPAINTING_DEATH 170
235
#define CUTSCENE_READ_MESSAGE 171
236
#define CUTSCENE_ENDING 172
237
#define CUTSCENE_STAR_SPAWN 173
238
#define CUTSCENE_GRAND_STAR 174
239
#define CUTSCENE_DANCE_DEFAULT 175
240
#define CUTSCENE_RED_COIN_STAR_SPAWN 176
241
#define CUTSCENE_END_WAVING 177
242
#define CUTSCENE_CREDITS 178
243
#define CUTSCENE_EXIT_WATERFALL 179
244
#define CUTSCENE_EXIT_FALL_WMOTR 180
245
#define CUTSCENE_ENTER_POOL 181
246
247
/**
248
* Stop the cutscene.
249
*/
250
#define CUTSCENE_STOP 0x8000
251
/**
252
* Play the current cutscene shot indefinitely (until canceled).
253
*/
254
#define CUTSCENE_LOOP 0x7FFF
255
256
#define HAND_CAM_SHAKE_OFF 0
257
#define HAND_CAM_SHAKE_CUTSCENE 1
258
#define HAND_CAM_SHAKE_UNUSED 2
259
#define HAND_CAM_SHAKE_HANG_OWL 3
260
#define HAND_CAM_SHAKE_HIGH 4
261
#define HAND_CAM_SHAKE_STAR_DANCE 5
262
#define HAND_CAM_SHAKE_LOW 6
263
264
#define DOOR_DEFAULT 0
265
#define DOOR_LEAVING_SPECIAL 1
266
#define DOOR_ENTER_LOBBY 2
267
268
// Might rename these to reflect what they are used for instead "SET_45" etc.
269
#define CAM_FOV_SET_45 1
270
#define CAM_FOV_DEFAULT 2
271
#define CAM_FOV_APP_45 4
272
#define CAM_FOV_SET_30 5
273
#define CAM_FOV_APP_20 6
274
#define CAM_FOV_BBH 7
275
#define CAM_FOV_APP_80 9
276
#define CAM_FOV_APP_30 10
277
#define CAM_FOV_APP_60 11
278
#define CAM_FOV_ZOOM_30 12
279
#define CAM_FOV_SET_29 13
280
281
#define CAM_EVENT_CANNON 1
282
#define CAM_EVENT_SHOT_FROM_CANNON 2
283
#define CAM_EVENT_UNUSED_3 3
284
#define CAM_EVENT_BOWSER_INIT 4
285
#define CAM_EVENT_DOOR_WARP 5
286
#define CAM_EVENT_DOOR 6
287
#define CAM_EVENT_BOWSER_JUMP 7
288
#define CAM_EVENT_BOWSER_THROW_BOUNCE 8
289
#define CAM_EVENT_START_INTRO 9
290
#define CAM_EVENT_START_GRAND_STAR 10
291
#define CAM_EVENT_START_ENDING 11
292
#define CAM_EVENT_START_END_WAVING 12
293
#define CAM_EVENT_START_CREDITS 13
294
295
/**
296
* A copy of player information that is relevant to the camera.
297
*/
298
struct PlayerCameraState
299
{
300
/**
301
* Mario's action on this frame.
302
*/
303
/*0x00*/ u32 action;
304
/*0x04*/ Vec3f pos;
305
/*0x10*/ Vec3s faceAngle;
306
/*0x16*/ Vec3s headRotation;
307
/*0x1C*/ s16 unused;
308
/**
309
* Set to nonzero when an event, such as entering a door, starting the credits, or throwing bowser,
310
* has happened on this frame.
311
*/
312
/*0x1E*/ s16 cameraEvent;
313
/*0x20*/ struct Object *usedObj;
314
};
315
316
/**
317
* Struct containing info that is used when transition_next_state() is called. Stores the intermediate
318
* distances and angular displacements from lakitu's goal position and focus.
319
*/
320
struct TransitionInfo
321
{
322
/*0x00*/ s16 posPitch;
323
/*0x02*/ s16 posYaw;
324
/*0x04*/ f32 posDist;
325
/*0x08*/ s16 focPitch;
326
/*0x0A*/ s16 focYaw;
327
/*0x0C*/ f32 focDist;
328
/*0x10*/ s32 framesLeft;
329
/*0x14*/ Vec3f marioPos;
330
/*0x20*/ u8 pad; // for the structs to align, there has to be an extra unused variable here. type is unknown.
331
};
332
333
/**
334
* A point that's used in a spline, controls the direction to move the camera in
335
* during the shake effect.
336
*/
337
struct HandheldShakePoint
338
{
339
/*0x00*/ s8 index; // only set to -1
340
/*0x04 (aligned)*/ u32 pad;
341
/*0x08*/ Vec3s point;
342
}; // size = 0x10
343
344
// These are the same type, but the name that is used depends on context.
345
/**
346
* A function that is called by CameraTriggers and cutscene shots.
347
* These are concurrent: multiple CameraEvents can occur on the same frame.
348
*/
349
typedef BAD_RETURN(s32) (*CameraEvent)(struct Camera *c);
350
/**
351
* The same type as a CameraEvent, but because these are generally longer, and happen in sequential
352
* order, they're are called "shots," a term taken from cinematography.
353
*
354
* To further tell the difference: CutsceneShots usually call multiple CameraEvents at once, but only
355
* one CutsceneShot is ever called on a given frame.
356
*/
357
typedef CameraEvent CutsceneShot;
358
359
/**
360
* Defines a bounding box which activates an event while Mario is inside
361
*/
362
struct CameraTrigger
363
{
364
/**
365
* The area this should be checked in, or -1 if it should run in every area of the level.
366
*
367
* Triggers with area set to -1 are run by default, they don't care if Mario is inside their bounds.
368
* However, they are only active if Mario is not already inside an area-specific trigger's
369
* boundaries.
370
*/
371
s8 area;
372
/// A function that gets called while Mario is in the trigger bounds
373
CameraEvent event;
374
// The (x,y,z) position of the center of the bounding box
375
s16 centerX;
376
s16 centerY;
377
s16 centerZ;
378
// The max displacement in x, y, and z from the center for a point to be considered inside the
379
// bounding box
380
s16 boundsX;
381
s16 boundsY;
382
s16 boundsZ;
383
/// This angle rotates Mario's offset from the box's origin, before it is checked for being inside.
384
s16 boundsYaw;
385
};
386
387
/**
388
* A camera shot that is active for a number of frames.
389
* Together, a sequence of shots makes up a cutscene.
390
*/
391
struct Cutscene
392
{
393
/// The function that gets called.
394
CutsceneShot shot;
395
/// How long the shot lasts.
396
s16 duration;
397
};
398
399
/**
400
* Info for the camera's field of view and the FOV shake effect.
401
*/
402
struct CameraFOVStatus
403
{
404
/// The current function being used to set the camera's field of view (before any fov shake is applied).
405
/*0x00*/ u8 fovFunc;
406
/// The current field of view in degrees
407
/*0x04*/ f32 fov;
408
409
// Fields used by shake_camera_fov()
410
411
/// The amount to change the current fov by in the fov shake effect.
412
/*0x08*/ f32 fovOffset;
413
/// A bool set in fov_default() but unused otherwise
414
/*0x0C*/ u32 unusedIsSleeping;
415
/// The range in degrees to shake fov
416
/*0x10*/ f32 shakeAmplitude;
417
/// Used to calculate fovOffset, the phase through the shake's period.
418
/*0x14*/ s16 shakePhase;
419
/// How much to progress through the shake period
420
/*0x16*/ s16 shakeSpeed;
421
/// How much to decrease shakeAmplitude each frame.
422
/*0x18*/ s16 decay;
423
};
424
425
/**
426
* Information for a control point in a spline segment.
427
*/
428
struct CutsceneSplinePoint
429
{
430
/* The index of this point in the spline. Ignored except for -1, which ends the spline.
431
An index of -1 should come four points after the start of the last segment. */
432
s8 index;
433
/* Roughly controls the number of frames it takes to progress through the spline segment.
434
See move_point_along_spline() in camera.c */
435
u8 speed;
436
Vec3s point;
437
};
438
439
/**
440
* Struct containing the nearest floor and ceiling to the player, as well as the previous floor and
441
* ceiling. It also stores their distances from the player's position.
442
*/
443
struct PlayerGeometry
444
{
445
/*0x00*/ struct Surface *currFloor;
446
/*0x04*/ f32 currFloorHeight;
447
/*0x08*/ s16 currFloorType;
448
/*0x0C*/ struct Surface *currCeil;
449
/*0x10*/ s16 currCeilType;
450
/*0x14*/ f32 currCeilHeight;
451
/*0x18*/ struct Surface *prevFloor;
452
/*0x1C*/ f32 prevFloorHeight;
453
/*0x20*/ s16 prevFloorType;
454
/*0x24*/ struct Surface *prevCeil;
455
/*0x28*/ f32 prevCeilHeight;
456
/*0x2C*/ s16 prevCeilType;
457
/// Unused, but recalculated every frame
458
/*0x30*/ f32 waterHeight;
459
};
460
461
/**
462
* Point used in transitioning between camera modes and C-Up.
463
*/
464
struct LinearTransitionPoint
465
{
466
Vec3f focus;
467
Vec3f pos;
468
f32 dist;
469
s16 pitch;
470
s16 yaw;
471
};
472
473
/**
474
* Info about transitioning between camera modes.
475
*/
476
struct ModeTransitionInfo
477
{
478
s16 newMode;
479
s16 lastMode;
480
s16 max;
481
s16 frame;
482
struct LinearTransitionPoint transitionStart;
483
struct LinearTransitionPoint transitionEnd;
484
};
485
486
/**
487
* A point in a path used by update_parallel_tracking_camera
488
*/
489
struct ParallelTrackingPoint
490
{
491
/// Whether this point is the start of a path
492
s16 startOfPath;
493
/// Point used to define a line segment to follow
494
Vec3f pos;
495
/// The distance Mario can move along the line before the camera should move
496
f32 distThresh;
497
/// The percentage that the camera should move from the line to Mario
498
f32 zoom;
499
};
500
501
/**
502
* Stores the camera's info
503
*/
504
struct CameraStoredInfo
505
{
506
/*0x00*/ Vec3f pos;
507
/*0x0C*/ Vec3f focus;
508
/*0x18*/ f32 panDist;
509
/*0x1C*/ f32 cannonYOffset;
510
};
511
512
/**
513
* Struct used to store cutscene info, like the camera's target position/focus.
514
*
515
* See the sCutsceneVars[] array in camera.c for more details.
516
*/
517
struct CutsceneVariable
518
{
519
/// Perhaps an index
520
s32 unused1;
521
Vec3f point;
522
Vec3f unusedPoint;
523
Vec3s angle;
524
/// Perhaps a boolean or an extra angle
525
s16 unused2;
526
};
527
528
/**
529
* The main camera struct. Gets updated by the active camera mode and the current level/area. In
530
* update_lakitu, its pos and focus are used to calculate lakitu's next position and focus, which are
531
* then used to render the game.
532
*/
533
struct Camera
534
{
535
/*0x00*/ u8 mode; // What type of mode the camera uses (see defines above)
536
/*0x01*/ u8 defMode;
537
/**
538
* Determines what direction Mario moves in when the analog stick is moved.
539
*
540
* @warning This is NOT the camera's xz-rotation in world space. This is the angle calculated from the
541
* camera's focus TO the camera's position, instead of the other way around like it should
542
* be. It's effectively the opposite of the camera's actual yaw. Use
543
* vec3f_get_dist_and_angle() if you need the camera's yaw.
544
*/
545
/*0x02*/ s16 yaw;
546
/*0x04*/ Vec3f focus;
547
/*0x10*/ Vec3f pos;
548
/*0x1C*/ Vec3f unusedVec1;
549
/// The x coordinate of the "center" of the area. The camera will rotate around this point.
550
/// For example, this is what makes the camera rotate around the hill in BoB
551
/*0x28*/ f32 areaCenX;
552
/// The z coordinate of the "center" of the area. The camera will rotate around this point.
553
/// For example, this is what makes the camera rotate around the hill in BoB
554
/*0x2C*/ f32 areaCenZ;
555
/*0x30*/ u8 cutscene;
556
/*0x31*/ u8 filler31[0x8];
557
/*0x3A*/ s16 nextYaw;
558
/*0x3C*/ u8 filler3C[0x28];
559
/*0x64*/ u8 doorStatus;
560
/// The y coordinate of the "center" of the area. Unlike areaCenX and areaCenZ, this is only used
561
/// when paused. See zoom_out_if_paused_and_outside
562
/*0x68*/ f32 areaCenY;
563
};
564
565
/**
566
* A struct containing info pertaining to lakitu, such as his position and focus, and what
567
* camera-related effects are happening to him, like camera shakes.
568
*
569
* This struct's pos and focus are what is actually used to render the game.
570
*
571
* @see update_lakitu()
572
*/
573
struct LakituState
574
{
575
/**
576
* Lakitu's position, which (when CAM_FLAG_SMOOTH_MOVEMENT is set), approaches his goalPos every frame.
577
*/
578
/*0x00*/ Vec3f curFocus;
579
/**
580
* Lakitu's focus, which (when CAM_FLAG_SMOOTH_MOVEMENT is set), approaches his goalFocus every frame.
581
*/
582
/*0x0C*/ Vec3f curPos;
583
/**
584
* The focus point that lakitu turns towards every frame.
585
* If CAM_FLAG_SMOOTH_MOVEMENT is unset, this is the same as curFocus.
586
*/
587
/*0x18*/ Vec3f goalFocus;
588
/**
589
* The point that lakitu flies towards every frame.
590
* If CAM_FLAG_SMOOTH_MOVEMENT is unset, this is the same as curPos.
591
*/
592
/*0x24*/ Vec3f goalPos;
593
594
/*0x30*/ u8 filler30[12]; // extra unused Vec3f?
595
596
/// Copy of the active camera mode
597
/*0x3C*/ u8 mode;
598
/// Copy of the default camera mode
599
/*0x3D*/ u8 defMode;
600
601
/*0x3E*/ u8 filler3E[10];
602
603
/*0x48*/ f32 focusDistance; // unused
604
/*0x4C*/ s16 oldPitch; // unused
605
/*0x4E*/ s16 oldYaw; // unused
606
/*0x50*/ s16 oldRoll; // unused
607
608
/// The angular offsets added to lakitu's pitch, yaw, and roll
609
/*0x52*/ Vec3s shakeMagnitude;
610
611
// shake pitch, yaw, and roll phase: The progression through the camera shake (a cosine wave).
612
// shake pitch, yaw, and roll vel: The speed of the camera shake.
613
// shake pitch, yaw, and roll decay: The shake's deceleration.
614
/*0x58*/ s16 shakePitchPhase;
615
/*0x5A*/ s16 shakePitchVel;
616
/*0x5C*/ s16 shakePitchDecay;
617
618
/*0x60*/ Vec3f unusedVec1;
619
/*0x6C*/ Vec3s unusedVec2;
620
/*0x72*/ u8 filler72[8];
621
622
/// Used to rotate the screen when rendering.
623
/*0x7A*/ s16 roll;
624
/// Copy of the camera's yaw.
625
/*0x7C*/ s16 yaw;
626
/// Copy of the camera's next yaw.
627
/*0x7E*/ s16 nextYaw;
628
/// The actual focus point the game uses to render.
629
/*0x80*/ Vec3f focus;
630
/// The actual position the game is rendered from.
631
/*0x8C*/ Vec3f pos;
632
633
// Shake variables: See above description
634
/*0x98*/ s16 shakeRollPhase;
635
/*0x9A*/ s16 shakeRollVel;
636
/*0x9C*/ s16 shakeRollDecay;
637
/*0x9E*/ s16 shakeYawPhase;
638
/*0xA0*/ s16 shakeYawVel;
639
/*0xA2*/ s16 shakeYawDecay;
640
641
// focH,Vspeed: how fast lakitu turns towards his goalFocus.
642
/// By default HSpeed is 0.8, so lakitu turns 80% of the horz distance to his goal each frame.
643
/*0xA4*/ f32 focHSpeed;
644
/// By default VSpeed is 0.3, so lakitu turns 30% of the vert distance to his goal each frame.
645
/*0xA8*/ f32 focVSpeed;
646
647
// posH,Vspeed: How fast lakitu flies towards his goalPos.
648
/// By default they are 0.3, so lakitu will fly 30% of the way towards his goal each frame.
649
/*0xAC*/ f32 posHSpeed;
650
/*0xB0*/ f32 posVSpeed;
651
652
/// The roll offset applied during part of the key dance cutscene
653
/*0xB4*/ s16 keyDanceRoll;
654
/// Mario's action from the previous frame. Only used to determine if Mario just finished a dive.
655
/*0xB8*/ u32 lastFrameAction;
656
/*0xBC*/ s16 unused;
657
658
u32 skipCameraInterpolationTimestamp;
659
};
660
661
// bss order hack to not affect BSS order. if possible, remove me, but it will be hard to match otherwise
662
#ifndef INCLUDED_FROM_CAMERA_C
663
// BSS
664
extern s16 sSelectionFlags;
665
extern s16 sCameraSoundFlags;
666
extern u16 sCButtonsPressed;
667
extern struct PlayerCameraState gPlayerCameraState[2];
668
extern struct LakituState gLakituState;
669
extern s16 gCameraMovementFlags;
670
extern s32 gObjCutsceneDone;
671
extern struct Camera *gCamera;
672
#endif
673
674
extern struct Object *gCutsceneFocus;
675
extern struct Object *gSecondCameraFocus;
676
extern u8 gRecentCutscene;
677
678
// TODO: sort all of this extremely messy shit out after the split
679
680
void set_camera_shake_from_hit(s16 shake);
681
void set_environmental_camera_shake(s16 shake);
682
void set_camera_shake_from_point(s16 shake, f32 posX, f32 posY, f32 posZ);
683
void move_mario_head_c_up(UNUSED struct Camera *c);
684
void transition_next_state(UNUSED struct Camera *c, s16 frames);
685
void set_camera_mode(struct Camera *c, s16 mode, s16 frames);
686
void update_camera(struct Camera *c);
687
void reset_camera(struct Camera *c);
688
void init_camera(struct Camera *c);
689
void select_mario_cam_mode(void);
690
Gfx *geo_camera_main(s32 callContext, struct GraphNode *g, void *context);
691
void stub_camera_2(UNUSED struct Camera *c);
692
void stub_camera_3(UNUSED struct Camera *c);
693
void vec3f_sub(Vec3f dst, Vec3f src);
694
void object_pos_to_vec3f(Vec3f dst, struct Object *o);
695
void vec3f_to_object_pos(struct Object *o, Vec3f src);
696
s32 move_point_along_spline(Vec3f p, struct CutsceneSplinePoint spline[], s16 *splineSegment, f32 *progress);
697
s32 cam_select_alt_mode(s32 angle);
698
s32 set_cam_angle(s32 mode);
699
void set_handheld_shake(u8 mode);
700
void shake_camera_handheld(Vec3f pos, Vec3f focus);
701
s32 find_c_buttons_pressed(u16 currentState, u16 buttonsPressed, u16 buttonsDown);
702
s32 update_camera_hud_status(struct Camera *c);
703
s32 collide_with_walls(Vec3f pos, f32 offsetY, f32 radius);
704
s32 clamp_pitch(Vec3f from, Vec3f to, s16 maxPitch, s16 minPitch);
705
s32 is_within_100_units_of_mario(f32 posX, f32 posY, f32 posZ);
706
s32 set_or_approach_f32_asymptotic(f32 *dst, f32 goal, f32 scale);
707
s32 approach_f32_asymptotic_bool(f32 *current, f32 target, f32 multiplier);
708
f32 approach_f32_asymptotic(f32 current, f32 target, f32 multiplier);
709
s32 approach_s16_asymptotic_bool(s16 *current, s16 target, s16 divisor);
710
s32 approach_s16_asymptotic(s16 current, s16 target, s16 divisor);
711
void approach_vec3f_asymptotic(Vec3f current, Vec3f target, f32 xMul, f32 yMul, f32 zMul);
712
void set_or_approach_vec3f_asymptotic(Vec3f dst, Vec3f goal, f32 xMul, f32 yMul, f32 zMul);
713
s32 camera_approach_s16_symmetric_bool(s16 *current, s16 target, s16 increment);
714
s32 set_or_approach_s16_symmetric(s16 *current, s16 target, s16 increment);
715
s32 camera_approach_f32_symmetric_bool(f32 *current, f32 target, f32 increment);
716
f32 camera_approach_f32_symmetric(f32 value, f32 target, f32 increment);
717
void random_vec3s(Vec3s dst, s16 xRange, s16 yRange, s16 zRange);
718
s32 clamp_positions_and_find_yaw(Vec3f pos, Vec3f origin, f32 xMax, f32 xMin, f32 zMax, f32 zMin);
719
s32 is_range_behind_surface(Vec3f from, Vec3f to, struct Surface *surf, s16 range, s16 surfType);
720
void scale_along_line(Vec3f dest, Vec3f from, Vec3f to, f32 scale);
721
s16 calculate_pitch(Vec3f from, Vec3f to);
722
s16 calculate_yaw(Vec3f from, Vec3f to);
723
void calculate_angles(Vec3f from, Vec3f to, s16 *pitch, s16 *yaw);
724
f32 calc_abs_dist(Vec3f a, Vec3f b);
725
f32 calc_hor_dist(Vec3f a, Vec3f b);
726
void rotate_in_xz(Vec3f dst, Vec3f src, s16 yaw);
727
void rotate_in_yz(Vec3f dst, Vec3f src, s16 pitch);
728
void set_camera_pitch_shake(s16 mag, s16 decay, s16 inc);
729
void set_camera_yaw_shake(s16 mag, s16 decay, s16 inc);
730
void set_camera_roll_shake(s16 mag, s16 decay, s16 inc);
731
void set_pitch_shake_from_point(s16 mag, s16 decay, s16 inc, f32 maxDist, f32 posX, f32 posY, f32 posZ);
732
void shake_camera_pitch(Vec3f pos, Vec3f focus);
733
void shake_camera_yaw(Vec3f pos, Vec3f focus);
734
void shake_camera_roll(s16 *roll);
735
s32 offset_yaw_outward_radial(struct Camera *c, s16 areaYaw);
736
void play_camera_buzz_if_cdown(void);
737
void play_camera_buzz_if_cbutton(void);
738
void play_camera_buzz_if_c_sideways(void);
739
void play_sound_cbutton_up(void);
740
void play_sound_cbutton_down(void);
741
void play_sound_cbutton_side(void);
742
void play_sound_button_change_blocked(void);
743
void play_sound_rbutton_changed(void);
744
void play_sound_if_cam_switched_to_lakitu_or_mario(void);
745
s32 radial_camera_input(struct Camera *c, UNUSED f32 unused);
746
s32 trigger_cutscene_dialog(s32 trigger);
747
void handle_c_button_movement(struct Camera *c);
748
void start_cutscene(struct Camera *c, u8 cutscene);
749
u8 get_cutscene_from_mario_status(struct Camera *c);
750
void warp_camera(f32 displacementX, f32 displacementY, f32 displacementZ);
751
void approach_camera_height(struct Camera *c, f32 goal, f32 inc);
752
void offset_rotated(Vec3f dst, Vec3f from, Vec3f to, Vec3s rotation);
753
s16 next_lakitu_state(Vec3f newPos, Vec3f newFoc, Vec3f curPos, Vec3f curFoc, Vec3f oldPos, Vec3f oldFoc, s16 yaw);
754
void set_fixed_cam_axis_sa_lobby(UNUSED s16 preset);
755
s16 camera_course_processing(struct Camera *c);
756
void resolve_geometry_collisions(Vec3f pos, UNUSED Vec3f lastGood);
757
s32 rotate_camera_around_walls(struct Camera *c, Vec3f cPos, s16 *avoidYaw, s16 yawRange);
758
void find_mario_floor_and_ceil(struct PlayerGeometry *pg);
759
u8 start_object_cutscene_without_focus(u8 cutscene);
760
s16 cutscene_object_with_dialog(u8 cutscene, struct Object *o, s16 dialogID);
761
s16 cutscene_object_without_dialog(u8 cutscene, struct Object *o);
762
s16 cutscene_object(u8 cutscene, struct Object *o);
763
void play_cutscene(struct Camera *c);
764
s32 cutscene_event(CameraEvent event, struct Camera * c, s16 start, s16 end);
765
s32 cutscene_spawn_obj(u32 obj, s16 frame);
766
void set_fov_shake(s16 amplitude, s16 decay, s16 shakeSpeed);
767
768
void set_fov_function(u8 func);
769
void cutscene_set_fov_shake_preset(u8 preset);
770
void set_fov_shake_from_point_preset(u8 preset, f32 posX, f32 posY, f32 posZ);
771
void obj_rotate_towards_point(struct Object *o, Vec3f point, s16 pitchOff, s16 yawOff, s16 pitchDiv, s16 yawDiv);
772
773
Gfx *geo_camera_fov(s32 callContext, struct GraphNode *g, UNUSED void *context);
774
775
#endif // CAMERA_H
776
777