Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
cam_mode_interp.c File Reference

Go to the source code of this file.

Functions

void update_camera_interp_pos (Camera *camera)
 

Function Documentation

◆ 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 CamLengthScale
Definition cam_main.c:12
#define sqrtf
#define atan2
f32 fabsf(f32 f)
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
f32 curBoomLength
Vec3f lookAt_eye

Referenced by update_cameras().