Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
camera.h File Reference

Go to the source code of this file.

Functions

void update_camera_minimal (Camera *)
 
void update_camera_no_interp (Camera *)
 
void update_camera_interp_pos (Camera *)
 
void update_camera_zone_interp (Camera *camera)
 
void update_camera_unused_confined (Camera *)
 
void update_camera_unused_leading (Camera *)
 
void update_camera_unused_radial (Camera *)
 
void update_camera_unused_ahead (Camera *)
 
void create_camera_leadplayer_matrix (Camera *)
 
Camerainitialize_next_camera (CameraInitData *data)
 

Variables

f32 CamLengthScale
 

Function Documentation

◆ update_camera_minimal()

void update_camera_minimal ( Camera * camera)

Definition at line 9 of file cam_mode_minimal.c.

9 {
10 f32 dx, dy, dz, dr;
11
12 if (camera->needsInit) {
13 camera->needsInit = FALSE;
14
15 camera->lookAt_obj.x = 0.0f;
16 camera->lookAt_obj.y = 0.0f;
17 camera->lookAt_obj.z = 0.0f;
18
19 camera->lookAt_eye.x = camera->lookAt_obj.x;
20 camera->lookAt_eye.y = camera->lookAt_obj.y;
21 camera->lookAt_eye.z = camera->lookAt_obj.z - (1000.0f / CamLengthScale);
22 }
23
24 dx = camera->lookAt_obj.x - camera->lookAt_eye.x;
25 dy = camera->lookAt_obj.y - camera->lookAt_eye.y;
26 dz = camera->lookAt_obj.z - camera->lookAt_eye.z;
27 dr = sqrtf(SQ(dx) + SQ(dz));
28
29 camera->lookAt_yaw = -atan2(0.0f, 0.0f, dx, dz);
30 camera->lookAt_pitch = atan2(0.0f, 0.0f, dy, -dr);
31 camera->curYaw = atan2(camera->lookAt_eye.x, camera->lookAt_eye.z, camera->lookAt_obj.x, camera->lookAt_obj.z);
32}
f32 CamLengthScale
Definition cam_main.c:12
#define sqrtf
#define atan2
#define SQ(x)
Definition macros.h:166
Vec3f lookAt_obj
f32 lookAt_pitch
Vec3f lookAt_eye

Referenced by update_cameras().

◆ update_camera_no_interp()

void update_camera_no_interp ( Camera * camera)

Definition at line 16 of file cam_mode_no_interp.c.

16 {
17 f32 yawAngle, sinYaw, cosYaw;
18 f32 pitchAngle, sinPitch, cosPitch;
19 f32 dx, dy, dz, dr;
20
21 if (camera->needsInit || camera->needsReinit) {
22 camera->needsInit = FALSE;
23 camera->needsReinit = FALSE;
24 camera->params.basic.skipRecalc = FALSE;
25 camera->params.basic.dist = 100;
26 camera->params.basic.pitch = 0;
27 camera->params.basic.yaw = 0;
28 camera->params.basic.offsetY = 0;
29 camera->params.basic.fovScale = 100;
30
31 camera->targetPos.x = 0.0f;
32 camera->targetPos.y = 0.0f;
33 camera->targetPos.z = 0.0f;
34
35 camera->lookAt_obj.x = camera->lookAt_obj_target.x;
36 camera->lookAt_obj.y = camera->lookAt_obj_target.y;
37 camera->lookAt_obj.z = camera->lookAt_obj_target.z;
38 }
39
40 if (!camera->params.basic.skipRecalc) {
41 camera->lookAt_obj.x = camera->lookAt_obj_target.x + camera->targetPos.x;
42 camera->lookAt_obj.y = camera->lookAt_obj_target.y + camera->targetPos.y + camera->params.basic.offsetY / 256.0;
43 camera->lookAt_obj.z = camera->lookAt_obj_target.z + camera->targetPos.z;
44
45 camera->curBoomLength = camera->params.basic.dist;
46 camera->curBoomPitch = camera->params.basic.pitch;
47 camera->curBoomYaw = camera->params.basic.yaw;
48 camera->vfov = (10000 / camera->params.basic.fovScale) / 4;
49
50 pitchAngle = DEG_TO_RAD(camera->curBoomPitch);
51 sinPitch = sin_rad(pitchAngle);
52 cosPitch = cos_rad(pitchAngle);
53
54 yawAngle = DEG_TO_RAD(camera->curBoomYaw);
55 sinYaw = sin_rad(yawAngle);
56 cosYaw = cos_rad(yawAngle);
57
58 dy = camera->curBoomLength * sinPitch;
59 dx = camera->curBoomLength * cosPitch * -sinYaw;
60 dz = camera->curBoomLength * cosPitch * cosYaw;
61
62 camera->lookAt_eye.x = camera->lookAt_obj.x + dx;
63 camera->lookAt_eye.y = camera->lookAt_obj.y + dy;
64 camera->lookAt_eye.z = camera->lookAt_obj.z + dz;
65 }
66
67 dx = camera->lookAt_obj.x - camera->lookAt_eye.x;
68 dy = camera->lookAt_obj.y - camera->lookAt_eye.y;
69 dz = camera->lookAt_obj.z - camera->lookAt_eye.z;
70 dr = sqrtf(SQ(dx) + SQ(dz));
71
72 camera->lookAt_yaw = -atan2(0.0f, 0.0f, dx, dz);
73 camera->lookAt_pitch = atan2(0.0f, 0.0f, dy, -dr);
74 camera->curYaw = atan2(camera->lookAt_eye.x, camera->lookAt_eye.z, camera->lookAt_obj.x, camera->lookAt_obj.z);
75
79}
f32 cos_rad(f32 x)
Definition 43F0.c:717
f32 sin_rad(f32 x)
Definition 43F0.c:713
#define DEG_TO_RAD(deg)
Definition macros.h:134
b16 needsReinit
Vec3f lookAt_obj_target
f32 curBoomPitch
union Camera::@17 params
Vec3f targetPos
f32 curBoomLength
BattleStatus gBattleStatus
Definition battle.c:11

