2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
cl_cam.c
|
|
|
|
|
2001-05-14 03:08:24 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/mathlib.h"
|
2001-08-29 02:12:57 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#include "client.h"
|
|
|
|
#include "world.h"
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean SV_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f,
|
|
|
|
vec3_t p1, vec3_t p2, trace_t *trace);
|
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
|
|
|
vec3_t chase_angles;
|
|
|
|
vec3_t chase_dest;
|
|
|
|
vec3_t chase_dest_angles;
|
2001-08-29 02:12:57 +00:00
|
|
|
vec3_t chase_pos;
|
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
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
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));
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1, start, end, &trace);
|
|
|
|
|
|
|
|
VectorCopy (trace.endpos, impact);
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Chase_Update (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
float dist;
|
|
|
|
vec3_t forward, up, right;
|
|
|
|
vec3_t dest, stop;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// if can't see player, reset
|
|
|
|
AngleVectors (cl.viewangles, forward, right, up);
|
|
|
|
|
|
|
|
// calc exact destination
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
chase_dest[i] = r_refdef.vieworg[i]
|
|
|
|
- forward[i] * chase_back->value - right[i] * chase_right->value;
|
2001-02-19 21:15:25 +00:00
|
|
|
chase_dest[2] = r_refdef.vieworg[2] + chase_up->value;
|
|
|
|
|
|
|
|
// find the spot the player is looking at
|
|
|
|
VectorMA (r_refdef.vieworg, 4096, forward, dest);
|
|
|
|
TraceLine (r_refdef.vieworg, dest, stop);
|
|
|
|
|
|
|
|
// calculate pitch to look at the same spot from camera
|
|
|
|
VectorSubtract (stop, r_refdef.vieworg, stop);
|
|
|
|
dist = DotProduct (stop, forward);
|
|
|
|
if (dist < 1)
|
|
|
|
dist = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
r_refdef.viewangles[PITCH] = -atan (stop[2] / dist) / M_PI * 180;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
TraceLine (r_refdef.vieworg, chase_dest, stop);
|
|
|
|
if (Length (stop) != 0)
|
|
|
|
VectorCopy (stop, chase_dest);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// move towards destination
|
|
|
|
VectorCopy (chase_dest, r_refdef.vieworg);
|
|
|
|
}
|