mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-29 23:52:22 +00:00
Clean up chase/spectator camera stuff.
o Rename nq's cl_cam.c to cl_chase.c. o Split out the chase cam stuff from qw's cl_cam.c to cl_chase.c
This commit is contained in:
parent
ac1bf2a158
commit
96785ccec7
9 changed files with 314 additions and 203 deletions
|
@ -74,7 +74,7 @@ server_LIBS= $(server_LIBFILES) $(common_LIBFILES) $(NET_LIBS)
|
||||||
server_LIB_DEPS=$(server_LIBFILES) $(common_LIBFILES)
|
server_LIB_DEPS=$(server_LIBFILES) $(common_LIBFILES)
|
||||||
|
|
||||||
libnq_client_a_SOURCES= \
|
libnq_client_a_SOURCES= \
|
||||||
cl_cam.c cl_cmd.c cl_demo.c cl_ents.c cl_input.c cl_main.c \
|
cl_chase.c cl_cmd.c cl_demo.c cl_ents.c cl_input.c cl_main.c \
|
||||||
cl_screen.c cl_parse.c cl_tent.c cl_view.c sbar.c
|
cl_screen.c cl_parse.c cl_tent.c cl_view.c sbar.c
|
||||||
|
|
||||||
libnq_server_a_SOURCES= \
|
libnq_server_a_SOURCES= \
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
cl_cam.c
|
cl_chase.c
|
||||||
|
|
||||||
camera support
|
chase camera support
|
||||||
|
|
||||||
Copyright (C) 1996-1997 Id Software, Inc.
|
Copyright (C) 1996-1997 Id Software, Inc.
|
||||||
|
|
||||||
|
@ -28,6 +28,13 @@
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_STRING_H
|
||||||
|
# include <string.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_STRINGS_H
|
||||||
|
# include <strings.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "QF/cvar.h"
|
#include "QF/cvar.h"
|
||||||
#include "QF/keys.h"
|
#include "QF/keys.h"
|
||||||
#include "QF/input.h"
|
#include "QF/input.h"
|
37
qw/include/chase.h
Normal file
37
qw/include/chase.h
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
chase.h
|
||||||
|
|
||||||
|
@description@
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __chase_h
|
||||||
|
#define __chase_h
|
||||||
|
|
||||||
|
extern struct cvar_s *chase_active;
|
||||||
|
|
||||||
|
void Chase_Init_Cvars (void);
|
||||||
|
void Chase_Reset (void);
|
||||||
|
void Chase_Update (void);
|
||||||
|
|
||||||
|
#endif // __chase_h
|
|
@ -41,7 +41,6 @@
|
||||||
extern int autocam;
|
extern int autocam;
|
||||||
extern int spec_track; // player# of who we are tracking
|
extern int spec_track; // player# of who we are tracking
|
||||||
extern int ideal_track;
|
extern int ideal_track;
|
||||||
extern struct cvar_s *chase_active;
|
|
||||||
|
|
||||||
void Cam_Lock (int playernum);
|
void Cam_Lock (int playernum);
|
||||||
int Cam_TrackNum (void);
|
int Cam_TrackNum (void);
|
||||||
|
@ -55,6 +54,4 @@ void CL_Cam_Init_Cvars(void);
|
||||||
|
|
||||||
void CL_ParseEntityLump(const char *entdata);
|
void CL_ParseEntityLump(const char *entdata);
|
||||||
|
|
||||||
void Chase_Update (void);
|
|
||||||
|
|
||||||
#endif // _CL_CAM_H
|
#endif // _CL_CAM_H
|
||||||
|
|
|
@ -109,7 +109,8 @@ client_LIBS= $(qw_client_LIBS)
|
||||||
client_libs= libqw_client.a libqw_common.a
|
client_libs= libqw_client.a libqw_common.a
|
||||||
|
|
||||||
libqw_client_a_SOURCES= \
|
libqw_client_a_SOURCES= \
|
||||||
cl_cam.c cl_chat.c cl_cmd.c cl_cvar.c cl_demo.c cl_entparse.c \
|
cl_cam.c cl_chase.c cl_chat.c cl_cmd.c cl_cvar.c cl_demo.c \
|
||||||
|
cl_entparse.c \
|
||||||
cl_ents.c cl_http.c cl_input.c cl_main.c cl_ngraph.c cl_parse.c \
|
cl_ents.c cl_http.c cl_input.c cl_main.c cl_ngraph.c cl_parse.c \
|
||||||
cl_pred.c cl_screen.c cl_skin.c cl_slist.c cl_tent.c cl_view.c \
|
cl_pred.c cl_screen.c cl_skin.c cl_slist.c cl_tent.c cl_view.c \
|
||||||
locs.c sbar.c teamplay.c
|
locs.c sbar.c teamplay.c
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#include "QF/cvar.h"
|
#include "QF/cvar.h"
|
||||||
#include "QF/msg.h"
|
#include "QF/msg.h"
|
||||||
|
|
||||||
|
#include "chase.h"
|
||||||
#include "cl_cam.h"
|
#include "cl_cam.h"
|
||||||
#include "cl_input.h"
|
#include "cl_input.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
@ -65,15 +66,6 @@
|
||||||
#include "QF/mathlib.h"
|
#include "QF/mathlib.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
|
|
||||||
vec3_t camera_origin = {0,0,0};
|
|
||||||
vec3_t camera_angles = {0,0,0};
|
|
||||||
vec3_t player_origin = {0,0,0};
|
|
||||||
vec3_t player_angles = {0,0,0};
|
|
||||||
|
|
||||||
cvar_t *chase_back;
|
|
||||||
cvar_t *chase_up;
|
|
||||||
cvar_t *chase_right;
|
|
||||||
cvar_t *chase_active;
|
|
||||||
cvar_t *cl_hightrack; // track high fragger
|
cvar_t *cl_hightrack; // track high fragger
|
||||||
cvar_t *cl_chasecam;
|
cvar_t *cl_chasecam;
|
||||||
cvar_t *cl_camera_maxpitch;
|
cvar_t *cl_camera_maxpitch;
|
||||||
|
@ -668,190 +660,4 @@ CL_Cam_Init_Cvars (void)
|
||||||
cl_hightrack = Cvar_Get ("cl_hightrack", "0", CVAR_NONE, NULL, "view the "
|
cl_hightrack = Cvar_Get ("cl_hightrack", "0", CVAR_NONE, NULL, "view the "
|
||||||
"player who has the most frags while you are in "
|
"player who has the most frags while you are in "
|
||||||
"spectator mode.");
|
"spectator mode.");
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
TraceLine (vec3_t start, vec3_t end, vec3_t impact)
|
|
||||||
{
|
|
||||||
trace_t trace;
|
|
||||||
|
|
||||||
memset (&trace, 0, sizeof (trace));
|
|
||||||
trace.fraction = 1;
|
|
||||||
MOD_TraceLine (cl.worldmodel->hulls, 0, start, end, &trace);
|
|
||||||
|
|
||||||
VectorCopy (trace.endpos, impact);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Chase_Update (void)
|
|
||||||
{
|
|
||||||
float pitch, yaw, fwd;
|
|
||||||
int i;
|
|
||||||
usercmd_t cmd; // movement direction
|
|
||||||
vec3_t forward, up, right, stop, dir;
|
|
||||||
|
|
||||||
// lazy camera, look toward player entity
|
|
||||||
|
|
||||||
if (chase_active->int_val == 2 || chase_active->int_val == 3) {
|
|
||||||
// control camera angles with key/mouse/joy-look
|
|
||||||
|
|
||||||
camera_angles[PITCH] += cl.viewangles[PITCH] - player_angles[PITCH];
|
|
||||||
camera_angles[YAW] += cl.viewangles[YAW] - player_angles[YAW];
|
|
||||||
camera_angles[ROLL] += cl.viewangles[ROLL] - player_angles[ROLL];
|
|
||||||
|
|
||||||
if (chase_active->int_val == 2) {
|
|
||||||
if (camera_angles[PITCH] < -60)
|
|
||||||
camera_angles[PITCH] = -60;
|
|
||||||
if (camera_angles[PITCH] > 60)
|
|
||||||
camera_angles[PITCH] = 60;
|
|
||||||
}
|
|
||||||
|
|
||||||
// move camera, it's not enough to just change the angles because
|
|
||||||
// the angles are automatically changed to look toward the player
|
|
||||||
|
|
||||||
if (chase_active->int_val == 3)
|
|
||||||
VectorCopy (r_data->refdef->vieworg, player_origin);
|
|
||||||
|
|
||||||
AngleVectors (camera_angles, forward, right, up);
|
|
||||||
VectorScale (forward, chase_back->value, forward);
|
|
||||||
VectorSubtract (player_origin, forward, camera_origin);
|
|
||||||
|
|
||||||
if (chase_active->int_val == 2) {
|
|
||||||
VectorCopy (r_data->refdef->vieworg, player_origin);
|
|
||||||
|
|
||||||
// don't let camera get too low
|
|
||||||
if (camera_origin[2] < player_origin[2] + chase_up->value)
|
|
||||||
camera_origin[2] = player_origin[2] + chase_up->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// don't let camera get too far from player
|
|
||||||
|
|
||||||
VectorSubtract (camera_origin, player_origin, dir);
|
|
||||||
VectorCopy (dir, forward);
|
|
||||||
VectorNormalize (forward);
|
|
||||||
|
|
||||||
if (VectorLength (dir) > chase_back->value) {
|
|
||||||
VectorScale (forward, chase_back->value, dir);
|
|
||||||
VectorAdd (player_origin, dir, camera_origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for walls between player and camera
|
|
||||||
|
|
||||||
VectorScale (forward, 8, forward);
|
|
||||||
VectorAdd (camera_origin, forward, camera_origin);
|
|
||||||
TraceLine (player_origin, camera_origin, stop);
|
|
||||||
if (VectorLength (stop) != 0)
|
|
||||||
VectorSubtract (stop, forward, camera_origin);
|
|
||||||
|
|
||||||
VectorSubtract (camera_origin, r_data->refdef->vieworg, dir);
|
|
||||||
VectorCopy (dir, forward);
|
|
||||||
VectorNormalize (forward);
|
|
||||||
|
|
||||||
if (chase_active->int_val == 2) {
|
|
||||||
if (dir[1] == 0 && dir[0] == 0) {
|
|
||||||
// look straight up or down
|
|
||||||
// camera_angles[YAW] = r_data->refdef->viewangles[YAW];
|
|
||||||
if (dir[2] > 0)
|
|
||||||
camera_angles[PITCH] = 90;
|
|
||||||
else
|
|
||||||
camera_angles[PITCH] = 270;
|
|
||||||
} else {
|
|
||||||
yaw = (atan2 (dir[1], dir[0]) * 180 / M_PI);
|
|
||||||
if (yaw < 0)
|
|
||||||
yaw += 360;
|
|
||||||
if (yaw < 180)
|
|
||||||
yaw += 180;
|
|
||||||
else
|
|
||||||
yaw -= 180;
|
|
||||||
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;
|
|
||||||
camera_angles[PITCH] = pitch;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VectorCopy (camera_angles, r_data->refdef->viewangles);// rotate camera
|
|
||||||
VectorCopy (camera_origin, r_data->refdef->vieworg); // move camera
|
|
||||||
|
|
||||||
// get basic movement from keyboard
|
|
||||||
|
|
||||||
memset (&cmd, 0, sizeof (cmd));
|
|
||||||
// VectorCopy (cl.viewangles, cmd.angles);
|
|
||||||
|
|
||||||
if (in_strafe.state & 1) {
|
|
||||||
cmd.sidemove += cl_sidespeed->value * CL_KeyState (&in_right);
|
|
||||||
cmd.sidemove -= cl_sidespeed->value * CL_KeyState (&in_left);
|
|
||||||
}
|
|
||||||
cmd.sidemove += cl_sidespeed->value * CL_KeyState (&in_moveright);
|
|
||||||
cmd.sidemove -= cl_sidespeed->value * CL_KeyState (&in_moveleft);
|
|
||||||
|
|
||||||
if (!(in_klook.state & 1)) {
|
|
||||||
cmd.forwardmove += cl_forwardspeed->value
|
|
||||||
* CL_KeyState (&in_forward);
|
|
||||||
cmd.forwardmove -= cl_backspeed->value * CL_KeyState (&in_back);
|
|
||||||
}
|
|
||||||
if (in_speed.state & 1) {
|
|
||||||
cmd.forwardmove *= cl_movespeedkey->value;
|
|
||||||
cmd.sidemove *= cl_movespeedkey->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// mouse and joystick controllers add to movement
|
|
||||||
VectorSet (0, cl.viewangles[1] - camera_angles[1], 0, dir);
|
|
||||||
AngleVectors (dir, forward, right, up);
|
|
||||||
VectorScale (forward, viewdelta.position[2] * m_forward->value,
|
|
||||||
forward);
|
|
||||||
VectorScale (right, viewdelta.position[0] * m_side->value, right);
|
|
||||||
VectorAdd (forward, right, dir);
|
|
||||||
cmd.forwardmove += dir[0];
|
|
||||||
cmd.sidemove -= dir[1];
|
|
||||||
|
|
||||||
VectorSet (0, camera_angles[1], 0, dir);
|
|
||||||
AngleVectors (dir, forward, right, up);
|
|
||||||
|
|
||||||
VectorScale (forward, cmd.forwardmove, forward);
|
|
||||||
VectorScale (right, cmd.sidemove, right);
|
|
||||||
VectorAdd (forward, right, dir);
|
|
||||||
|
|
||||||
if (dir[1] || dir[0]) {
|
|
||||||
cl.viewangles[YAW] = (atan2 (dir[1], dir[0]) * 180 / M_PI);
|
|
||||||
if (cl.viewangles[YAW] < 0) cl.viewangles[YAW] += 360;
|
|
||||||
// if (cl.viewangles[YAW] < 180)
|
|
||||||
// cl.viewangles[YAW] += 180;
|
|
||||||
// else
|
|
||||||
// cl.viewangles[YAW] -= 180;
|
|
||||||
}
|
|
||||||
|
|
||||||
cl.viewangles[PITCH] = 0;
|
|
||||||
|
|
||||||
// remember the new angle to calculate the difference next frame
|
|
||||||
VectorCopy (cl.viewangles, player_angles);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// regular camera, faces same direction as player
|
|
||||||
|
|
||||||
AngleVectors (cl.viewangles, forward, right, up);
|
|
||||||
|
|
||||||
// calc exact destination
|
|
||||||
for (i = 0; i < 3; i++)
|
|
||||||
camera_origin[i] = r_data->refdef->vieworg[i]
|
|
||||||
- forward[i] * chase_back->value - right[i] * chase_right->value;
|
|
||||||
camera_origin[2] += chase_up->value;
|
|
||||||
|
|
||||||
// check for walls between player and camera
|
|
||||||
TraceLine (r_data->refdef->vieworg, camera_origin, stop);
|
|
||||||
if (VectorLength (stop) != 0)
|
|
||||||
for (i = 0; i < 3; i++)
|
|
||||||
camera_origin[i] = stop[i] + forward[i] * 8;
|
|
||||||
|
|
||||||
VectorCopy (camera_origin, r_data->refdef->vieworg);
|
|
||||||
}
|
}
|
||||||
|
|
261
qw/source/cl_chase.c
Normal file
261
qw/source/cl_chase.c
Normal file
|
@ -0,0 +1,261 @@
|
||||||
|
/*
|
||||||
|
cl_chase.c
|
||||||
|
|
||||||
|
chase camera support
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
#ifdef HAVE_STRING_H
|
||||||
|
# include <string.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_STRINGS_H
|
||||||
|
# include <strings.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "QF/cvar.h"
|
||||||
|
#include "QF/keys.h"
|
||||||
|
#include "QF/input.h"
|
||||||
|
#include "QF/mathlib.h"
|
||||||
|
|
||||||
|
#include "QF/plugin/vid_render.h"
|
||||||
|
|
||||||
|
#include "chase.h"
|
||||||
|
#include "cl_input.h"
|
||||||
|
#include "client.h"
|
||||||
|
#include "world.h"
|
||||||
|
|
||||||
|
vec3_t camera_origin = {0,0,0};
|
||||||
|
vec3_t camera_angles = {0,0,0};
|
||||||
|
vec3_t player_origin = {0,0,0};
|
||||||
|
vec3_t player_angles = {0,0,0};
|
||||||
|
|
||||||
|
vec3_t chase_angles;
|
||||||
|
vec3_t chase_dest;
|
||||||
|
vec3_t chase_dest_angles;
|
||||||
|
vec3_t chase_pos;
|
||||||
|
|
||||||
|
cvar_t *chase_back;
|
||||||
|
cvar_t *chase_up;
|
||||||
|
cvar_t *chase_right;
|
||||||
|
cvar_t *chase_active;
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Chase_Init_Cvars (void)
|
||||||
|
{
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Chase_Reset (void)
|
||||||
|
{
|
||||||
|
// for respawning and teleporting
|
||||||
|
// start position 12 units behind head
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
TraceLine (vec3_t start, vec3_t end, vec3_t impact)
|
||||||
|
{
|
||||||
|
trace_t trace;
|
||||||
|
|
||||||
|
memset (&trace, 0, sizeof (trace));
|
||||||
|
trace.fraction = 1;
|
||||||
|
MOD_TraceLine (cl.worldmodel->hulls, 0, start, end, &trace);
|
||||||
|
|
||||||
|
VectorCopy (trace.endpos, impact);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Chase_Update (void)
|
||||||
|
{
|
||||||
|
float pitch, yaw, fwd;
|
||||||
|
int i;
|
||||||
|
usercmd_t cmd; // movement direction
|
||||||
|
vec3_t forward, up, right, stop, dir;
|
||||||
|
|
||||||
|
// lazy camera, look toward player entity
|
||||||
|
|
||||||
|
if (chase_active->int_val == 2 || chase_active->int_val == 3) {
|
||||||
|
// control camera angles with key/mouse/joy-look
|
||||||
|
|
||||||
|
camera_angles[PITCH] += cl.viewangles[PITCH] - player_angles[PITCH];
|
||||||
|
camera_angles[YAW] += cl.viewangles[YAW] - player_angles[YAW];
|
||||||
|
camera_angles[ROLL] += cl.viewangles[ROLL] - player_angles[ROLL];
|
||||||
|
|
||||||
|
if (chase_active->int_val == 2) {
|
||||||
|
if (camera_angles[PITCH] < -60)
|
||||||
|
camera_angles[PITCH] = -60;
|
||||||
|
if (camera_angles[PITCH] > 60)
|
||||||
|
camera_angles[PITCH] = 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
// move camera, it's not enough to just change the angles because
|
||||||
|
// the angles are automatically changed to look toward the player
|
||||||
|
|
||||||
|
if (chase_active->int_val == 3)
|
||||||
|
VectorCopy (r_data->refdef->vieworg, player_origin);
|
||||||
|
|
||||||
|
AngleVectors (camera_angles, forward, right, up);
|
||||||
|
VectorScale (forward, chase_back->value, forward);
|
||||||
|
VectorSubtract (player_origin, forward, camera_origin);
|
||||||
|
|
||||||
|
if (chase_active->int_val == 2) {
|
||||||
|
VectorCopy (r_data->refdef->vieworg, player_origin);
|
||||||
|
|
||||||
|
// don't let camera get too low
|
||||||
|
if (camera_origin[2] < player_origin[2] + chase_up->value)
|
||||||
|
camera_origin[2] = player_origin[2] + chase_up->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// don't let camera get too far from player
|
||||||
|
|
||||||
|
VectorSubtract (camera_origin, player_origin, dir);
|
||||||
|
VectorCopy (dir, forward);
|
||||||
|
VectorNormalize (forward);
|
||||||
|
|
||||||
|
if (VectorLength (dir) > chase_back->value) {
|
||||||
|
VectorScale (forward, chase_back->value, dir);
|
||||||
|
VectorAdd (player_origin, dir, camera_origin);
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for walls between player and camera
|
||||||
|
|
||||||
|
VectorScale (forward, 8, forward);
|
||||||
|
VectorAdd (camera_origin, forward, camera_origin);
|
||||||
|
TraceLine (player_origin, camera_origin, stop);
|
||||||
|
if (VectorLength (stop) != 0)
|
||||||
|
VectorSubtract (stop, forward, camera_origin);
|
||||||
|
|
||||||
|
VectorSubtract (camera_origin, r_data->refdef->vieworg, dir);
|
||||||
|
VectorCopy (dir, forward);
|
||||||
|
VectorNormalize (forward);
|
||||||
|
|
||||||
|
if (chase_active->int_val == 2) {
|
||||||
|
if (dir[1] == 0 && dir[0] == 0) {
|
||||||
|
// look straight up or down
|
||||||
|
// camera_angles[YAW] = r_data->refdef->viewangles[YAW];
|
||||||
|
if (dir[2] > 0)
|
||||||
|
camera_angles[PITCH] = 90;
|
||||||
|
else
|
||||||
|
camera_angles[PITCH] = 270;
|
||||||
|
} else {
|
||||||
|
yaw = (atan2 (dir[1], dir[0]) * 180 / M_PI);
|
||||||
|
if (yaw < 0)
|
||||||
|
yaw += 360;
|
||||||
|
if (yaw < 180)
|
||||||
|
yaw += 180;
|
||||||
|
else
|
||||||
|
yaw -= 180;
|
||||||
|
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;
|
||||||
|
camera_angles[PITCH] = pitch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VectorCopy (camera_angles, r_data->refdef->viewangles);// rotate camera
|
||||||
|
VectorCopy (camera_origin, r_data->refdef->vieworg); // move camera
|
||||||
|
|
||||||
|
// get basic movement from keyboard
|
||||||
|
|
||||||
|
memset (&cmd, 0, sizeof (cmd));
|
||||||
|
// VectorCopy (cl.viewangles, cmd.angles);
|
||||||
|
|
||||||
|
if (in_strafe.state & 1) {
|
||||||
|
cmd.sidemove += cl_sidespeed->value * CL_KeyState (&in_right);
|
||||||
|
cmd.sidemove -= cl_sidespeed->value * CL_KeyState (&in_left);
|
||||||
|
}
|
||||||
|
cmd.sidemove += cl_sidespeed->value * CL_KeyState (&in_moveright);
|
||||||
|
cmd.sidemove -= cl_sidespeed->value * CL_KeyState (&in_moveleft);
|
||||||
|
|
||||||
|
if (!(in_klook.state & 1)) {
|
||||||
|
cmd.forwardmove += cl_forwardspeed->value
|
||||||
|
* CL_KeyState (&in_forward);
|
||||||
|
cmd.forwardmove -= cl_backspeed->value * CL_KeyState (&in_back);
|
||||||
|
}
|
||||||
|
if (in_speed.state & 1) {
|
||||||
|
cmd.forwardmove *= cl_movespeedkey->value;
|
||||||
|
cmd.sidemove *= cl_movespeedkey->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// mouse and joystick controllers add to movement
|
||||||
|
VectorSet (0, cl.viewangles[1] - camera_angles[1], 0, dir);
|
||||||
|
AngleVectors (dir, forward, right, up);
|
||||||
|
VectorScale (forward, viewdelta.position[2] * m_forward->value,
|
||||||
|
forward);
|
||||||
|
VectorScale (right, viewdelta.position[0] * m_side->value, right);
|
||||||
|
VectorAdd (forward, right, dir);
|
||||||
|
cmd.forwardmove += dir[0];
|
||||||
|
cmd.sidemove -= dir[1];
|
||||||
|
|
||||||
|
VectorSet (0, camera_angles[1], 0, dir);
|
||||||
|
AngleVectors (dir, forward, right, up);
|
||||||
|
|
||||||
|
VectorScale (forward, cmd.forwardmove, forward);
|
||||||
|
VectorScale (right, cmd.sidemove, right);
|
||||||
|
VectorAdd (forward, right, dir);
|
||||||
|
|
||||||
|
if (dir[1] || dir[0]) {
|
||||||
|
cl.viewangles[YAW] = (atan2 (dir[1], dir[0]) * 180 / M_PI);
|
||||||
|
if (cl.viewangles[YAW] < 0) cl.viewangles[YAW] += 360;
|
||||||
|
// if (cl.viewangles[YAW] < 180)
|
||||||
|
// cl.viewangles[YAW] += 180;
|
||||||
|
// else
|
||||||
|
// cl.viewangles[YAW] -= 180;
|
||||||
|
}
|
||||||
|
|
||||||
|
cl.viewangles[PITCH] = 0;
|
||||||
|
|
||||||
|
// remember the new angle to calculate the difference next frame
|
||||||
|
VectorCopy (cl.viewangles, player_angles);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// regular camera, faces same direction as player
|
||||||
|
|
||||||
|
AngleVectors (cl.viewangles, forward, right, up);
|
||||||
|
|
||||||
|
// calc exact destination
|
||||||
|
for (i = 0; i < 3; i++)
|
||||||
|
camera_origin[i] = r_data->refdef->vieworg[i]
|
||||||
|
- forward[i] * chase_back->value - right[i] * chase_right->value;
|
||||||
|
camera_origin[2] += chase_up->value;
|
||||||
|
|
||||||
|
// check for walls between player and camera
|
||||||
|
TraceLine (r_data->refdef->vieworg, camera_origin, stop);
|
||||||
|
if (VectorLength (stop) != 0)
|
||||||
|
for (i = 0; i < 3; i++)
|
||||||
|
camera_origin[i] = stop[i] + forward[i] * 8;
|
||||||
|
|
||||||
|
VectorCopy (camera_origin, r_data->refdef->vieworg);
|
||||||
|
}
|
|
@ -47,6 +47,7 @@
|
||||||
|
|
||||||
#include "qw/msg_ucmd.h"
|
#include "qw/msg_ucmd.h"
|
||||||
|
|
||||||
|
#include "chase.h"
|
||||||
#include "cl_cam.h"
|
#include "cl_cam.h"
|
||||||
#include "cl_demo.h"
|
#include "cl_demo.h"
|
||||||
#include "cl_input.h"
|
#include "cl_input.h"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
r_view.c
|
cl_view.c
|
||||||
|
|
||||||
player eye positioning
|
player eye positioning
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@
|
||||||
#include "QF/vid.h"
|
#include "QF/vid.h"
|
||||||
|
|
||||||
#include "qw/bothdefs.h"
|
#include "qw/bothdefs.h"
|
||||||
|
#include "chase.h"
|
||||||
#include "cl_cam.h"
|
#include "cl_cam.h"
|
||||||
#include "cl_ents.h"
|
#include "cl_ents.h"
|
||||||
#include "cl_main.h"
|
#include "cl_main.h"
|
||||||
|
|
Loading…
Reference in a new issue