Referenced by update_cameras().

◆ update_camera_interp_pos()

void update_camera_interp_pos ( Camera * camera)

Definition at line 14 of file cam_mode_interp.c.

14 {
15 f32 pitchAngle, sinPitch, cosPitch;
16 f32 yawAngle, sinYaw, cosYaw;
17 f32 x, y, z, dx, dy, dz, dr;
18
19 camera->curBoomLength = camera->params.interp.dist * CamLengthScale;
20 camera->targetOffsetY = camera->params.interp.offsetY * CamLengthScale;
21 camera->curBoomPitch = camera->params.interp.pitch;
22 camera->interpYaw = camera->params.interp.yaw;
23 camera->curBoomYaw = camera->interpYaw;
24
25 if (camera->needsInit) {
26 camera->needsInit = FALSE;
27
28 camera->lookAt_obj.x = camera->lookAt_obj_target.x;
29 camera->lookAt_obj.y = camera->lookAt_obj_target.y + camera->targetOffsetY;
30 camera->lookAt_obj.z = camera->lookAt_obj_target.z;
31
32 pitchAngle = DEG_TO_RAD(camera->curBoomPitch);
33 sinPitch = sin_rad(pitchAngle);
34 cosPitch = cos_rad(pitchAngle);
35
36 yawAngle = DEG_TO_RAD(camera->interpYaw);
37 sinYaw = sin_rad(yawAngle);
38 cosYaw = cos_rad(yawAngle);
39
40 dy = camera->curBoomLength * sinPitch;
41 dx = camera->curBoomLength * cosPitch * -sinYaw;
42 dz = camera->curBoomLength * cosPitch * cosYaw;
43
44 camera->lookAt_eye.x = camera->lookAt_obj.x + dx;
45 camera->lookAt_eye.y = camera->lookAt_obj.y + dy;
46 camera->lookAt_eye.z = camera->lookAt_obj.z + dz;
47 }
48
49 // interpolate lookAt_obj toward lookAt_obj_target by stepping half the difference each frame
50
51 dx = camera->lookAt_obj_target.x - camera->lookAt_obj.x;
52 dy = camera->lookAt_obj_target.y - camera->lookAt_obj.y + camera->targetOffsetY;
53 dz = camera->lookAt_obj_target.z - camera->lookAt_obj.z;
54
55 if (fabsf(dx) > 16.0f) {
56 if (dx < 0.0f) {
57 dx = -16.0f;
58 } else {
59 dx = 16.0f;
60 }
61 }
62 if (fabsf(dy) > 16.0f) {
63 if (dy < 0.0f) {
64 dy = -16.0f;
65 } else {
66 dy = 16.0f;
67 }
68 }
69 if (fabsf(dz) > 16.0f) {
70 if (dz < 0.0f) {
71 dz = -16.0f;
72 } else {
73 dz = 16.0f;
74 }
75 }
76
77 camera->lookAt_obj.x += dx * 0.5f;
78 camera->lookAt_obj.y += dy * 0.5f;
79 camera->lookAt_obj.z += dz * 0.5f;
80
81 // calculate new camera eye position from distance and angles
82
83 pitchAngle = DEG_TO_RAD(camera->curBoomPitch);
84 sinPitch = sin_rad(pitchAngle);
85 cosPitch = cos_rad(pitchAngle);
86
87 yawAngle = DEG_TO_RAD(camera->interpYaw);
88 sinYaw = sin_rad(yawAngle);
89 cosYaw = cos_rad(yawAngle);
90
91 dy = camera->curBoomLength * sinPitch;
92 dx = camera->curBoomLength * cosPitch * -sinYaw;
93 dz = camera->curBoomLength * cosPitch * cosYaw;
94
95 x = camera->lookAt_obj.x + dx;
96 y = camera->lookAt_obj.y + dy;
97 z = camera->lookAt_obj.z + dz;
98
99 // interpolate lookAt_eye toward new eye position by stepping half the difference each frame
100
101 dx = (x - camera->lookAt_eye.x) * 0.5f;
102 dy = (y - camera->lookAt_eye.y) * 0.5f;
103 dz = (z - camera->lookAt_eye.z) * 0.5f;
104
105 if (fabsf(dx) > 16.0f) {
106 if (dx < 0.0f) {
107 dx = -16.0f;
108 } else {
109 dx = 16.0f;
110 }
111 }
112 if (fabsf(dy) > 16.0f) {
113 if (dy < 0.0f) {
114 dy = -16.0f;
115 } else {
116 dy = 16.0f;
117 }
118 }
119 if (fabsf(dz) > 16.0f) {
120 if (dz < 0.0f) {
121 dz = -16.0f;
122 } else {
123 dz = 16.0f;
124 }
125 }
126
127 camera->lookAt_eye.x += dx;
128 camera->lookAt_eye.y += dy;
129 camera->lookAt_eye.z += dz;
130
131 // calculate final position and orientation for camera
132
133 dx = camera->lookAt_obj.x - camera->lookAt_eye.x;
134 dy = camera->lookAt_obj.y - camera->lookAt_eye.y;
135 dz = camera->lookAt_obj.z - camera->lookAt_eye.z;
136 dr = sqrtf(SQ(dx) + SQ(dz));
137
138 camera->lookAt_yaw = -atan2(0.0f, 0.0f, dx, dz);
139 camera->lookAt_pitch = atan2(0.0f, 0.0f, dy, -dr);
140 camera->curYaw = atan2(camera->lookAt_eye.x, camera->lookAt_eye.z, camera->lookAt_obj.x, camera->lookAt_obj.z);
141}
f32 fabsf(f32 f)
f32 targetOffsetY

