Skip to content

Commit

Permalink
camera: improve photo mode movements
Browse files Browse the repository at this point in the history
Makes left / right / up / down camera movements perpendicular to the
current vertical axis. Roll remains unaccounted for.
  • Loading branch information
rr- committed Oct 5, 2024
1 parent e82155a commit ae854ff
Showing 1 changed file with 34 additions and 64 deletions.
98 changes: 34 additions & 64 deletions src/tr1/game/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
#define SHIFT_Z(distance, elevation, angle) \
(((distance * Math_Cos(elevation)) >> W2V_SHIFT) * Math_Cos(angle) \
>> W2V_SHIFT)
#define SHIFT_Y(dy, distance, elevation) \
(dy * -(distance * Math_Sin(elevation) >> W2V_SHIFT))
#define SHIFT_Y(distance, elevation) \
((distance * Math_Sin(elevation) >> W2V_SHIFT))

#define SHIFT_POS(a, b) \
do { \
Expand Down Expand Up @@ -255,9 +255,9 @@ static void M_UpdatePhotoMode(void)
g_Camera.target.x, g_Camera.target.y, g_Camera.target.z);
}

const bool axis_shift_input = g_Input.camera_up || g_Input.camera_down;
const bool dir_shift_input = g_Input.camera_forward || g_Input.camera_back
|| g_Input.camera_left || g_Input.camera_right;
const bool shift_input = g_Input.camera_forward || g_Input.camera_back
|| g_Input.camera_left || g_Input.camera_right || g_Input.camera_up
|| g_Input.camera_down;
const bool rot_input =
g_Input.left || g_Input.right || g_Input.forward || g_Input.back;
const bool rot_target_input = g_InputDB.roll;
Expand All @@ -276,7 +276,7 @@ static void M_UpdatePhotoMode(void)
g_Camera = m_OldCamera;
m_PhotoSpeed = 0;
m_Roll = 0;
} else if (axis_shift_input || dir_shift_input || rot_input || roll_input) {
} else if (shift_input || rot_input || roll_input) {
m_PhotoSpeed++;
CLAMPG(m_PhotoSpeed, PHOTO_MAX_SPEED);
} else {
Expand All @@ -290,73 +290,43 @@ static void M_UpdatePhotoMode(void)
}
CLAMP(m_Roll, -PHOTO_MAX_PITCH_ROLL, PHOTO_MAX_PITCH_ROLL);

if (!axis_shift_input && !dir_shift_input && !rot_input
&& !rot_target_input) {
if (!shift_input && !rot_input && !rot_target_input) {
return;
}

if (axis_shift_input) {
const int32_t distance = CAM_SPEED_SHIFT((WALL_L * 5.0) / LOGIC_FPS);
XYZ_32 shift = {
.x = 0,
.y = 0,
.z = 0,
};
if (g_Input.camera_up) {
shift.y = -distance;
} else if (g_Input.camera_down) {
shift.y = distance;
}
SHIFT_POS(g_Camera.pos, shift);
SHIFT_POS(g_Camera.target, shift);
}

if (dir_shift_input) {
if (shift_input) {
const int32_t distance = CAM_SPEED_SHIFT((WALL_L * 5.0) / LOGIC_FPS);

PHD_ANGLE angle = g_Camera.target_angle;
PHD_ANGLE elevation = g_Camera.target_elevation;

if (g_Input.camera_forward || g_Input.camera_back) {
int32_t dy = 0;
if (g_Input.camera_forward) {
dy = 1;
} else {
angle += PHD_180;
dy = -1;
}

const XYZ_32 shift = {
.x = SHIFT_X(distance, elevation, angle),
.z = SHIFT_Z(distance, elevation, angle),
.y = SHIFT_Y(dy, distance, elevation),
};
SHIFT_POS(g_Camera.pos, shift);
SHIFT_POS(g_Camera.target, shift);

Math_GetVectorAngles(
g_Camera.target.x - g_Camera.pos.x,
g_Camera.target.y - g_Camera.pos.y,
g_Camera.target.z - g_Camera.pos.z, angles);
angle = angles[0];
elevation = angles[1];
int32_t dy = 1;
if (g_Input.camera_left) {
angle -= PHD_90;
elevation = 0;
} else if (g_Input.camera_right) {
angle += PHD_90;
elevation = 0;
} else if (g_Input.camera_forward) {
dy = -1;
} else if (g_Input.camera_back) {
angle += PHD_180;
} else if (g_Input.camera_up) {
elevation += PHD_90;
dy = -1;
} else if (g_Input.camera_down) {
elevation -= PHD_90;
dy = -1;
}

if (g_Input.camera_left || g_Input.camera_right) {
if (g_Input.camera_left) {
angle -= PHD_90;
} else {
angle += PHD_90;
}
const XYZ_32 shift = {
.x = SHIFT_X(distance, elevation, angle),
.z = SHIFT_Z(distance, elevation, angle),
.y = SHIFT_Y(distance * dy, elevation),
};

const XYZ_32 shift = {
.x = SHIFT_X(distance, elevation, angle),
.z = SHIFT_Z(distance, elevation, angle),
.y = 0,
};
SHIFT_POS(g_Camera.pos, shift);
SHIFT_POS(g_Camera.target, shift);
}
SHIFT_POS(g_Camera.pos, shift);
SHIFT_POS(g_Camera.target, shift);
}

if (rot_input) {
Expand All @@ -380,7 +350,7 @@ static void M_UpdatePhotoMode(void)
const XYZ_32 shift = {
.x = SHIFT_X(distance, elevation, angle),
.z = SHIFT_Z(distance, elevation, angle),
.y = SHIFT_Y(1, distance, elevation),
.y = SHIFT_Y(-distance, elevation),
};
g_Camera.target.x = g_Camera.pos.x + shift.x;
g_Camera.target.y = g_Camera.pos.y + shift.y;
Expand All @@ -394,7 +364,7 @@ static void M_UpdatePhotoMode(void)
const XYZ_32 shift = {
.x = SHIFT_X(distance, elevation, angle),
.z = SHIFT_Z(distance, elevation, angle),
.y = SHIFT_Y(1, distance, elevation),
.y = SHIFT_Y(-distance, elevation),
};
g_Camera.pos.x = g_Camera.target.x - shift.x;
g_Camera.pos.y = g_Camera.target.y - shift.y;
Expand Down

0 comments on commit ae854ff

Please sign in to comment.