Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5131 | clevermous | 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", "100"}; |
||
25 | cvar_t chase_up = {"chase_up", "16"}; |
||
26 | cvar_t chase_right = {"chase_right", "0"}; |
||
27 | cvar_t chase_active = {"chase_active", "0"}; |
||
28 | |||
29 | vec3_t chase_pos; |
||
30 | vec3_t chase_angles; |
||
31 | |||
32 | vec3_t chase_dest; |
||
33 | vec3_t chase_dest_angles; |
||
34 | |||
35 | |||
36 | void Chase_Init (void) |
||
37 | { |
||
38 | Cvar_RegisterVariable (&chase_back); |
||
39 | Cvar_RegisterVariable (&chase_up); |
||
40 | Cvar_RegisterVariable (&chase_right); |
||
41 | Cvar_RegisterVariable (&chase_active); |
||
42 | } |
||
43 | |||
44 | void Chase_Reset (void) |
||
45 | { |
||
46 | // for respawning and teleporting |
||
47 | // start position 12 units behind head |
||
48 | } |
||
49 | |||
50 | void TraceLine (vec3_t start, vec3_t end, vec3_t impact) |
||
51 | { |
||
52 | trace_t trace; |
||
53 | |||
54 | memset (&trace, 0, sizeof(trace)); |
||
55 | SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1, start, end, &trace); |
||
56 | |||
57 | VectorCopy (trace.endpos, impact); |
||
58 | } |
||
59 | |||
60 | void Chase_Update (void) |
||
61 | { |
||
62 | int i; |
||
63 | float dist; |
||
64 | vec3_t forward, up, right; |
||
65 | vec3_t dest, stop; |
||
66 | |||
67 | |||
68 | // if can't see player, reset |
||
69 | AngleVectors (cl.viewangles, forward, right, up); |
||
70 | |||
71 | // calc exact destination |
||
72 | for (i=0 ; i<3 ; i++) |
||
73 | chase_dest[i] = r_refdef.vieworg[i] |
||
74 | - forward[i]*chase_back.value |
||
75 | - right[i]*chase_right.value; |
||
76 | chase_dest[2] = r_refdef.vieworg[2] + chase_up.value; |
||
77 | |||
78 | // find the spot the player is looking at |
||
79 | VectorMA (r_refdef.vieworg, 4096, forward, dest); |
||
80 | TraceLine (r_refdef.vieworg, dest, stop); |
||
81 | |||
82 | // calculate pitch to look at the same spot from camera |
||
83 | VectorSubtract (stop, r_refdef.vieworg, stop); |
||
84 | dist = DotProduct (stop, forward); |
||
85 | if (dist < 1) |
||
86 | dist = 1; |
||
87 | r_refdef.viewangles[PITCH] = -atan(stop[2] / dist) / M_PI * 180; |
||
88 | |||
89 | // move towards destination |
||
90 | VectorCopy (chase_dest, r_refdef.vieworg); |
||
91 | }>3> |
||
92 |