Referenced by update_cameras().

◆ update_camera_zone_interp()

void update_camera_zone_interp ( Camera * camera)

Definition at line 688 of file cam_mode_zone_interp.c.

688 {
689 CameraControlSettings* curSettings;
690 CameraControlSettings* nextSettings;
691 f32 targetX;
692 f32 targetY;
693 f32 targetZ;
694 f32 maxDelta;
695 f32 panPhase;
696 f32 panRad;
697 f32 cosAngle;
698 f32 temp_f24;
699 f64 temp_f22_2;
700 b32 allParamsMatch;
701 s32 changingZone;
702 f32 dist;
703
704 targetX = camera->targetPos.x;
705 targetY = camera->targetPos.y;
706 targetZ = camera->targetPos.z;
707 changingZone = FALSE;
708
709 if (camera->needsReinit) {
710 camera->curSettings = NULL;
711 camera->prevSettings = NULL;
712 camera->linearInterp = 0.0f;
713 camera->yinterpAlpha = 1.0f;
714 camera->yinterpGoal = 0.0f;
715 camera->yinterpCur = targetY;
716
717 camera->interpEasingParameter = 0.0f;
718 camera->interpAlpha = 1.0f;
719 camera->linearInterpRate = 1.0f;
720
721 camera->prevTargetPos.x = 0.0f;
722 camera->prevTargetPos.y = 0.0f;
723 camera->prevTargetPos.z = 0.0f;
724 camera->prevUseOverride = FALSE;
725 camera->prevPrevUseOverride = FALSE;
726 D_800A08DC = 0.0f;
727 D_800A08E0 = 0.0f;
728 }
729
730 // determine current y-position
731 interp_camera_y_position(camera, targetY);
732
733 if (camera->panActive
734 || camera->prevTargetPos.x != targetX
735 || camera->prevTargetPos.y != targetY
736 || camera->prevTargetPos.z != targetZ
737 || camera->needsReinit
738 ) {
739 if (camera->useOverrideSettings) {
740 nextSettings = &camera->overrideSettings;
741 } else {
742 nextSettings = test_ray_zone_aabb(targetX, targetY + 10.0f, targetZ);
743 }
744
745 allParamsMatch = FALSE;
746 curSettings = camera->curSettings;
747 if (nextSettings != NULL
748 && curSettings != NULL
749 && nextSettings->type == curSettings->type
750 && nextSettings->flag == curSettings->flag
751 && nextSettings->boomLength == curSettings->boomLength
752 && nextSettings->boomPitch == curSettings->boomPitch
753 && nextSettings->viewPitch == curSettings->viewPitch
754 ) {
755 switch (nextSettings->type) {
757 if (nextSettings->points.two.Ax == curSettings->points.two.Ax
758 && nextSettings->points.two.Az == curSettings->points.two.Az
759 && nextSettings->points.two.Bx == curSettings->points.two.Bx
760 && nextSettings->points.two.Bz == curSettings->points.two.Bz
761 ) {
762 allParamsMatch = TRUE;
763 }
764 break;
766 if (nextSettings->flag) {
767 if (nextSettings->points.two.Ax == curSettings->points.two.Ax
768 && nextSettings->points.two.Az == curSettings->points.two.Az
769 && nextSettings->points.two.Bx == curSettings->points.two.Bx
770 && nextSettings->points.two.Bz == curSettings->points.two.Bz
771 ) {
772 allParamsMatch = TRUE;
773 }
774 } else {
775 if (nextSettings->points.two.Ax == curSettings->points.two.Ax
776 && nextSettings->points.two.Az == curSettings->points.two.Az
777 ) {
778 allParamsMatch = TRUE;
779 }
780 }
781 break;
782 default:
783 if (nextSettings->points.two.Ax == curSettings->points.two.Ax
784 && nextSettings->points.two.Az == curSettings->points.two.Az
785 && nextSettings->points.two.Ay == curSettings->points.two.Ay
786 && nextSettings->points.two.By == curSettings->points.two.By
787 && nextSettings->points.two.Bx == curSettings->points.two.Bx
788 && nextSettings->points.two.Bz == curSettings->points.two.Bz
789 ) {
790 allParamsMatch = TRUE;
791 }
792 break;
793 }
794 }
795
796 if (camera->panActive || (nextSettings != curSettings && !allParamsMatch)) {
797 if (camera->interpAlpha == 1.0f) {
798 camera->prevSettings = camera->curSettings;
799 } else {
801 }
802 camera->panActive = FALSE;
803 changingZone = TRUE;
804 camera->prevRig = CurrentCamRig;
805 camera->curSettings = nextSettings;
806
807 camera->interpAlpha = 0.0f;
808 camera->linearInterp = 0.0f;
809 camera->linearInterpRate = camera->moveSpeed;
810
811 camera->prevPrevUseOverride = camera->prevUseOverride;
812 camera->prevUseOverride = camera->useOverrideSettings;
813
814 camera->prevPrevMovePos.x = camera->prevMovePos.x;
815 camera->prevPrevMovePos.y = camera->prevMovePos.y;
816 camera->prevPrevMovePos.z = camera->prevMovePos.z;
817
818 camera->prevMovePos.x = camera->movePos.x;
819 camera->prevMovePos.y = camera->movePos.y;
820 camera->prevMovePos.z = camera->movePos.z;
821 }
822 }
823
824 camera->prevTargetPos.x = targetX;
825 camera->prevTargetPos.y = targetY;
826 camera->prevTargetPos.z = targetZ;
827
828 f32 posX;
829 f32 posY;
830 f32 posZ;
831 f32 tX;
832 f32 tY;
833 f32 tZ;
834
835 if (camera->prevPrevUseOverride) {
836 posX = camera->prevPrevMovePos.x;
837 posY = camera->prevPrevMovePos.y;
838 posZ = camera->prevPrevMovePos.z;
839 } else {
840 posX = targetX;
841 posY = camera->yinterpCur;
842 posZ = targetZ;
843 }
844
845 if (camera->prevUseOverride) {
846 tX = camera->prevMovePos.x;
847 tY = camera->prevMovePos.y;
848 tZ = camera->prevMovePos.z;
849 camera->yinterpCur = tY;
850 } else {
851 tX = targetX;
852 tY = camera->yinterpCur;
853 tZ = targetZ;
854 }
855
857 &camera->prevRig, &camera->prevSettings, &camera->nextRig, &camera->curSettings,
858 posX, posY, posZ, tX, tY, tZ,
859 &camera->interpAlpha, camera->needsReinit, changingZone);
860
861 if (camera->needsReinit) {
862 camera->prevRig = camera->nextRig;
863 camera->needsReinit = FALSE;
864 camera->interpAlpha = 1.0f;
865 }
866
867 if (camera->prevRig.boomYaw - camera->nextRig.boomYaw > 180.0f) {
868 camera->prevRig.boomYaw -= 360.0f;
869 }
870 if (camera->prevRig.boomYaw - camera->nextRig.boomYaw < -180.0f) {
871 camera->prevRig.boomYaw += 360.0f;
872 }
873
874 maxDelta = get_maximum_interp_delta(camera);
875
876 camera->linearInterp += (1.0f / maxDelta) * camera->linearInterpRate;
877 if (camera->linearInterp > 1.0f) {
878 camera->linearInterp = 1.0f;
879 }
880
881 if (camera->interpAlpha < 1.0f) {
882 // this phi parameter controls whether the easing will be cosine in/out or quadratic out
883 // when phi = 0, this expression reduces to cos(PI_D * alpha) and the easing is cosine in and out
884 // when phi = 1, gamma 'blows up' as the denominator goes to zero, so this value is not valid.
885 // however, as phi approaches 1, the formula for interpAlpha approaches 1 - SQ(1 - alpha)
886 // intermediate values smoothly produce intermediate easing functions
887 // in practice, only 0 and 0.5 are ever used, and 0.5 is extremely rare
888 f32 phi = camera->interpEasingParameter;
889 f32 plusCos = (1.0f + cos_rad(PI_D * phi)) * 0.5f;
890 f32 minusCos = (1.0f - cos_rad(PI_D * phi)) * 0.5f;
891 f32 alpha = camera->linearInterp;
892 f32 beta = cos_rad(PI_D * (alpha * (1.0f - phi) + phi));
893 f32 gamma = (beta + minusCos) / plusCos;
894 // the range of gamma is [1,-1] so we must remap it to [0,1] before assigning interpAlpha
895 camera->interpAlpha = (1.0f - gamma) * 0.5001;
896 }
897
898 if (camera->interpAlpha >= 1.0f) {
899 camera->interpAlpha = 1.0f;
900 camera->linearInterp = 0.0f;
901 }
902
903 // interpolate rig parameters between prevRig and nextRig, storing them in CurrentCamRig
904
905 #define CAM_INTERP(field) CurrentCamRig.field = \
906 (camera->prevRig.field * (1.0f - camera->interpAlpha)) + (camera->nextRig.field * camera->interpAlpha)
907
908 CAM_INTERP(boomYaw);
909 CAM_INTERP(boomLength);
910 CAM_INTERP(boomPitch);
911 CAM_INTERP(viewPitch);
912 CAM_INTERP(targetPos.x);
913 CAM_INTERP(targetPos.y);
914 CAM_INTERP(targetPos.z);
915
916 #undef CAM_INTERP
917
918 CurrentCamRig.boomLength *= (camera->params.world.zoomPercent / 100.0f);
919
920 // calculate camera position and orientation based on CurrentCamRig
922}
void interp_camera_y_position(Camera *camera, f32 targetY)
BSS f32 D_800A08DC
BSS CameraRig CurrentCamRig
f32 get_maximum_interp_delta(Camera *camera)
BSS f32 D_800A08E0
@ CAMERA_SETTINGS_PTR_MINUS_1
void update_camera_from_controller(Camera *camera, CameraRig *prevRig, CameraControlSettings **prevSettingsPtr, CameraRig *newRig, CameraControlSettings **curSettingsPtr, f32 x1, f32 y1, f32 z1, f32 x2, f32 y2, f32 z2, f32 *interpAlpha, b32 changingMap, b32 changingZone)
CameraControlSettings * test_ray_zone_aabb(f32 x, f32 y, f32 z)
void set_camera_from_rig(Camera *camera, CameraRig *rig)
#define CAM_INTERP(field)
s32 b32
union CameraControlSettings::@14 points
@ CAM_CONTROL_FIXED_ORIENTATION
Definition enums.h:4790
@ CAM_CONTROL_LOOK_AT_POINT
Definition enums.h:4795
#define PI_D
Definition macros.h:127
CameraRig nextRig
f32 linearInterpRate
Vec3f movePos
Vec3f prevTargetPos
b16 prevUseOverride
CameraControlSettings * curSettings
f32 yinterpGoal
f32 yinterpAlpha
Vec3f prevPrevMovePos
f32 interpEasingParameter
CameraControlSettings * prevSettings
b16 useOverrideSettings
CameraRig prevRig
CameraControlSettings overrideSettings
f32 linearInterp
b16 prevPrevUseOverride
Vec3f prevMovePos
f32 interpAlpha

