Paper Mario DX
Paper Mario (N64) modding
Loading...
Searching...
No Matches
cam_mode_unused_radial.c
Go to the documentation of this file.
1
#include "common.h"
2
#include "
camera.h
"
3
4
#define YSCALE (1.0f / 5.0f)
5
#define LEN_SCALE (100 / CamLengthScale)
6
7
// implements CAM_UPDATE_UNUSED_RADIAL
8
// this camera tracks lookAt_obj_target in a circular region centered on targetPos. the camera does not update
9
// unless lookAt_obj_target is greater than a minimum distance from targetPos to prevent wild movements.
10
//
11
// control parameters:
12
// dist -- length of the camera boom arm
13
// pitch -- rising angle of the boom arm, up toward the y-axis
14
// offsetY -- offset of the base of the boom arm above the target point
15
// minRadius -- do not update camera if lookAt_obj_target is closer than this distance from targetPos
16
void
update_camera_unused_radial
(
Camera
* camera) {
17
f32 yawAngle, sinYaw, cosYaw;
18
f32 pitchAngle, sinPitch, cosPitch;
19
f32 dx, dy, dz, dr;
20
f32 x1, z1, x2, z2;
21
f32 dist, angle;
22
23
if
(camera->
needsInit
) {
24
camera->
needsInit
= FALSE;
25
26
x1 = camera->
lookAt_obj_target
.
x
;
27
z1 = camera->
lookAt_obj_target
.
z
;
28
x2 = camera->
targetPos
.
x
;
29
z2 = camera->
targetPos
.
z
;
30
31
camera->
curBoomPitch
= camera->
params
.radial.pitch;
32
camera->
curBoomLength
= camera->
params
.radial.dist *
LEN_SCALE
;
33
camera->
targetOffsetY
= camera->
params
.radial.offsetY *
YSCALE
*
LEN_SCALE
;
34
35
angle =
atan2
(x1, z1, x2, z2);
36
dist =
dist2D
(x1, z1, x2, z2);
37
if
(dist >= camera->
params
.radial.minRadius *
LEN_SCALE
) {
38
camera->
curBoomYaw
= angle;
39
}
40
camera->
targetBoomYaw
= camera->
curBoomYaw
;
41
42
camera->
lookAt_obj
.
x
= camera->
lookAt_obj_target
.
x
;
43
camera->
lookAt_obj
.
y
= camera->
lookAt_obj_target
.
y
+ camera->
targetOffsetY
;
44
camera->
lookAt_obj
.
z
= camera->
lookAt_obj_target
.
z
;
45
46
pitchAngle =
DEG_TO_RAD
(camera->
curBoomPitch
);
47
sinPitch =
sin_rad
(pitchAngle);
48
cosPitch =
cos_rad
(pitchAngle);
49
50
yawAngle =
DEG_TO_RAD
(angle);
51
sinYaw =
sin_rad
(yawAngle);
52
cosYaw =
cos_rad
(yawAngle);
53
54
dy = camera->
curBoomLength
* sinPitch;
55
dx = camera->
curBoomLength
* cosPitch * -sinYaw;
56
dz = camera->
curBoomLength
* cosPitch * cosYaw;
57
58
camera->
lookAt_eye
.
x
= camera->
lookAt_obj
.
x
+ dx;
59
camera->
lookAt_eye
.
y
= camera->
lookAt_obj
.
y
+ dy;
60
camera->
lookAt_eye
.
z
= camera->
lookAt_obj
.
z
+ dz;
61
}
62
63
camera->
curBoomPitch
= camera->
params
.radial.pitch;
64
camera->
curBoomLength
= camera->
params
.radial.dist *
LEN_SCALE
;
65
camera->
targetOffsetY
= camera->
params
.radial.offsetY *
YSCALE
*
LEN_SCALE
;
66
67
dx = camera->
lookAt_obj_target
.
x
- camera->
lookAt_obj
.
x
;
68
dy = camera->
lookAt_obj_target
.
y
- camera->
lookAt_obj
.
y
+ camera->
targetOffsetY
;
69
dz = camera->
lookAt_obj_target
.
z
- camera->
lookAt_obj
.
z
;
70
71
camera->
lookAt_obj
.
x
+= dx * 0.5f;
72
camera->
lookAt_obj
.
y
+= dy *
YSCALE
* 0.5f;
73
camera->
lookAt_obj
.
z
+= dz * 0.5f;
74
75
x1 = camera->
lookAt_obj_target
.
x
;
76
z1 = camera->
lookAt_obj_target
.
z
;
77
x2 = camera->
targetPos
.
x
;
78
z2 = camera->
targetPos
.
z
;
79
80
angle =
atan2
(x1, z1, x2, z2);
81
dist =
dist2D
(x1, z1, x2, z2);
82
if
(dist >= camera->
params
.radial.minRadius *
LEN_SCALE
) {
83
camera->
curBoomYaw
= angle;
84
}
85
camera->
targetBoomYaw
-=
get_clamped_angle_diff
(camera->
curBoomYaw
, camera->
targetBoomYaw
) / 10.0f;
86
87
pitchAngle =
DEG_TO_RAD
(camera->
curBoomPitch
);
88
sinPitch =
sin_rad
(pitchAngle);
89
cosPitch =
cos_rad
(pitchAngle);
90
91
yawAngle =
DEG_TO_RAD
((camera->
targetBoomYaw
));
92
sinYaw =
sin_rad
(yawAngle);
93
cosYaw =
cos_rad
(yawAngle);
94
95
dy = camera->
curBoomLength
* sinPitch;
96
dx = camera->
curBoomLength
* cosPitch * -sinYaw;
97
dz = camera->
curBoomLength
* cosPitch * cosYaw;
98
99
camera->
lookAt_eye
.
x
= camera->
lookAt_obj
.
x
+ dx;
100
camera->
lookAt_eye
.
y
= camera->
lookAt_obj
.
y
+ dy;
101
camera->
lookAt_eye
.
z
= camera->
lookAt_obj
.
z
+ dz;
102
103
dx = camera->
lookAt_obj
.
x
- camera->
lookAt_eye
.
x
;
104
dy = camera->
lookAt_obj
.
y
- camera->
lookAt_eye
.
y
;
105
dz = camera->
lookAt_obj
.
z
- camera->
lookAt_eye
.
z
;
106
dr =
sqrtf
(
SQ
(dx) +
SQ
(dz));
107
108
camera->
lookAt_yaw
= -
atan2
(0.0f, 0.0f, dx, dz);
109
camera->
lookAt_pitch
=
atan2
(0.0f, 0.0f, dy, -dr);
110
camera->
curYaw
=
atan2
(camera->
lookAt_eye
.
x
, camera->
lookAt_eye
.
z
, camera->
lookAt_obj
.
x
, camera->
lookAt_obj
.
z
);
111
}
update_camera_unused_radial
void update_camera_unused_radial(Camera *camera)
Definition
cam_mode_unused_radial.c:16
LEN_SCALE
#define LEN_SCALE
Definition
cam_mode_unused_radial.c:5
YSCALE
#define YSCALE
Definition
cam_mode_unused_radial.c:4
camera.h
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
dist2D
f32 dist2D(f32 ax, f32 ay, f32 bx, f32 by)
Definition
43F0.c:670
sin_rad
f32 sin_rad(f32 x)
Definition
43F0.c:713
get_clamped_angle_diff
f32 get_clamped_angle_diff(f32, f32)
Definition
43F0.c:606
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::targetBoomYaw
f32 targetBoomYaw
Definition
common_structs.h:806
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::lookAt_eye
Vec3f lookAt_eye
Definition
common_structs.h:796
src
cam_mode_unused_radial.c
Generated by
1.10.0