2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // chase.c -- chase camera code
24 cvar_t chase_back = {CVAR_SAVE, "chase_back", "48"};
25 cvar_t chase_up = {CVAR_SAVE, "chase_up", "48"};
26 cvar_t chase_active = {CVAR_SAVE, "chase_active", "0"};
28 void Chase_Init (void)
30 Cvar_RegisterVariable (&chase_back);
31 Cvar_RegisterVariable (&chase_up);
32 Cvar_RegisterVariable (&chase_active);
35 void Chase_Reset (void)
37 // for respawning and teleporting
38 // start position 12 units behind head
41 int traceline_endcontents;
43 float TraceLine (vec3_t start, vec3_t end, vec3_t impact, vec3_t normal, int contents)
47 // FIXME: broken, fix it
48 // if (impact == NULL && normal == NULL && contents == 0)
49 // return SV_TestLine (cl.worldmodel->hulls, 0, start, end);
51 Mod_CheckLoaded(cl.worldmodel);
52 memset (&trace, 0, sizeof(trace));
53 VectorCopy (end, trace.endpos);
55 trace.startcontents = contents;
56 VectorCopy(start, RecursiveHullCheckInfo.start);
57 VectorSubtract(end, start, RecursiveHullCheckInfo.dist);
58 RecursiveHullCheckInfo.hull = cl.worldmodel->hulls;
59 RecursiveHullCheckInfo.trace = &trace;
60 SV_RecursiveHullCheck (0, 0, 1, start, end);
62 VectorCopy (trace.endpos, impact);
64 VectorCopy (trace.plane.normal, normal);
65 traceline_endcontents = trace.endcontents;
66 return trace.fraction;
69 void Chase_Update (void)
71 vec3_t forward, stop, chase_dest, normal;
74 chase_back.value = bound(0, chase_back.value, 128);
75 chase_up.value = bound(-48, chase_up.value, 96);
77 AngleVectors (cl.viewangles, forward, NULL, NULL);
79 dist = -chase_back.value - 8;
80 chase_dest[0] = r_refdef.vieworg[0] + forward[0] * dist;
81 chase_dest[1] = r_refdef.vieworg[1] + forward[1] * dist;
82 chase_dest[2] = r_refdef.vieworg[2] + forward[2] * dist + chase_up.value;
84 TraceLine (r_refdef.vieworg, chase_dest, stop, normal, 0);
85 chase_dest[0] = stop[0] + forward[0] * 8 + normal[0] * 4;
86 chase_dest[1] = stop[1] + forward[1] * 8 + normal[1] * 4;
87 chase_dest[2] = stop[2] + forward[2] * 8 + normal[2] * 4;
89 VectorCopy (chase_dest, r_refdef.vieworg);