Referenced by update_cameras().

◆ update_camera_unused_confined()

void update_camera_unused_confined ( Camera * camera)

Definition at line 15 of file cam_mode_unused_confined.c.

15 {
16 f32 yawAngle, sinYaw, cosYaw;
17 f32 pitchAngle, sinPitch, cosPitch;
18 f32 dx, dy, dz, dr;
19 f32 targetX;
20 f32 targetZ;
21
22 targetX = camera->targetPos.x;
23 if (targetX > camera->params.confined.xLimit) {
24 targetX = camera->params.confined.xLimit;
25 }
26 if (targetX < -camera->params.confined.xLimit) {
27 targetX = -camera->params.confined.xLimit;
28 }
29 camera->lookAt_obj_target.x = targetX;
30
31 targetZ = camera->targetPos.z;
32 if (targetZ > camera->params.confined.zLimit) {
33 targetZ = camera->params.confined.zLimit;
34 }
35 if (targetZ < -camera->params.confined.zLimit) {
36 targetZ = -camera->params.confined.zLimit;
37 }
38 camera->lookAt_obj_target.z = targetZ;
39
40 camera->interpYaw = 0.0f;
41 camera->curBoomPitch = 0.0f;
42 camera->curBoomYaw = 0.0f;
43 camera->curBoomLength = camera->params.confined.dist * CamLengthScale;
44 camera->targetOffsetY = camera->params.confined.offsetY * CamLengthScale;
45
46 if (camera->needsInit) {
47 camera->needsInit = FALSE;
48
49 camera->lookAt_obj.x = camera->lookAt_obj_target.x;
50 camera->lookAt_obj.y = camera->lookAt_obj_target.y + camera->targetOffsetY;
51 camera->lookAt_obj.z = camera->lookAt_obj_target.z;
52
53 pitchAngle = DEG_TO_RAD(camera->curBoomPitch);
54 sinPitch = sin_rad(pitchAngle);
55 cosPitch = cos_rad(pitchAngle);
56
57 yawAngle = DEG_TO_RAD(camera->interpYaw);
58 sinYaw = sin_rad(yawAngle);
59 cosYaw = cos_rad(yawAngle);
60
61 dy = camera->curBoomLength * sinPitch;
62 dx = camera->curBoomLength * cosPitch * -sinYaw;
63 dz = camera->curBoomLength * cosPitch * cosYaw;
64
65 camera->lookAt_eye.x = camera->lookAt_obj.x + dx;
66 camera->lookAt_eye.y = camera->lookAt_obj.y + dy;
67 camera->lookAt_eye.z = camera->lookAt_obj.z + dz;
68 }
69
70 camera->lookAt_obj.x = camera->lookAt_obj_target.x;
71 camera->lookAt_obj.y = camera->lookAt_obj_target.y + camera->targetOffsetY;
72 camera->lookAt_obj.z = camera->lookAt_obj_target.z;
73
74 pitchAngle = DEG_TO_RAD(camera->curBoomPitch);
75 sinPitch = sin_rad(pitchAngle);
76 cosPitch = cos_rad(pitchAngle);
77
78 yawAngle = DEG_TO_RAD(camera->interpYaw);
79 sinYaw = sin_rad(yawAngle);
80 cosYaw = cos_rad(yawAngle);
81
82 dy = camera->curBoomLength * sinPitch;
83 dx = camera->curBoomLength * cosPitch * -sinYaw;
84 dz = camera->curBoomLength * cosPitch * cosYaw;
85
86 camera->lookAt_eye.x = camera->lookAt_obj.x + dx;
87 camera->lookAt_eye.y = camera->lookAt_obj.y + dy;
88 camera->lookAt_eye.z = camera->lookAt_obj.z + dz;
89
90 dx = camera->lookAt_obj.x - camera->lookAt_eye.x;
91 dy = camera->lookAt_obj.y - camera->lookAt_eye.y;
92 dz = camera->lookAt_obj.z - camera->lookAt_eye.z;
93 dr = sqrtf(SQ(dx) + SQ(dz));
94
95 camera->lookAt_yaw = -atan2(0.0f, 0.0f, dx, dz);
96 camera->lookAt_pitch = atan2(0.0f, 0.0f, dy, -dr);
97 camera->curYaw = atan2(camera->lookAt_eye.x, camera->lookAt_eye.z, camera->lookAt_obj.x, camera->lookAt_obj.z);
98}

