Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
cam_mode_unused_leading.c
Go to the documentation of this file.
1#include "common.h"
2
4 // moving left? (along +x axis)
6 if (camera->unusedLeadDir == 0) {
7 if (camera->unusedLeadCounter <= 0) {
8 camera->unusedLeadAmt = 35.0f;
9 } else {
10 camera->unusedLeadCounter--;
11 }
12 } else {
13 camera->unusedLeadCounter = 15;
14 camera->unusedLeadDir = 0;
15 }
16 // moving right? (along -x axis)
17 } else if (fabsf(get_clamped_angle_diff(gPlayerStatus.curYaw, 270.0f)) < 45.0f) {
18 if (camera->unusedLeadDir == 1) {
19 if (camera->unusedLeadCounter <= 0) {
20 camera->unusedLeadAmt = -35.0f;
21 } else {
22 camera->unusedLeadCounter--;
23 }
24 } else {
25 camera->unusedLeadCounter = 15;
26 camera->unusedLeadDir = 1;
27 }
28 }
29}
30
31void interp_lookat_pos(Camera* camera, f32 interpAmtXZ, f32 maxDeltaXZ, s16 lockPosY) {
32 f32 pitchAngle, sinPitch, cosPitch;
33 f32 deltaX, deltaZ;
34
35 deltaX = (camera->lookAt_obj_target.x - camera->lookAt_obj.x) * interpAmtXZ;
36 deltaZ = (camera->lookAt_obj_target.z - camera->lookAt_obj.z) * interpAmtXZ;
37
38 if (deltaX < -maxDeltaXZ) {
39 deltaX = -maxDeltaXZ;
40 }
41 if (deltaX > maxDeltaXZ) {
42 deltaX = maxDeltaXZ;
43 }
44
45 camera->lookAt_obj.x += deltaX;
46 camera->lookAt_obj.z += deltaZ;
47
48 pitchAngle = DEG_TO_RAD(camera->curBoomPitch);
49 sinPitch = sin_rad(pitchAngle);
50 cosPitch = cos_rad(pitchAngle);
51
52 camera->lookAt_eye.x = camera->lookAt_obj.x;
53 camera->lookAt_eye.z = camera->lookAt_obj.z + (camera->curBoomLength * cosPitch);
54
55 if (!lockPosY) {
56 camera->lookAt_obj.y += (camera->lookAt_obj_target.y - camera->lookAt_obj.y) * 0.125f;
57 camera->lookAt_eye.y = camera->lookAt_obj.y + (camera->curBoomLength * sinPitch);
58 }
59}
60
61// implements CAM_UPDATE_UNUSED_LEADING
62// this camera tracks player position and adds basic 'leading' in the x-direction only
63// camera yaw is fixed at zero and the lead direction is determined by player world yaw
64// thus, this only works for '2D' style maps where left is -x and right is +x
65//
66// no control parameters
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}
108
void update_camera_unused_leading(Camera *camera)
void update_unused_lead_amt(Camera *camera)
void interp_lookat_pos(Camera *camera, f32 interpAmtXZ, f32 maxDeltaXZ, s16 lockPosY)
#define sqrtf
#define atan2
@ CAMERA_MOVE_IGNORE_PLAYER_Y
Definition enums.h:4732
f32 fabsf(f32 f)
f32 cos_rad(f32 x)
Definition 43F0.c:717
f32 sin_rad(f32 x)
Definition 43F0.c:713
f32 get_clamped_angle_diff(f32, f32)
Definition 43F0.c:606
#define DEG_TO_RAD(deg)
Definition macros.h:134
#define SQ(x)
Definition macros.h:166
Vec3f lookAt_obj
f32 targetOffsetY
Vec3f lookAt_obj_target
f32 curBoomPitch
f32 unusedLeadAmt
f32 lookAt_pitch
s16 unusedLeadCounter
s16 unusedLeadDir
Vec3f targetPos
f32 curBoomLength
Vec3f lookAt_eye
PlayerStatus gPlayerStatus
Definition 77480.c:39