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
15
void
update_camera_unused_confined
(
Camera
* camera) {
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
}
update_camera_unused_confined
void update_camera_unused_confined(Camera *camera)
Definition
cam_mode_unused_confined.c:15
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
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::targetPos
Vec3f targetPos
Definition
common_structs.h:799
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_unused_confined.c
Generated by
1.10.0