Referenced by update_cameras().

◆ update_camera_unused_leading()

void update_camera_unused_leading ( Camera * camera)

Definition at line 67 of file cam_mode_unused_leading.c.

67 {
68 f32 dx, dy, dz, dr;
69
70 camera->curBoomPitch = 18.0f;
71 camera->curBoomLength = 690.0f;
72 camera->targetOffsetY = 47.0f;
73
74 if (camera->needsInit) {
75 camera->needsInit = FALSE;
76 camera->unusedLeadAmt = 0.0f;
77 camera->unusedLeadCounter = 0;
78 camera->interpYaw = 0.0f;
79 camera->curBoomYaw = 0.0f;
80 camera->lookAt_obj.x = camera->targetPos.x;
81 camera->lookAt_obj.y = camera->targetPos.y + camera->targetOffsetY;
82 camera->lookAt_obj.z = camera->targetPos.z;
83 interp_lookat_pos(camera, 0.0f, 0.0f, FALSE);
84 } else {
85 f32 maxInterpSpeed = (gPlayerStatus.curSpeed * 1.5f) + 1.0f;
86 f32 interpRate = (gPlayerStatus.curSpeed * 0.05f) + 0.05f;
87
88 camera->lookAt_obj_target.x = camera->targetPos.x + camera->unusedLeadAmt;
89 camera->lookAt_obj_target.y = camera->targetPos.y + camera->targetOffsetY;
90 camera->lookAt_obj_target.z = camera->targetPos.z;
93 interp_lookat_pos(camera, interpRate, maxInterpSpeed, TRUE);
94 } else {
95 interp_lookat_pos(camera, interpRate, maxInterpSpeed, FALSE);
96 }
97 }
98
99 dx = camera->lookAt_obj.x - camera->lookAt_eye.x;
100 dy = camera->lookAt_obj.y - camera->lookAt_eye.y;
101 dz = camera->lookAt_obj.z - camera->lookAt_eye.z;
102 dr = sqrtf(SQ(dx) + SQ(dz));
103
104 camera->lookAt_yaw = -atan2(0.0f, 0.0f, dx, dz);
105 camera->lookAt_pitch = atan2(0.0f, 0.0f, dy, -dr);
106 camera->curYaw = atan2(camera->lookAt_eye.x, camera->lookAt_eye.z, camera->lookAt_obj.x, camera->lookAt_obj.z);
107}
void update_unused_lead_amt(Camera *camera)
void interp_lookat_pos(Camera *camera, f32 interpAmtXZ, f32 maxDeltaXZ, s16 lockPosY)
@ CAMERA_MOVE_IGNORE_PLAYER_Y
Definition enums.h:4732
f32 unusedLeadAmt
s16 unusedLeadCounter
PlayerStatus gPlayerStatus
Definition 77480.c:39

