camera.h (29934B)
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 * Mario's action on this frame. 301 */ 302 /*0x00*/ u32 action; 303 /*0x04*/ Vec3f pos; 304 /*0x10*/ Vec3s faceAngle; 305 /*0x16*/ Vec3s headRotation; 306 /*0x1C*/ s16 unused; 307 /** 308 * Set to nonzero when an event, such as entering a door, starting the credits, or throwing bowser, 309 * has happened on this frame. 310 */ 311 /*0x1E*/ s16 cameraEvent; 312 /*0x20*/ struct Object *usedObj; 313 }; 314 315 /** 316 * Struct containing info that is used when transition_next_state() is called. Stores the intermediate 317 * distances and angular displacements from lakitu's goal position and focus. 318 */ 319 struct TransitionInfo { 320 /*0x00*/ s16 posPitch; 321 /*0x02*/ s16 posYaw; 322 /*0x04*/ f32 posDist; 323 /*0x08*/ s16 focPitch; 324 /*0x0A*/ s16 focYaw; 325 /*0x0C*/ f32 focDist; 326 /*0x10*/ s32 framesLeft; 327 /*0x14*/ Vec3f marioPos; 328 /*0x20*/ u8 unused; // for the structs to align, there has to be an extra unused variable here. type is unknown. 329 }; 330 331 /** 332 * A point that's used in a spline, controls the direction to move the camera in 333 * during the shake effect. 334 */ 335 struct HandheldShakePoint { 336 /*0x00*/ s8 index; // only set to -1 337 /*0x04 (aligned)*/ u32 unused; 338 /*0x08*/ Vec3s point; 339 }; // size = 0x10 340 341 // These are the same type, but the name that is used depends on context. 342 /** 343 * A function that is called by CameraTriggers and cutscene shots. 344 * These are concurrent: multiple CameraEvents can occur on the same frame. 345 */ 346 typedef BAD_RETURN(s32) (*CameraEvent)(struct Camera *c); 347 /** 348 * The same type as a CameraEvent, but because these are generally longer, and happen in sequential 349 * order, they're are called "shots," a term taken from cinematography. 350 * 351 * To further tell the difference: CutsceneShots usually call multiple CameraEvents at once, but only 352 * one CutsceneShot is ever called on a given frame. 353 */ 354 typedef CameraEvent CutsceneShot; 355 356 /** 357 * Defines a bounding box which activates an event while Mario is inside 358 */ 359 struct CameraTrigger { 360 /** 361 * The area this should be checked in, or -1 if it should run in every area of the level. 362 * 363 * Triggers with area set to -1 are run by default, they don't care if Mario is inside their bounds. 364 * However, they are only active if Mario is not already inside an area-specific trigger's 365 * boundaries. 366 */ 367 s8 area; 368 /// A function that gets called while Mario is in the trigger bounds 369 CameraEvent event; 370 // The (x,y,z) position of the center of the bounding box 371 s16 centerX; 372 s16 centerY; 373 s16 centerZ; 374 // The max displacement in x, y, and z from the center for a point to be considered inside the 375 // bounding box 376 s16 boundsX; 377 s16 boundsY; 378 s16 boundsZ; 379 /// This angle rotates Mario's offset from the box's origin, before it is checked for being inside. 380 s16 boundsYaw; 381 }; 382 383 /** 384 * A camera shot that is active for a number of frames. 385 * Together, a sequence of shots makes up a cutscene. 386 */ 387 struct Cutscene { 388 /// The function that gets called. 389 CutsceneShot shot; 390 /// How long the shot lasts. 391 s16 duration; 392 }; 393 394 /** 395 * Info for the camera's field of view and the FOV shake effect. 396 */ 397 struct CameraFOVStatus { 398 /// The current function being used to set the camera's field of view (before any fov shake is applied). 399 /*0x00*/ u8 fovFunc; 400 /// The current field of view in degrees 401 /*0x04*/ f32 fov; 402 403 // Fields used by shake_camera_fov() 404 405 /// The amount to change the current fov by in the fov shake effect. 406 /*0x08*/ f32 fovOffset; 407 /// A bool set in fov_default() but unused otherwise 408 /*0x0C*/ u32 unusedIsSleeping; 409 /// The range in degrees to shake fov 410 /*0x10*/ f32 shakeAmplitude; 411 /// Used to calculate fovOffset, the phase through the shake's period. 412 /*0x14*/ s16 shakePhase; 413 /// How much to progress through the shake period 414 /*0x16*/ s16 shakeSpeed; 415 /// How much to decrease shakeAmplitude each frame. 416 /*0x18*/ s16 decay; 417 }; 418 419 /** 420 * Information for a control point in a spline segment. 421 */ 422 struct CutsceneSplinePoint { 423 /* The index of this point in the spline. Ignored except for -1, which ends the spline. 424 An index of -1 should come four points after the start of the last segment. */ 425 s8 index; 426 /* Roughly controls the number of frames it takes to progress through the spline segment. 427 See move_point_along_spline() in camera.c */ 428 u8 speed; 429 Vec3s point; 430 }; 431 432 /** 433 * Struct containing the nearest floor and ceiling to the player, as well as the previous floor and 434 * ceiling. It also stores their distances from the player's position. 435 */ 436 struct PlayerGeometry { 437 /*0x00*/ struct Surface *currFloor; 438 /*0x04*/ f32 currFloorHeight; 439 /*0x08*/ s16 currFloorType; 440 /*0x0C*/ struct Surface *currCeil; 441 /*0x10*/ s16 currCeilType; 442 /*0x14*/ f32 currCeilHeight; 443 /*0x18*/ struct Surface *prevFloor; 444 /*0x1C*/ f32 prevFloorHeight; 445 /*0x20*/ s16 prevFloorType; 446 /*0x24*/ struct Surface *prevCeil; 447 /*0x28*/ f32 prevCeilHeight; 448 /*0x2C*/ s16 prevCeilType; 449 /// Unused, but recalculated every frame 450 /*0x30*/ f32 waterHeight; 451 }; 452 453 /** 454 * Point used in transitioning between camera modes and C-Up. 455 */ 456 struct LinearTransitionPoint { 457 Vec3f focus; 458 Vec3f pos; 459 f32 dist; 460 s16 pitch; 461 s16 yaw; 462 }; 463 464 /** 465 * Info about transitioning between camera modes. 466 */ 467 struct ModeTransitionInfo { 468 s16 newMode; 469 s16 lastMode; 470 s16 max; 471 s16 frame; 472 struct LinearTransitionPoint transitionStart; 473 struct LinearTransitionPoint transitionEnd; 474 }; 475 476 /** 477 * A point in a path used by update_parallel_tracking_camera 478 */ 479 struct ParallelTrackingPoint { 480 /// Whether this point is the start of a path 481 s16 startOfPath; 482 /// Point used to define a line segment to follow 483 Vec3f pos; 484 /// The distance Mario can move along the line before the camera should move 485 f32 distThresh; 486 /// The percentage that the camera should move from the line to Mario 487 f32 zoom; 488 }; 489 490 /** 491 * Stores the camera's info 492 */ 493 struct CameraStoredInfo { 494 /*0x00*/ Vec3f pos; 495 /*0x0C*/ Vec3f focus; 496 /*0x18*/ f32 panDist; 497 /*0x1C*/ f32 cannonYOffset; 498 }; 499 500 /** 501 * Struct used to store cutscene info, like the camera's target position/focus. 502 * 503 * See the sCutsceneVars[] array in camera.c for more details. 504 */ 505 struct CutsceneVariable { 506 /// Perhaps an index 507 s32 unused1; 508 Vec3f point; 509 Vec3f unusedPoint; 510 Vec3s angle; 511 /// Perhaps a boolean or an extra angle 512 s16 unused2; 513 }; 514 515 /** 516 * The main camera struct. Gets updated by the active camera mode and the current level/area. In 517 * update_lakitu, its pos and focus are used to calculate lakitu's next position and focus, which are 518 * then used to render the game. 519 */ 520 struct Camera { 521 /*0x00*/ u8 mode; // What type of mode the camera uses (see defines above) 522 /*0x01*/ u8 defMode; 523 /** 524 * Determines what direction Mario moves in when the analog stick is moved. 525 * 526 * @warning This is NOT the camera's xz-rotation in world space. This is the angle calculated from the 527 * camera's focus TO the camera's position, instead of the other way around like it should 528 * be. It's effectively the opposite of the camera's actual yaw. Use 529 * vec3f_get_dist_and_angle() if you need the camera's yaw. 530 */ 531 /*0x02*/ s16 yaw; 532 /*0x04*/ Vec3f focus; 533 /*0x10*/ Vec3f pos; 534 /*0x1C*/ Vec3f unusedVec1; 535 /// The x coordinate of the "center" of the area. The camera will rotate around this point. 536 /// For example, this is what makes the camera rotate around the hill in BoB 537 /*0x28*/ f32 areaCenX; 538 /// The z coordinate of the "center" of the area. The camera will rotate around this point. 539 /// For example, this is what makes the camera rotate around the hill in BoB 540 /*0x2C*/ f32 areaCenZ; 541 /*0x30*/ u8 cutscene; 542 /*0x31*/ u8 filler1[8]; 543 /*0x3A*/ s16 nextYaw; 544 /*0x3C*/ u8 filler2[40]; 545 /*0x64*/ u8 doorStatus; 546 /// The y coordinate of the "center" of the area. Unlike areaCenX and areaCenZ, this is only used 547 /// when paused. See zoom_out_if_paused_and_outside 548 /*0x68*/ f32 areaCenY; 549 }; 550 551 /** 552 * A struct containing info pertaining to lakitu, such as his position and focus, and what 553 * camera-related effects are happening to him, like camera shakes. 554 * 555 * This struct's pos and focus are what is actually used to render the game. 556 * 557 * @see update_lakitu() 558 */ 559 struct LakituState { 560 /** 561 * Lakitu's position, which (when CAM_FLAG_SMOOTH_MOVEMENT is set), approaches his goalPos every frame. 562 */ 563 /*0x00*/ Vec3f curFocus; 564 /** 565 * Lakitu's focus, which (when CAM_FLAG_SMOOTH_MOVEMENT is set), approaches his goalFocus every frame. 566 */ 567 /*0x0C*/ Vec3f curPos; 568 /** 569 * The focus point that lakitu turns towards every frame. 570 * If CAM_FLAG_SMOOTH_MOVEMENT is unset, this is the same as curFocus. 571 */ 572 /*0x18*/ Vec3f goalFocus; 573 /** 574 * The point that lakitu flies towards every frame. 575 * If CAM_FLAG_SMOOTH_MOVEMENT is unset, this is the same as curPos. 576 */ 577 /*0x24*/ Vec3f goalPos; 578 579 /*0x30*/ u8 filler1[12]; // extra unused Vec3f? 580 581 /// Copy of the active camera mode 582 /*0x3C*/ u8 mode; 583 /// Copy of the default camera mode 584 /*0x3D*/ u8 defMode; 585 586 /*0x3E*/ u8 filler2[10]; 587 588 /*0x48*/ f32 focusDistance; // unused 589 /*0x4C*/ s16 oldPitch; // unused 590 /*0x4E*/ s16 oldYaw; // unused 591 /*0x50*/ s16 oldRoll; // unused 592 593 /// The angular offsets added to lakitu's pitch, yaw, and roll 594 /*0x52*/ Vec3s shakeMagnitude; 595 596 // shake pitch, yaw, and roll phase: The progression through the camera shake (a cosine wave). 597 // shake pitch, yaw, and roll vel: The speed of the camera shake. 598 // shake pitch, yaw, and roll decay: The shake's deceleration. 599 /*0x58*/ s16 shakePitchPhase; 600 /*0x5A*/ s16 shakePitchVel; 601 /*0x5C*/ s16 shakePitchDecay; 602 603 /*0x60*/ Vec3f unusedVec1; 604 /*0x6C*/ Vec3s unusedVec2; 605 /*0x72*/ u8 filler3[8]; 606 607 /// Used to rotate the screen when rendering. 608 /*0x7A*/ s16 roll; 609 /// Copy of the camera's yaw. 610 /*0x7C*/ s16 yaw; 611 /// Copy of the camera's next yaw. 612 /*0x7E*/ s16 nextYaw; 613 /// The actual focus point the game uses to render. 614 /*0x80*/ Vec3f focus; 615 /// The actual position the game is rendered from. 616 /*0x8C*/ Vec3f pos; 617 618 // Shake variables: See above description 619 /*0x98*/ s16 shakeRollPhase; 620 /*0x9A*/ s16 shakeRollVel; 621 /*0x9C*/ s16 shakeRollDecay; 622 /*0x9E*/ s16 shakeYawPhase; 623 /*0xA0*/ s16 shakeYawVel; 624 /*0xA2*/ s16 shakeYawDecay; 625 626 // focH,Vspeed: how fast lakitu turns towards his goalFocus. 627 /// By default HSpeed is 0.8, so lakitu turns 80% of the horz distance to his goal each frame. 628 /*0xA4*/ f32 focHSpeed; 629 /// By default VSpeed is 0.3, so lakitu turns 30% of the vert distance to his goal each frame. 630 /*0xA8*/ f32 focVSpeed; 631 632 // posH,Vspeed: How fast lakitu flies towards his goalPos. 633 /// By default they are 0.3, so lakitu will fly 30% of the way towards his goal each frame. 634 /*0xAC*/ f32 posHSpeed; 635 /*0xB0*/ f32 posVSpeed; 636 637 /// The roll offset applied during part of the key dance cutscene 638 /*0xB4*/ s16 keyDanceRoll; 639 /// Mario's action from the previous frame. Only used to determine if Mario just finished a dive. 640 /*0xB8*/ u32 lastFrameAction; 641 /*0xBC*/ s16 unused; 642 }; 643 644 // bss order hack to not affect BSS order. if possible, remove me, but it will be hard to match otherwise 645 #ifndef INCLUDED_FROM_CAMERA_C 646 // BSS 647 extern s16 sSelectionFlags; 648 extern s16 sCameraSoundFlags; 649 extern u16 sCButtonsPressed; 650 extern struct PlayerCameraState gPlayerCameraState[2]; 651 extern struct LakituState gLakituState; 652 extern s16 gCameraMovementFlags; 653 extern s32 gObjCutsceneDone; 654 extern struct Camera *gCamera; 655 #endif 656 657 extern struct Object *gCutsceneFocus; 658 extern struct Object *gSecondCameraFocus; 659 extern u8 gRecentCutscene; 660 661 // TODO: sort all of this extremely messy shit out after the split 662 663 void set_camera_shake_from_hit(s16 shake); 664 void set_environmental_camera_shake(s16 shake); 665 void set_camera_shake_from_point(s16 shake, f32 posX, f32 posY, f32 posZ); 666 void move_mario_head_c_up(UNUSED struct Camera *c); 667 void transition_next_state(UNUSED struct Camera *c, s16 frames); 668 void set_camera_mode(struct Camera *c, s16 mode, s16 frames); 669 void update_camera(struct Camera *c); 670 void reset_camera(struct Camera *c); 671 void init_camera(struct Camera *c); 672 void select_mario_cam_mode(void); 673 Gfx *geo_camera_main(s32 callContext, struct GraphNode *g, void *context); 674 void stub_camera_2(UNUSED struct Camera *c); 675 void stub_camera_3(UNUSED struct Camera *c); 676 void vec3f_sub(Vec3f dst, Vec3f src); 677 void object_pos_to_vec3f(Vec3f dst, struct Object *o); 678 void vec3f_to_object_pos(struct Object *o, Vec3f src); 679 s32 move_point_along_spline(Vec3f p, struct CutsceneSplinePoint spline[], s16 *splineSegment, f32 *progress); 680 s32 cam_select_alt_mode(s32 angle); 681 s32 set_cam_angle(s32 mode); 682 void set_handheld_shake(u8 mode); 683 void shake_camera_handheld(Vec3f pos, Vec3f focus); 684 s32 find_c_buttons_pressed(u16 currentState, u16 buttonsPressed, u16 buttonsDown); 685 s32 update_camera_hud_status(struct Camera *c); 686 s32 collide_with_walls(Vec3f pos, f32 offsetY, f32 radius); 687 s32 clamp_pitch(Vec3f from, Vec3f to, s16 maxPitch, s16 minPitch); 688 s32 is_within_100_units_of_mario(f32 posX, f32 posY, f32 posZ); 689 s32 set_or_approach_f32_asymptotic(f32 *dst, f32 goal, f32 scale); 690 s32 approach_f32_asymptotic_bool(f32 *current, f32 target, f32 multiplier); 691 f32 approach_f32_asymptotic(f32 current, f32 target, f32 multiplier); 692 s32 approach_s16_asymptotic_bool(s16 *current, s16 target, s16 divisor); 693 s32 approach_s16_asymptotic(s16 current, s16 target, s16 divisor); 694 void approach_vec3f_asymptotic(Vec3f current, Vec3f target, f32 xMul, f32 yMul, f32 zMul); 695 void set_or_approach_vec3f_asymptotic(Vec3f dst, Vec3f goal, f32 xMul, f32 yMul, f32 zMul); 696 s32 camera_approach_s16_symmetric_bool(s16 *current, s16 target, s16 increment); 697 s32 set_or_approach_s16_symmetric(s16 *current, s16 target, s16 increment); 698 s32 camera_approach_f32_symmetric_bool(f32 *current, f32 target, f32 increment); 699 f32 camera_approach_f32_symmetric(f32 value, f32 target, f32 increment); 700 void random_vec3s(Vec3s dst, s16 xRange, s16 yRange, s16 zRange); 701 s32 clamp_positions_and_find_yaw(Vec3f pos, Vec3f origin, f32 xMax, f32 xMin, f32 zMax, f32 zMin); 702 s32 is_range_behind_surface(Vec3f from, Vec3f to, struct Surface *surf, s16 range, s16 surfType); 703 void scale_along_line(Vec3f dest, Vec3f from, Vec3f to, f32 scale); 704 s16 calculate_pitch(Vec3f from, Vec3f to); 705 s16 calculate_yaw(Vec3f from, Vec3f to); 706 void calculate_angles(Vec3f from, Vec3f to, s16 *pitch, s16 *yaw); 707 f32 calc_abs_dist(Vec3f a, Vec3f b); 708 f32 calc_hor_dist(Vec3f a, Vec3f b); 709 void rotate_in_xz(Vec3f dst, Vec3f src, s16 yaw); 710 void rotate_in_yz(Vec3f dst, Vec3f src, s16 pitch); 711 void set_camera_pitch_shake(s16 mag, s16 decay, s16 inc); 712 void set_camera_yaw_shake(s16 mag, s16 decay, s16 inc); 713 void set_camera_roll_shake(s16 mag, s16 decay, s16 inc); 714 void set_pitch_shake_from_point(s16 mag, s16 decay, s16 inc, f32 maxDist, f32 posX, f32 posY, f32 posZ); 715 void shake_camera_pitch(Vec3f pos, Vec3f focus); 716 void shake_camera_yaw(Vec3f pos, Vec3f focus); 717 void shake_camera_roll(s16 *roll); 718 s32 offset_yaw_outward_radial(struct Camera *c, s16 areaYaw); 719 void play_camera_buzz_if_cdown(void); 720 void play_camera_buzz_if_cbutton(void); 721 void play_camera_buzz_if_c_sideways(void); 722 void play_sound_cbutton_up(void); 723 void play_sound_cbutton_down(void); 724 void play_sound_cbutton_side(void); 725 void play_sound_button_change_blocked(void); 726 void play_sound_rbutton_changed(void); 727 void play_sound_if_cam_switched_to_lakitu_or_mario(void); 728 s32 radial_camera_input(struct Camera *c, UNUSED f32 unused); 729 s32 trigger_cutscene_dialog(s32 trigger); 730 void handle_c_button_movement(struct Camera *c); 731 void start_cutscene(struct Camera *c, u8 cutscene); 732 u8 get_cutscene_from_mario_status(struct Camera *c); 733 void warp_camera(f32 displacementX, f32 displacementY, f32 displacementZ); 734 void approach_camera_height(struct Camera *c, f32 goal, f32 inc); 735 void offset_rotated(Vec3f dst, Vec3f from, Vec3f to, Vec3s rotation); 736 s16 next_lakitu_state(Vec3f newPos, Vec3f newFoc, Vec3f curPos, Vec3f curFoc, Vec3f oldPos, Vec3f oldFoc, s16 yaw); 737 void set_fixed_cam_axis_sa_lobby(UNUSED s16 preset); 738 s16 camera_course_processing(struct Camera *c); 739 void resolve_geometry_collisions(Vec3f pos, UNUSED Vec3f lastGood); 740 s32 rotate_camera_around_walls(struct Camera *c, Vec3f cPos, s16 *avoidYaw, s16 yawRange); 741 void find_mario_floor_and_ceil(struct PlayerGeometry *pg); 742 u8 start_object_cutscene_without_focus(u8 cutscene); 743 s16 cutscene_object_with_dialog(u8 cutscene, struct Object *o, s16 dialogID); 744 s16 cutscene_object_without_dialog(u8 cutscene, struct Object *o); 745 s16 cutscene_object(u8 cutscene, struct Object *o); 746 void play_cutscene(struct Camera *c); 747 s32 cutscene_event(CameraEvent event, struct Camera * c, s16 start, s16 end); 748 s32 cutscene_spawn_obj(u32 obj, s16 frame); 749 void set_fov_shake(s16 amplitude, s16 decay, s16 shakeSpeed); 750 751 void set_fov_function(u8 func); 752 void cutscene_set_fov_shake_preset(u8 preset); 753 void set_fov_shake_from_point_preset(u8 preset, f32 posX, f32 posY, f32 posZ); 754 void obj_rotate_towards_point(struct Object *o, Vec3f point, s16 pitchOff, s16 yawOff, s16 pitchDiv, s16 yawDiv); 755 756 Gfx *geo_camera_fov(s32 callContext, struct GraphNode *g, UNUSED void *context); 757 758 #endif // CAMERA_H