Paper Mario DX
Paper Mario (N64) modding
Loading...
Searching...
No Matches
cam_mode_unused_leading.c
Go to the documentation of this file.
1
#include "common.h"
2
3
void
update_unused_lead_amt
(
Camera
* camera) {
4
// moving left? (along +x axis)
5
if
(
fabsf
(
get_clamped_angle_diff
(
gPlayerStatus
.
curYaw
, 90.0f)) < 45.0f) {
6
if
(camera->
unusedLeadDir
== 0) {
7
if
(camera->
unusedLeadCounter
<= 0) {
8
camera->
unusedLeadAmt
= 35.0f;
9
}
else
{
10
camera->
unusedLeadCounter
--;
11
}
12
}
else
{
13
camera->
unusedLeadCounter
= 15;
14
camera->
unusedLeadDir
= 0;
15
}
16
// moving right? (along -x axis)
17
}
else
if
(
fabsf
(
get_clamped_angle_diff
(
gPlayerStatus
.
curYaw
, 270.0f)) < 45.0f) {
18
if
(camera->
unusedLeadDir
== 1) {
19
if
(camera->
unusedLeadCounter
<= 0) {
20
camera->
unusedLeadAmt
= -35.0f;
21
}
else
{
22
camera->
unusedLeadCounter
--;
23
}
24
}
else
{
25
camera->
unusedLeadCounter
= 15;
26
camera->
unusedLeadDir
= 1;
27
}
28
}
29
}
30
31
void
interp_lookat_pos
(
Camera
* camera, f32 interpAmtXZ, f32 maxDeltaXZ, s16 lockPosY) {
32
f32 pitchAngle, sinPitch, cosPitch;
33
f32 deltaX, deltaZ;
34
35
deltaX = (camera->
lookAt_obj_target
.
x
- camera->
lookAt_obj
.
x
) * interpAmtXZ;
36
deltaZ = (camera->
lookAt_obj_target
.
z
- camera->
lookAt_obj
.
z
) * interpAmtXZ;
37
38
if
(deltaX < -maxDeltaXZ) {
39
deltaX = -maxDeltaXZ;
40
}
41
if
(deltaX > maxDeltaXZ) {
42
deltaX = maxDeltaXZ;
43
}
44
45
camera->
lookAt_obj
.
x
+= deltaX;
46
camera->
lookAt_obj
.
z
+= deltaZ;
47
48
pitchAngle =
DEG_TO_RAD
(camera->
curBoomPitch
);
49
sinPitch =
sin_rad
(pitchAngle);
50
cosPitch =
cos_rad
(pitchAngle);
51
52
camera->
lookAt_eye
.
x
= camera->
lookAt_obj
.
x
;
53
camera->
lookAt_eye
.
z
= camera->
lookAt_obj
.
z
+ (camera->
curBoomLength
* cosPitch);
54
55
if
(!lockPosY) {
56
camera->
lookAt_obj
.
y
+= (camera->
lookAt_obj_target
.
y
- camera->
lookAt_obj
.
y
) * 0.125f;
57
camera->
lookAt_eye
.
y
= camera->
lookAt_obj
.
y
+ (camera->
curBoomLength
* sinPitch);
58
}
59
}
60
61
// implements CAM_UPDATE_UNUSED_LEADING
62
// this camera tracks player position and adds basic 'leading' in the x-direction only
63
// camera yaw is fixed at zero and the lead direction is determined by player world yaw
64
// thus, this only works for '2D' style maps where left is -x and right is +x
65
//
66
// no control parameters
67
void
update_camera_unused_leading
(
Camera
* camera) {
68
f32 dx, dy, dz, dr;
69
70
camera->
curBoomPitch
= 18.0f;
71
camera->
curBoomLength
= 690.0f;
72
camera->
targetOffsetY
= 47.0f;
73
74
if
(camera->
needsInit
) {
75
camera->
needsInit
= FALSE;
76
camera->
unusedLeadAmt
= 0.0f;
77
camera->
unusedLeadCounter
= 0;
78
camera->
interpYaw
= 0.0f;
79
camera->
curBoomYaw
= 0.0f;
80
camera->
lookAt_obj
.
x
= camera->
targetPos
.
x
;
81
camera->
lookAt_obj
.
y
= camera->
targetPos
.
y
+ camera->
targetOffsetY
;
82
camera->
lookAt_obj
.
z
= camera->
targetPos
.
z
;
83
interp_lookat_pos
(camera, 0.0f, 0.0f, FALSE);
84
}
else
{
85
f32 maxInterpSpeed = (
gPlayerStatus
.
curSpeed
* 1.5f) + 1.0f;
86
f32 interpRate = (
gPlayerStatus
.
curSpeed
* 0.05f) + 0.05f;
87
88
camera->
lookAt_obj_target
.
x
= camera->
targetPos
.
x
+ camera->
unusedLeadAmt
;
89
camera->
lookAt_obj_target
.
y
= camera->
targetPos
.
y
+ camera->
targetOffsetY
;
90
camera->
lookAt_obj_target
.
z
= camera->
targetPos
.
z
;
91
update_unused_lead_amt
(camera);
92
if
(camera->
moveFlags
&
CAMERA_MOVE_IGNORE_PLAYER_Y
) {
93
interp_lookat_pos
(camera, interpRate, maxInterpSpeed, TRUE);
94
}
else
{
95
interp_lookat_pos
(camera, interpRate, maxInterpSpeed, FALSE);
96
}
97
}
98
99
dx = camera->
lookAt_obj
.
x
- camera->
lookAt_eye
.
x
;
100
dy = camera->
lookAt_obj
.
y
- camera->
lookAt_eye
.
y
;
101
dz = camera->
lookAt_obj
.
z
- camera->
lookAt_eye
.
z
;
102
dr =
sqrtf
(
SQ
(dx) +
SQ
(dz));
103
104
camera->
lookAt_yaw
= -
atan2
(0.0f, 0.0f, dx, dz);
105
camera->
lookAt_pitch
=
atan2
(0.0f, 0.0f, dy, -dr);
106
camera->
curYaw
=
atan2
(camera->
lookAt_eye
.
x
, camera->
lookAt_eye
.
z
, camera->
lookAt_obj
.
x
, camera->
lookAt_obj
.
z
);
107
}
108
update_camera_unused_leading
void update_camera_unused_leading(Camera *camera)
Definition
cam_mode_unused_leading.c:67
update_unused_lead_amt
void update_unused_lead_amt(Camera *camera)
Definition
cam_mode_unused_leading.c:3
interp_lookat_pos
void interp_lookat_pos(Camera *camera, f32 interpAmtXZ, f32 maxDeltaXZ, s16 lockPosY)
Definition
cam_mode_unused_leading.c:31
PlayerStatus::curSpeed
f32 curSpeed
Definition
common_structs.h:2001
PlayerStatus::curYaw
f32 curYaw
Definition
common_structs.h:2010
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
CAMERA_MOVE_IGNORE_PLAYER_Y
@ CAMERA_MOVE_IGNORE_PLAYER_Y
Definition
enums.h:4732
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
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::moveFlags
s16 moveFlags
Definition
common_structs.h:750
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::unusedLeadAmt
f32 unusedLeadAmt
Definition
common_structs.h:851
Camera::lookAt_pitch
f32 lookAt_pitch
Definition
common_structs.h:808
Camera::unusedLeadCounter
s16 unusedLeadCounter
Definition
common_structs.h:852
Camera::unusedLeadDir
s16 unusedLeadDir
Definition
common_structs.h:853
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
gPlayerStatus
PlayerStatus gPlayerStatus
Definition
77480.c:39
src
cam_mode_unused_leading.c
Generated by
1.10.0