Referenced by update_cameras().

◆ update_camera_unused_radial()

void update_camera_unused_radial ( Camera * camera)

Definition at line 16 of file cam_mode_unused_radial.c.

16 {
17 f32 yawAngle, sinYaw, cosYaw;
18 f32 pitchAngle, sinPitch, cosPitch;
19 f32 dx, dy, dz, dr;
20 f32 x1, z1, x2, z2;
21 f32 dist, angle;
22
23 if (camera->needsInit) {
24 camera->needsInit = FALSE;
25
26 x1 = camera->lookAt_obj_target.x;
27 z1 = camera->lookAt_obj_target.z;
28 x2 = camera->targetPos.x;
29 z2 = camera->targetPos.z;
30
31 camera->curBoomPitch = camera->params.radial.pitch;
32 camera->curBoomLength = camera->params.radial.dist * LEN_SCALE;
33 camera->targetOffsetY = camera->params.radial.offsetY * YSCALE * LEN_SCALE;
34
35 angle = atan2(x1, z1, x2, z2);
36 dist = dist2D(x1, z1, x2, z2);
37 if (dist >= camera->params.radial.minRadius * LEN_SCALE) {
38 camera->curBoomYaw = angle;
39 }
40 camera->targetBoomYaw = camera->curBoomYaw;
41
42 camera->lookAt_obj.x = camera->lookAt_obj_target.x;
43 camera->lookAt_obj.y = camera->lookAt_obj_target.y + camera->targetOffsetY;
44 camera->lookAt_obj.z = camera->lookAt_obj_target.z;
45
46 pitchAngle = DEG_TO_RAD(camera->curBoomPitch);
47 sinPitch = sin_rad(pitchAngle);
48 cosPitch = cos_rad(pitchAngle);
49
50 yawAngle = DEG_TO_RAD(angle);
51 sinYaw = sin_rad(yawAngle);
52 cosYaw = cos_rad(yawAngle);
53
54 dy = camera->curBoomLength * sinPitch;
55 dx = camera->curBoomLength * cosPitch * -sinYaw;
56 dz = camera->curBoomLength * cosPitch * cosYaw;
57
58 camera->lookAt_eye.x = camera->lookAt_obj.x + dx;
59 camera->lookAt_eye.y = camera->lookAt_obj.y + dy;
60 camera->lookAt_eye.z = camera->lookAt_obj.z + dz;
61 }
62
63 camera->curBoomPitch = camera->params.radial.pitch;
64 camera->curBoomLength = camera->params.radial.dist * LEN_SCALE;
65 camera->targetOffsetY = camera->params.radial.offsetY * YSCALE * LEN_SCALE;
66
67 dx = camera->lookAt_obj_target.x - camera->lookAt_obj.x;
68 dy = camera->lookAt_obj_target.y - camera->lookAt_obj.y + camera->targetOffsetY;
69 dz = camera->lookAt_obj_target.z - camera->lookAt_obj.z;
70
71 camera->lookAt_obj.x += dx * 0.5f;
72 camera->lookAt_obj.y += dy * YSCALE * 0.5f;
73 camera->lookAt_obj.z += dz * 0.5f;
74
75 x1 = camera->lookAt_obj_target.x;
76 z1 = camera->lookAt_obj_target.z;
77 x2 = camera->targetPos.x;
78 z2 = camera->targetPos.z;
79
80 angle = atan2(x1, z1, x2, z2);
81 dist = dist2D(x1, z1, x2, z2);
82 if (dist >= camera->params.radial.minRadius * LEN_SCALE) {
83 camera->curBoomYaw = angle;
84 }
85 camera->targetBoomYaw -= get_clamped_angle_diff(camera->curBoomYaw, camera->targetBoomYaw) / 10.0f;
86
87 pitchAngle = DEG_TO_RAD(camera->curBoomPitch);
88 sinPitch = sin_rad(pitchAngle);
89 cosPitch = cos_rad(pitchAngle);
90
91 yawAngle = DEG_TO_RAD((camera->targetBoomYaw));
92 sinYaw = sin_rad(yawAngle);
93 cosYaw = cos_rad(yawAngle);
94
95 dy = camera->curBoomLength * sinPitch;
96 dx = camera->curBoomLength * cosPitch * -sinYaw;
97 dz = camera->curBoomLength * cosPitch * cosYaw;
98
99 camera->lookAt_eye.x = camera->lookAt_obj.x + dx;
100 camera->lookAt_eye.y = camera->lookAt_obj.y + dy;
101 camera->lookAt_eye.z = camera->lookAt_obj.z + dz;
102
103 dx = camera->lookAt_obj.x - camera->lookAt_eye.x;
104 dy = camera->lookAt_obj.y - camera->lookAt_eye.y;
105 dz = camera->lookAt_obj.z - camera->lookAt_eye.z;
106 dr = sqrtf(SQ(dx) + SQ(dz));
107
108 camera->lookAt_yaw = -atan2(0.0f, 0.0f, dx, dz);
109 camera->lookAt_pitch = atan2(0.0f, 0.0f, dy, -dr);
110 camera->curYaw = atan2(camera->lookAt_eye.x, camera->lookAt_eye.z, camera->lookAt_obj.x, camera->lookAt_obj.z);
111}
#define LEN_SCALE
#define YSCALE
f32 dist2D(f32 ax, f32 ay, f32 bx, f32 by)
Definition 43F0.c:670
f32 get_clamped_angle_diff(f32, f32)
Definition 43F0.c:606
f32 targetBoomYaw

