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"
|
2021-03-19 11:18:45 +00:00
|
|
|
#include "QF/simd/vec4f.h"
|
2012-02-14 08:28:09 +00:00
|
|
|
|
2020-06-21 14:15:17 +00:00
|
|
|
#include "qw/include/chase.h"
|
|
|
|
#include "qw/include/cl_input.h"
|
|
|
|
#include "qw/include/client.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
#include "world.h"
|
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
|
|
|
|
vec4f_t camera_origin = {0,0,0,1};
|
|
|
|
vec4f_t player_origin = {0,0,0,1};
|
|
|
|
vec4f_t player_angles = {0,0,0,1};
|
|
|
|
|
|
|
|
vec3_t camera_angles = {0,0,0};
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2002-08-20 02:22:40 +00:00
|
|
|
vec3_t chase_angles;
|
|
|
|
vec3_t chase_dest;
|
|
|
|
vec3_t chase_dest_angles;
|
|
|
|
vec3_t chase_pos;
|
2001-02-19 21:15:25 +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
|
|
|
}
|
|
|
|
|
2004-11-02 08:40:00 +00:00
|
|
|
static inline void
|
2001-02-26 06:48:02 +00:00
|
|
|
TraceLine (vec3_t start, vec3_t end, vec3_t impact)
|
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;
|
2021-02-01 10:31:11 +00:00
|
|
|
MOD_TraceLine (cl.worldmodel->brush.hulls, 0, start, end, &trace);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
VectorCopy (trace.endpos, impact);
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Chase_Update (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2021-03-19 11:18:45 +00:00
|
|
|
float pitch, yaw, fwd;
|
|
|
|
usercmd_t cmd; // movement direction
|
|
|
|
vec4f_t forward = {}, up = {}, right = {}, stop = {}, dir = {};
|
2001-09-28 07:51:15 +00:00
|
|
|
|
|
|
|
// lazy camera, look toward player entity
|
|
|
|
|
2002-08-20 02:22:40 +00:00
|
|
|
if (chase_active->int_val == 2 || chase_active->int_val == 3) {
|
2001-09-28 07:51:15 +00:00
|
|
|
// control camera angles with key/mouse/joy-look
|
2021-03-19 11:18:45 +00:00
|
|
|
vec3_t d;
|
|
|
|
VectorSubtract (cl.viewstate.angles, player_angles, d);
|
|
|
|
VectorAdd (camera_angles, d, camera_angles);
|
2002-08-20 02:22:40 +00:00
|
|
|
|
|
|
|
if (chase_active->int_val == 2) {
|
|
|
|
if (camera_angles[PITCH] < -60)
|
|
|
|
camera_angles[PITCH] = -60;
|
|
|
|
if (camera_angles[PITCH] > 60)
|
|
|
|
camera_angles[PITCH] = 60;
|
2001-09-28 07:51:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// move camera, it's not enough to just change the angles because
|
|
|
|
// the angles are automatically changed to look toward the player
|
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
if (chase_active->int_val == 3) {
|
|
|
|
player_origin = r_data->refdef->viewposition;
|
|
|
|
}
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
AngleVectors (camera_angles, &forward[0], &right[0], &up[0]);
|
|
|
|
camera_origin = player_origin - chase_back->value * forward;
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2002-08-20 02:22:40 +00:00
|
|
|
if (chase_active->int_val == 2) {
|
2021-03-19 11:18:45 +00:00
|
|
|
player_origin = r_data->refdef->viewposition;
|
2001-09-28 07:51:15 +00:00
|
|
|
|
|
|
|
// don't let camera get too low
|
2021-03-19 11:18:45 +00:00
|
|
|
if (camera_origin[2] < player_origin[2] + chase_up->value) {
|
2001-09-28 07:51:15 +00:00
|
|
|
camera_origin[2] = player_origin[2] + chase_up->value;
|
2021-03-19 11:18:45 +00:00
|
|
|
}
|
2001-09-28 07:51:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// don't let camera get too far from player
|
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
dir = camera_origin - player_origin;
|
|
|
|
forward = normalf (dir);
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
if (magnitudef (dir)[0] > chase_back->value) {
|
|
|
|
camera_origin = player_origin + forward * chase_back->value;
|
2001-09-28 07:51:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check for walls between player and camera
|
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
camera_origin += 8 * forward;
|
|
|
|
//FIXME
|
|
|
|
TraceLine (&player_origin[0], &camera_origin[0], &stop[0]);
|
|
|
|
stop[3] = 1;
|
|
|
|
if (magnitude3f (stop)[0] != 0) {
|
|
|
|
camera_origin = stop - forward;
|
|
|
|
}
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
dir = camera_origin - r_data->refdef->viewposition;
|
|
|
|
forward = normalf (dir);
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2002-08-20 02:22:40 +00:00
|
|
|
if (chase_active->int_val == 2) {
|
|
|
|
if (dir[1] == 0 && dir[0] == 0) {
|
2001-09-28 07:51:15 +00:00
|
|
|
// look straight up or down
|
2021-03-19 11:18:45 +00:00
|
|
|
// camera_angles[YAW] = r_data->refdef->viewstate.angles[YAW];
|
2002-08-20 02:22:40 +00:00
|
|
|
if (dir[2] > 0)
|
|
|
|
camera_angles[PITCH] = 90;
|
|
|
|
else
|
|
|
|
camera_angles[PITCH] = 270;
|
|
|
|
} else {
|
2001-09-28 07:51:15 +00:00
|
|
|
yaw = (atan2 (dir[1], dir[0]) * 180 / M_PI);
|
2002-08-20 02:22:40 +00:00
|
|
|
if (yaw < 0)
|
|
|
|
yaw += 360;
|
|
|
|
if (yaw < 180)
|
|
|
|
yaw += 180;
|
|
|
|
else
|
|
|
|
yaw -= 180;
|
2001-09-28 07:51:15 +00:00
|
|
|
camera_angles[YAW] = yaw;
|
|
|
|
|
|
|
|
fwd = sqrt (dir[0] * dir[0] + dir[1] * dir[1]);
|
|
|
|
pitch = (atan2 (dir[2], fwd) * 180 / M_PI);
|
2002-08-20 02:22:40 +00:00
|
|
|
if (pitch < 0)
|
|
|
|
pitch += 360;
|
2001-09-28 07:51:15 +00:00
|
|
|
camera_angles[PITCH] = pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
AngleQuat (camera_angles, &r_data->refdef->viewrotation[0]);//FIXME rotate camera
|
|
|
|
r_data->refdef->viewposition = camera_origin; // move camera
|
2001-09-28 07:51:15 +00:00
|
|
|
|
|
|
|
// get basic movement from keyboard
|
|
|
|
|
|
|
|
memset (&cmd, 0, sizeof (cmd));
|
2021-03-19 11:18:45 +00:00
|
|
|
// VectorCopy (cl.viewstate.angles, cmd.angles);
|
2001-09-28 07:51:15 +00:00
|
|
|
|
|
|
|
if (in_strafe.state & 1) {
|
[input] Rework logical buttons
kbutton_t is now in_button_t and has been moved to input.h. Also, a
button registration function has been added to take care of +button and
-button command creation and, eventually, direct binding of "physical"
buttons to logical buttons. "Physical" buttons are those coming in from
the OS (keyboard, mouse, joystick...), logical buttons are what the code
looks at for button state.
Additionally, the button edge detection code has been cleaned up such
that it no longer uses magic numbers, and the conversion to a float is
cleaner. Interestingly, I found that the handling is extremely
frame-rate dependent (eg, +forward will accelerate the player to full
speed much faster at 72fps than it does at 20fps). This may be a factor
in why gamers are frame rate obsessed: other games doing the same thing
would certainly feel different under varying frame rates.
2021-10-01 00:16:31 +00:00
|
|
|
cmd.sidemove += cl_sidespeed->value * IN_ButtonState (&in_right);
|
|
|
|
cmd.sidemove -= cl_sidespeed->value * IN_ButtonState (&in_left);
|
2001-09-28 07:51:15 +00:00
|
|
|
}
|
[input] Rework logical buttons
kbutton_t is now in_button_t and has been moved to input.h. Also, a
button registration function has been added to take care of +button and
-button command creation and, eventually, direct binding of "physical"
buttons to logical buttons. "Physical" buttons are those coming in from
the OS (keyboard, mouse, joystick...), logical buttons are what the code
looks at for button state.
Additionally, the button edge detection code has been cleaned up such
that it no longer uses magic numbers, and the conversion to a float is
cleaner. Interestingly, I found that the handling is extremely
frame-rate dependent (eg, +forward will accelerate the player to full
speed much faster at 72fps than it does at 20fps). This may be a factor
in why gamers are frame rate obsessed: other games doing the same thing
would certainly feel different under varying frame rates.
2021-10-01 00:16:31 +00:00
|
|
|
cmd.sidemove += cl_sidespeed->value * IN_ButtonState (&in_moveright);
|
|
|
|
cmd.sidemove -= cl_sidespeed->value * IN_ButtonState (&in_moveleft);
|
2001-09-28 07:51:15 +00:00
|
|
|
|
|
|
|
if (!(in_klook.state & 1)) {
|
2002-08-20 02:22:40 +00:00
|
|
|
cmd.forwardmove += cl_forwardspeed->value
|
[input] Rework logical buttons
kbutton_t is now in_button_t and has been moved to input.h. Also, a
button registration function has been added to take care of +button and
-button command creation and, eventually, direct binding of "physical"
buttons to logical buttons. "Physical" buttons are those coming in from
the OS (keyboard, mouse, joystick...), logical buttons are what the code
looks at for button state.
Additionally, the button edge detection code has been cleaned up such
that it no longer uses magic numbers, and the conversion to a float is
cleaner. Interestingly, I found that the handling is extremely
frame-rate dependent (eg, +forward will accelerate the player to full
speed much faster at 72fps than it does at 20fps). This may be a factor
in why gamers are frame rate obsessed: other games doing the same thing
would certainly feel different under varying frame rates.
2021-10-01 00:16:31 +00:00
|
|
|
* IN_ButtonState (&in_forward);
|
|
|
|
cmd.forwardmove -= cl_backspeed->value * IN_ButtonState (&in_back);
|
2001-09-28 07:51:15 +00:00
|
|
|
}
|
|
|
|
if (in_speed.state & 1) {
|
|
|
|
cmd.forwardmove *= cl_movespeedkey->value;
|
2011-08-24 04:56:00 +00:00
|
|
|
cmd.sidemove *= cl_movespeedkey->value;
|
2001-09-28 07:51:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// mouse and joystick controllers add to movement
|
2021-03-19 11:18:45 +00:00
|
|
|
VectorSet (0, cl.viewstate.angles[1] - camera_angles[1], 0, dir);
|
|
|
|
AngleVectors (&dir[0], &forward[0], &right[0], &up[0]); //FIXME
|
2021-11-18 06:33:49 +00:00
|
|
|
//forward *= viewdelta.position[2] * m_forward->value; FIXME
|
|
|
|
//right *= viewdelta.position[0] * m_side->value; FIXME
|
2021-03-19 11:18:45 +00:00
|
|
|
dir = forward + right;
|
2001-12-11 20:49:10 +00:00
|
|
|
cmd.forwardmove += dir[0];
|
2011-08-24 04:56:00 +00:00
|
|
|
cmd.sidemove -= dir[1];
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2011-08-24 04:56:00 +00:00
|
|
|
VectorSet (0, camera_angles[1], 0, dir);
|
2021-03-19 11:18:45 +00:00
|
|
|
AngleVectors (&dir[0], &forward[0], &right[0], &up[0]); //FIXME
|
2001-09-28 07:51:15 +00:00
|
|
|
|
|
|
|
VectorScale (forward, cmd.forwardmove, forward);
|
2011-08-24 04:56:00 +00:00
|
|
|
VectorScale (right, cmd.sidemove, right);
|
|
|
|
VectorAdd (forward, right, dir);
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2002-08-20 02:22:40 +00:00
|
|
|
if (dir[1] || dir[0]) {
|
2021-03-19 11:18:45 +00:00
|
|
|
cl.viewstate.angles[YAW] = (atan2 (dir[1], dir[0]) * 180 / M_PI);
|
|
|
|
if (cl.viewstate.angles[YAW] < 0) {
|
|
|
|
cl.viewstate.angles[YAW] += 360;
|
|
|
|
}
|
2001-09-28 07:51:15 +00:00
|
|
|
}
|
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
cl.viewstate.angles[PITCH] = 0;
|
2001-09-28 07:51:15 +00:00
|
|
|
|
|
|
|
// remember the new angle to calculate the difference next frame
|
2021-03-19 11:18:45 +00:00
|
|
|
VectorCopy (cl.viewstate.angles, player_angles);
|
2001-09-28 07:51:15 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// regular camera, faces same direction as player
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
//FIXME
|
|
|
|
AngleVectors (cl.viewstate.angles, &forward[0], &right[0], &up[0]);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// calc exact destination
|
2021-03-19 11:18:45 +00:00
|
|
|
camera_origin = r_data->refdef->viewposition
|
|
|
|
- forward * chase_back->value - right * chase_right->value;
|
|
|
|
// chase_up is world up
|
2001-11-30 22:30:23 +00:00
|
|
|
camera_origin[2] += chase_up->value;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-09-28 07:51:15 +00:00
|
|
|
// check for walls between player and camera
|
2021-03-19 11:18:45 +00:00
|
|
|
//FIXME
|
|
|
|
TraceLine (&r_data->refdef->viewposition[0], &camera_origin[0], &stop[0]);
|
|
|
|
stop[3] = 1;
|
|
|
|
if (magnitude3f (stop)[0] != 0) {
|
|
|
|
camera_origin = stop + forward * 8;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
r_data->refdef->viewposition = camera_origin;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|