Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
cam_mode_unused_confined.c
Go to the documentation of this file.
1#include "common.h"
2#include "camera.h"
3
4// implements CAM_UPDATE_UNUSED_CONFINED
5// this camera tracks targetPos, clamped within the rectangular region given by +/- xLimit and +/- zLimit
6// y-position is drawn from lookAt_obj_target
7// does not use easing or interpolation
8// uses a boom arm, but pitch and yaw are always zero
9//
10// control parameters:
11// dist -- length of the camera boom arm
12// offsetY -- offset of the base of the boom arm above the target point
13// xLimit -- confine x position of target from -xLimit to +xLimit
14// zLimit -- confine z position of target from -zLimit to +zLimit
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}
void update_camera_unused_confined(Camera *camera)
f32 CamLengthScale
Definition cam_main.c:12
#define sqrtf
#define atan2
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
#define SQ(x)
Definition macros.h:166
Vec3f lookAt_obj
f32 targetOffsetY
Vec3f lookAt_obj_target
f32 curBoomPitch
f32 lookAt_pitch
union Camera::@17 params
Vec3f targetPos
f32 curBoomLength
Vec3f lookAt_eye