Referenced by update_cameras().

◆ update_camera_unused_ahead()

void update_camera_unused_ahead ( Camera * camera)

Definition at line 14 of file cam_mode_unused_ahead.c.

14 {
15 f32 yawAngle, sinYaw, cosYaw;
16 f32 pitchAngle, sinPitch, cosPitch;
17 f32 dx, dy, dz, dr;
18
19 if (camera->needsInit || camera->needsReinit) {
20 camera->needsInit = FALSE;
21 camera->needsReinit = FALSE;
22 camera->params.basic.skipRecalc = FALSE;
23 camera->params.basic.dist = 100;
24 camera->params.basic.pitch = 0;
25 camera->params.basic.yaw = 0;
26 camera->params.basic.fovScale = 100;
27
28 camera->lookAt_obj.x = camera->lookAt_obj_target.x;
29 camera->lookAt_obj.y = camera->lookAt_obj_target.y;
30 camera->lookAt_obj.z = camera->lookAt_obj_target.z;
31 }
32
34 camera->lookAt_obj_target.y = gPlayerStatus.pos.y + 60.0f;
35 }
37 camera->lookAt_obj_target.z = gPlayerStatus.pos.z + 400.0f;
38
39 if (!camera->params.basic.skipRecalc) {
40 camera->lookAt_obj.x = camera->lookAt_obj_target.x;
41 camera->lookAt_obj.y = camera->lookAt_obj_target.y;
42 camera->lookAt_obj.z = camera->lookAt_obj_target.z;
43
44 camera->curBoomYaw = camera->params.basic.yaw;
45 camera->curBoomPitch = camera->params.basic.pitch;
46 camera->curBoomLength = camera->params.basic.dist;
47 camera->vfov = (10000 / camera->params.basic.fovScale) / 4;
48
49 pitchAngle = DEG_TO_RAD(camera->curBoomPitch);
50 sinPitch = sin_rad(pitchAngle);
51 cosPitch = cos_rad(pitchAngle);
52
53 yawAngle = DEG_TO_RAD(camera->curBoomYaw);
54 sinYaw = sin_rad(yawAngle);
55 cosYaw = cos_rad(yawAngle);
56
57 dy = camera->curBoomLength * sinPitch;
58 dx = camera->curBoomLength * cosPitch * -sinYaw;
59 dz = camera->curBoomLength * cosPitch * cosYaw;
60
61 camera->lookAt_eye.x = camera->lookAt_obj.x + dx;
62 camera->lookAt_eye.y = camera->lookAt_obj.y + dy;
63 camera->lookAt_eye.z = camera->lookAt_obj.z + dz;
64 }
65
66 dx = camera->lookAt_obj.x - camera->lookAt_eye.x;
67 dy = camera->lookAt_obj.y - camera->lookAt_eye.y;
68 dz = camera->lookAt_obj.z - camera->lookAt_eye.z;
69 dr = sqrtf(SQ(dx) + SQ(dz));
70
71 camera->lookAt_yaw = -atan2(0.0f, 0.0f, dx, dz);
72 camera->lookAt_pitch = atan2(0.0f, 0.0f, dy, -dr);
73 camera->curYaw = atan2(camera->lookAt_eye.x, camera->lookAt_eye.z, camera->lookAt_obj.x, camera->lookAt_obj.z);
74}
@ PS_FLAG_FALLING
Definition enums.h:3036
@ PS_FLAG_JUMPING
Definition enums.h:3035

