Paper Mario DX
Paper Mario (N64) modding
Loading...
Searching...
No Matches
cam_mode_interp.c
Go to the documentation of this file.
1
#include "common.h"
2
#include "
camera.h
"
3
4
// implements CAM_UPDATE_INTERP_POS
5
// this camera uses a set of control parameters to calculate its target lookAt_obj and lookAt_eye positions,
6
// then interpolates current positions toward those targets, moving up to half the remaining distance each frame
7
// position of the camera is determined with a boom and the ultimate target is given by lookAt_obj_target
8
//
9
// control parameters:
10
// dist -- length of the camera boom arm
11
// pitch -- rising angle of the boom arm, up toward the y-axis
12
// yaw -- yaw angle for the boom arm in the xz-plane
13
// offsetY -- offset of the base of the boom arm above the target point
14
void
update_camera_interp_pos
(
Camera
*camera) {
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
}
update_camera_interp_pos
void update_camera_interp_pos(Camera *camera)
Definition
cam_mode_interp.c:14
camera.h
CamLengthScale
f32 CamLengthScale
Definition
cam_main.c:12
Vec3f::z
f32 z
Definition
common_structs.h:102
Vec3f::x
f32 x
Definition
common_structs.h:100
Vec3f::y
f32 y
Definition
common_structs.h:101
sqrtf
#define sqrtf
Definition
effect_shims.h:60
atan2
#define atan2
Definition
effect_shims.h:57
fabsf
f32 fabsf(f32 f)
cos_rad
f32 cos_rad(f32 x)
Definition
43F0.c:717
sin_rad
f32 sin_rad(f32 x)
Definition
43F0.c:713
DEG_TO_RAD
#define DEG_TO_RAD(deg)
Definition
macros.h:134
SQ
#define SQ(x)
Definition
macros.h:166
Camera
Definition
common_structs.h:748
Camera::lookAt_obj
Vec3f lookAt_obj
Definition
common_structs.h:797
Camera::targetOffsetY
f32 targetOffsetY
Definition
common_structs.h:805
Camera::lookAt_obj_target
Vec3f lookAt_obj_target
Definition
common_structs.h:798
Camera::lookAt_yaw
f32 lookAt_yaw
Definition
common_structs.h:807
Camera::curBoomPitch
f32 curBoomPitch
Definition
common_structs.h:803
Camera::curBoomYaw
f32 curBoomYaw
Definition
common_structs.h:804
Camera::curYaw
f32 curYaw
Definition
common_structs.h:800
Camera::needsInit
b16 needsInit
Definition
common_structs.h:752
Camera::lookAt_pitch
f32 lookAt_pitch
Definition
common_structs.h:808
Camera::params
union Camera::@17 params
Camera::curBoomLength
f32 curBoomLength
Definition
common_structs.h:802
Camera::interpYaw
f32 interpYaw
Definition
common_structs.h:801
Camera::lookAt_eye
Vec3f lookAt_eye
Definition
common_structs.h:796
src
cam_mode_interp.c
Generated by
1.10.0