2001-02-19 21:15:25 +00:00
|
|
|
/*
|
2012-05-20 10:17:41 +00:00
|
|
|
cl_chase.c
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-05-20 10:17:41 +00:00
|
|
|
chase camera support
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-05-20 10:17:41 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "QF/keys.h"
|
|
|
|
#include "QF/input.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/mathlib.h"
|
2001-08-29 02:12:57 +00:00
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "QF/plugin/vid_render.h"
|
2022-03-01 02:43:23 +00:00
|
|
|
#include "QF/scene/transform.h"
|
2012-02-14 08:28:09 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#include "world.h"
|
|
|
|
|
2022-02-22 06:23:09 +00:00
|
|
|
#include "client/chase.h"
|
|
|
|
#include "client/input.h"
|
|
|
|
#include "client/view.h"
|
2020-06-21 14:15:17 +00:00
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
cvar_t *chase_back;
|
|
|
|
cvar_t *chase_up;
|
|
|
|
cvar_t *chase_right;
|
|
|
|
cvar_t *chase_active;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2001-05-19 22:26:06 +00:00
|
|
|
Chase_Init_Cvars (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-04-10 23:39:30 +00:00
|
|
|
chase_back = Cvar_Get ("chase_back", "100", CVAR_NONE, NULL, "None");
|
|
|
|
chase_up = Cvar_Get ("chase_up", "16", CVAR_NONE, NULL, "None");
|
|
|
|
chase_right = Cvar_Get ("chase_right", "0", CVAR_NONE, NULL, "None");
|
|
|
|
chase_active = Cvar_Get ("chase_active", "0", CVAR_NONE, NULL, "None");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Chase_Reset (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
// for respawning and teleporting
|
2001-05-14 03:08:24 +00:00
|
|
|
// start position 12 units behind head
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-03-01 02:43:23 +00:00
|
|
|
static inline vec4f_t
|
|
|
|
TraceLine (chasestate_t *cs, vec4f_t start, vec4f_t end)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
trace_t trace;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
memset (&trace, 0, sizeof (trace));
|
2011-08-24 04:56:00 +00:00
|
|
|
trace.fraction = 1;
|
2022-03-01 02:43:23 +00:00
|
|
|
MOD_TraceLine (cs->worldmodel->brush.hulls, 0, &start[0], &end[0], &trace);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-03-01 02:43:23 +00:00
|
|
|
return (vec4f_t) {trace.endpos[0], trace.endpos[1], trace.endpos[2], 1};
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
static void
|
|
|
|
check_for_walls (chasestate_t *cs, vec4f_t forward)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2022-03-01 04:49:14 +00:00
|
|
|
// check for walls between player and camera
|
|
|
|
cs->camera_origin += 8 * forward;
|
|
|
|
vec4f_t stop = TraceLine (cs, cs->player_origin, cs->camera_origin);
|
|
|
|
if (magnitude3f (stop)[0] != 0) {
|
|
|
|
cs->camera_origin = stop - forward;
|
|
|
|
}
|
|
|
|
}
|
2001-09-28 07:51:15 +00:00
|
|
|
|
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
static void
|
|
|
|
limit_distance (chasestate_t *cs)
|
|
|
|
{
|
|
|
|
// don't let camera get too far from player
|
2002-08-20 02:22:40 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
vec4f_t dir = cs->camera_origin - cs->player_origin;
|
|
|
|
vec4f_t forward = normalf (dir);
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
if (magnitudef (dir)[0] > chase_back->value) {
|
|
|
|
cs->camera_origin = cs->player_origin + forward * chase_back->value;
|
|
|
|
}
|
|
|
|
}
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
static void
|
|
|
|
set_camera (chasestate_t *cs, viewstate_t *vs)
|
|
|
|
{
|
|
|
|
vec4f_t rotation;
|
|
|
|
AngleQuat (cs->camera_angles, &rotation[0]);//FIXME
|
|
|
|
Transform_SetWorldRotation (vs->camera_transform, rotation);
|
|
|
|
Transform_SetWorldPosition (vs->camera_transform, cs->camera_origin);
|
|
|
|
}
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
static void
|
|
|
|
cam_controls (chasestate_t *cs, viewstate_t *vs)
|
|
|
|
{
|
|
|
|
// get basic movement from keyboard
|
|
|
|
vec4f_t move = { };
|
|
|
|
vec4f_t forward = { };
|
|
|
|
vec4f_t right = { };
|
|
|
|
vec4f_t up = { };
|
|
|
|
vec4f_t dir = { };
|
|
|
|
|
|
|
|
if (in_strafe.state & 1) {
|
|
|
|
move[SIDE] += cl_sidespeed->value * IN_ButtonState (&in_right);
|
|
|
|
move[SIDE] -= cl_sidespeed->value * IN_ButtonState (&in_left);
|
|
|
|
}
|
|
|
|
move[SIDE] += cl_sidespeed->value * IN_ButtonState (&in_moveright);
|
|
|
|
move[SIDE] -= cl_sidespeed->value * IN_ButtonState (&in_moveleft);
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
if (!(in_klook.state & 1)) {
|
|
|
|
move[FORWARD] += cl_forwardspeed->value
|
|
|
|
* IN_ButtonState (&in_forward);
|
|
|
|
move[FORWARD] -= cl_backspeed->value * IN_ButtonState (&in_back);
|
|
|
|
}
|
|
|
|
if (in_speed.state & 1) {
|
|
|
|
move *= cl_movespeedkey->value;
|
|
|
|
}
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
// mouse and joystick controllers add to movement
|
|
|
|
VectorSet (0, vs->player_angles[1] - cs->camera_angles[1], 0, dir);
|
|
|
|
AngleVectors (&dir[0], &forward[0], &right[0], &up[0]); //FIXME
|
|
|
|
//forward *= viewdelta.position[2] * m_forward->value; FIXME
|
|
|
|
//right *= viewdelta.position[0] * m_side->value; FIXME
|
|
|
|
dir = forward + right;
|
|
|
|
move[FORWARD] += dir[0];
|
|
|
|
move[SIDE] -= dir[1];
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
VectorSet (0, cs->camera_angles[1], 0, dir);
|
|
|
|
AngleVectors (&dir[0], &forward[0], &right[0], &up[0]); //FIXME
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
dir = forward * move[FORWARD] + right * move[SIDE];
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
if (dir[1] || dir[0]) {
|
|
|
|
vs->player_angles[YAW] = (atan2 (dir[1], dir[0]) * 180 / M_PI);
|
|
|
|
if (vs->player_angles[YAW] < 0) {
|
|
|
|
vs->player_angles[YAW] += 360;
|
2001-09-28 07:51:15 +00:00
|
|
|
}
|
2022-03-01 04:49:14 +00:00
|
|
|
}
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
vs->player_angles[PITCH] = 0;
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
// remember the new angle to calculate the difference next frame
|
|
|
|
VectorCopy (vs->player_angles, cs->player_angles);
|
|
|
|
}
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
static void
|
|
|
|
update_cam_frame (chasestate_t *cs, viewstate_t *vs)
|
|
|
|
{
|
|
|
|
// control camera angles with key/mouse/joy-look
|
|
|
|
vec3_t d;
|
|
|
|
VectorSubtract (vs->player_angles, cs->player_angles, d);
|
|
|
|
VectorAdd (cs->camera_angles, d, cs->camera_angles);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
chase_mode_1 (chasestate_t *cs)
|
|
|
|
{
|
|
|
|
// regular camera, faces same direction as player
|
|
|
|
viewstate_t *vs = cs->viewstate;
|
|
|
|
vec4f_t forward = {}, up = {}, right = {}, stop = {};
|
|
|
|
//FIXME
|
|
|
|
AngleVectors (vs->player_angles, &forward[0], &right[0], &up[0]);
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
// calc exact destination
|
|
|
|
cs->camera_origin = vs->player_origin
|
|
|
|
- forward * chase_back->value - right * chase_right->value;
|
|
|
|
// chase_up is world up
|
|
|
|
cs->camera_origin[2] += chase_up->value;
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
// check for walls between player and camera
|
|
|
|
stop = TraceLine (cs, vs->player_origin, cs->camera_origin);
|
|
|
|
if (magnitude3f (stop)[0] != 0) {
|
|
|
|
cs->camera_origin = stop + forward * 8;
|
|
|
|
}
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
Transform_SetWorldPosition (vs->camera_transform, cs->camera_origin);
|
|
|
|
}
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
static void
|
|
|
|
chase_mode_2 (chasestate_t *cs)
|
|
|
|
{
|
|
|
|
viewstate_t *vs = cs->viewstate;
|
|
|
|
vec4f_t forward = {}, up = {}, right = {}, dir = {};
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
// lazy camera, look toward player entity
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
update_cam_frame (cs, vs);
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
cs->camera_angles[PITCH] = bound (-60, cs->camera_angles[PITCH], 60);
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
// move camera, it's not enough to just change the angles because
|
|
|
|
// the angles are automatically changed to look toward the player
|
|
|
|
AngleVectors (cs->camera_angles, &forward[0], &right[0], &up[0]);
|
|
|
|
cs->camera_origin = cs->player_origin - chase_back->value * forward;
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
cs->player_origin = vs->player_origin;
|
|
|
|
|
|
|
|
// don't let camera get too low
|
|
|
|
if (cs->camera_origin[2] < cs->player_origin[2] + chase_up->value) {
|
|
|
|
cs->camera_origin[2] = cs->player_origin[2] + chase_up->value;
|
2001-09-28 07:51:15 +00:00
|
|
|
}
|
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
limit_distance (cs);
|
|
|
|
check_for_walls (cs, forward);
|
|
|
|
|
|
|
|
dir = cs->camera_origin - vs->player_origin;
|
|
|
|
forward = normalf (dir);
|
|
|
|
|
|
|
|
if (dir[1] == 0 && dir[0] == 0) {
|
|
|
|
// look straight up or down
|
|
|
|
cs->camera_angles[YAW] = vs->player_angles[YAW];
|
|
|
|
if (dir[2] > 0)
|
|
|
|
cs->camera_angles[PITCH] = 90;
|
|
|
|
else
|
|
|
|
cs->camera_angles[PITCH] = 270;
|
|
|
|
} else {
|
|
|
|
float pitch, yaw, fwd;
|
|
|
|
yaw = (atan2 (dir[1], dir[0]) * 180 / M_PI);
|
|
|
|
if (yaw < 0)
|
|
|
|
yaw += 360;
|
|
|
|
if (yaw < 180)
|
|
|
|
yaw += 180;
|
|
|
|
else
|
|
|
|
yaw -= 180;
|
|
|
|
cs->camera_angles[YAW] = yaw;
|
|
|
|
|
|
|
|
fwd = sqrt (dir[0] * dir[0] + dir[1] * dir[1]);
|
|
|
|
pitch = (atan2 (dir[2], fwd) * 180 / M_PI);
|
|
|
|
if (pitch < 0)
|
|
|
|
pitch += 360;
|
|
|
|
cs->camera_angles[PITCH] = pitch;
|
|
|
|
}
|
|
|
|
set_camera (cs, vs);
|
|
|
|
cam_controls (cs, vs);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
static void
|
|
|
|
chase_mode_3 (chasestate_t *cs)
|
|
|
|
{
|
|
|
|
viewstate_t *vs = cs->viewstate;
|
|
|
|
vec4f_t forward = {}, up = {}, right = {};
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
// lazy camera, look toward player entity
|
|
|
|
update_cam_frame (cs, vs);
|
|
|
|
|
|
|
|
// move camera, it's not enough to just change the angles because
|
|
|
|
// the angles are automatically changed to look toward the player
|
|
|
|
|
|
|
|
cs->player_origin = vs->player_origin;
|
|
|
|
AngleVectors (cs->camera_angles, &forward[0], &right[0], &up[0]);
|
|
|
|
cs->camera_origin = cs->player_origin - chase_back->value * forward;
|
|
|
|
limit_distance (cs);
|
|
|
|
check_for_walls (cs, forward);
|
|
|
|
set_camera (cs, vs);
|
|
|
|
cam_controls (cs, vs);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-03-01 04:49:14 +00:00
|
|
|
void
|
|
|
|
Chase_Update (chasestate_t *cs)
|
|
|
|
{
|
|
|
|
switch (chase_active->int_val) {
|
|
|
|
case 1:
|
|
|
|
chase_mode_1 (cs);
|
|
|
|
return;
|
|
|
|
case 2:
|
|
|
|
chase_mode_2 (cs);
|
|
|
|
return;
|
|
|
|
case 3:
|
|
|
|
chase_mode_3 (cs);
|
|
|
|
return;
|
2021-03-19 11:18:45 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|