◆ create_camera_leadplayer_matrix()

void create_camera_leadplayer_matrix ( Camera * camera)

Definition at line 476 of file cam_math.c.

476 {
477 f32 dx = camera->lookAt_eye.x - camera->lookAt_obj.x;
478 f32 dy = camera->lookAt_eye.y - camera->lookAt_obj.y;
479 f32 dz = camera->lookAt_eye.z - camera->lookAt_obj.z;
480 f32 dist = sqrtf(SQ(dx) + SQ(dy) + SQ(dz));
481 f32 theta = ((camera->vfov * 0.5f) / 180.0f) * PI;
482 f32 distTanTheta = dist * (sin_rad(theta) / cos_rad(theta));
483 f32 hfov = distTanTheta * camera->viewportW / camera->viewportH;
484
485 update_camera_lead_amount(camera, hfov * camera->leadAmtScale);
487 guTranslateF(camera->mtxViewLeading, -camera->leadAmount, 0.0f, 0.0f);
488}
void apply_constraints_to_lead_amount(Camera *camera)
Definition cam_math.c:329
void update_camera_lead_amount(Camera *camera, f32 candidateLeadAmount)
Definition cam_math.c:224
#define guTranslateF
#define PI
Definition macros.h:126
Matrix4f mtxViewLeading
f32 leadAmtScale

Referenced by update_cameras().

◆ initialize_next_camera()

Camera * initialize_next_camera ( CameraInitData * data)

Definition at line 311 of file cam_main.c.

311 {
312 Camera* camera;
313 s32 camID;
314
315 for (camID = 0; camID < ARRAY_COUNT(gCameras); camID++) {
316 camera = &gCameras[camID];
317
318 if (camera->flags == 0) {
319 break;
320 }
321 }
322
323 ASSERT(camID < ARRAY_COUNT(gCameras));
324
325 camera->flags = initData->flags | CAMERA_FLAG_INITIALIZED | CAMERA_FLAG_LEAD_PLAYER;
326 camera->moveFlags = 0;
327 camera->lookAt_eye.x = 0;
328 camera->lookAt_eye.y = 0;
329 camera->lookAt_eye.z = 0;
330 camera->lookAt_obj.x = 0;
331 camera->lookAt_obj.y = 0;
332 camera->lookAt_obj.z = -100.0f;
333 camera->curYaw = 0.0f;
334 camera->curBoomLength = 0;
335 camera->targetOffsetY = 0;
336 camera->curBoomYaw = 0.0f;
337 camera->targetBoomYaw = 0.0f;
338 camera->needsInit = TRUE;
339 camera->updateMode = initData->updateMode;
340 camera->nearClip = initData->nearClip;
341 camera->farClip = initData->farClip;
342 camera->vfov = initData->vfov;
343 camera->params.world.zoomPercent = 100;
344 set_cam_viewport(camID, initData->viewStartX, initData->viewStartY, initData->viewWidth, initData->viewHeight);
345 camera->bgColor[0] = 0;
346 camera->bgColor[1] = 0;
347 camera->bgColor[2] = 0;
348 camera->lookAt_obj_target.x = 0;
349 camera->lookAt_obj_target.y = 0;
350 camera->lookAt_obj_target.z = 0;
351 camera->targetPos.x = 0;
352 camera->targetPos.y = 0;
353 camera->targetPos.z = 0;
354 camera->fpDoPreRender = NULL;
355 camera->fpDoPostRender = NULL;
356 camera->leadAmount = 0.0f;
357 camera->targetLeadAmount = 0.0f;
358 camera->leadInterpAlpha = 0.0f;
359 camera->accumulatedStickLead = 0.0f;
360 camera->increasingLeadInterp = FALSE;
361 camera->prevLeadPosX = 0.0f;
362 camera->prevLeadPosZ = 0.0f;
363 camera->leadConstrainDir = 0;
364 camera->needsInitialConstrainDir = TRUE;
365 camera->prevLeadSettings = NULL;
366 camera->panActive = FALSE;
367 camera->useOverrideSettings = FALSE;
368 camera->leadAmtScale = 0.2f;
369 camera->moveSpeed = 1.0f;
370 return camera;
371}
Camera gCameras[4]
Definition cam_main.c:17
void set_cam_viewport(s16 id, s16 x, s16 y, s16 width, s16 height)
Definition cam_main.c:373
#define ASSERT(condition)
@ CAMERA_FLAG_LEAD_PLAYER
Definition enums.h:4722
@ CAMERA_FLAG_INITIALIZED
Definition enums.h:4720
#define ARRAY_COUNT(arr)
Definition macros.h:40
s16 bgColor[3]
s32 increasingLeadInterp
f32 leadInterpAlpha
f32 prevLeadPosX
b32 needsInitialConstrainDir
CameraControlSettings * prevLeadSettings
s32 leadConstrainDir
void(* fpDoPreRender)(struct Camera *)
f32 targetLeadAmount
void(* fpDoPostRender)(struct Camera *)
f32 accumulatedStickLead
f32 prevLeadPosZ

Referenced by create_cameras().

Variable Documentation

◆ CamLengthScale

f32 CamLengthScale
extern