]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - chase.c
Fog variables redesigned slightly. (no longer cvars)
[xonotic/darkplaces.git] / chase.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
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.
8
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.  
12
13 See the GNU General Public License for more details.
14
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.
18
19 */
20 // chase.c -- chase camera code
21
22 #include "quakedef.h"
23
24 cvar_t  chase_back = {"chase_back", "48"};
25 cvar_t  chase_up = {"chase_up", "22"};
26 cvar_t  chase_active = {"chase_active", "0"};
27
28 void Chase_Init (void)
29 {
30         Cvar_RegisterVariable (&chase_back);
31         Cvar_RegisterVariable (&chase_up);
32         Cvar_RegisterVariable (&chase_active);
33 }
34
35 void Chase_Reset (void)
36 {
37         // for respawning and teleporting
38 //      start position 12 units behind head
39 }
40
41 qboolean SV_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, vec3_t p2, trace_t *trace);
42
43 void TraceLine (vec3_t start, vec3_t end, vec3_t impact)
44 {
45         trace_t trace;
46
47         memset (&trace, 0, sizeof(trace));
48         SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1, start, end, &trace);
49
50         if (trace.fraction < 1)
51         {
52                 VectorCopy (trace.endpos, impact);
53         }
54         else
55         {
56                 VectorCopy (end, impact);
57         }
58 }
59
60 void Chase_Update (void)
61 {
62         vec3_t  forward, up, right, stop, chase_dest;
63         float   dist;
64
65         chase_back.value = bound(0, chase_back.value, 128);
66         chase_up.value = bound(-64, chase_up.value, 64);
67
68         AngleVectors (cl.viewangles, forward, right, up);
69
70         dist = -chase_back.value - 8;
71         chase_dest[0] = r_refdef.vieworg[0] + forward[0] * dist;
72         chase_dest[1] = r_refdef.vieworg[1] + forward[1] * dist;
73         chase_dest[2] = r_refdef.vieworg[2] + forward[2] * dist + chase_up.value;
74
75         TraceLine (r_refdef.vieworg, chase_dest, stop);
76         chase_dest[0] = stop[0] + forward[0] * 8;
77         chase_dest[1] = stop[1] + forward[1] * 8;
78         chase_dest[2] = stop[2] + forward[2] * 8;
79
80         VectorCopy (chase_dest, r_refdef.vieworg);
81 }
82