]> icculus.org git repositories - divverent/darkplaces.git/blob - chase.c
got rid of buildnumber.c and buildnum program, now uses builddate.c (touched each...
[divverent/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 = {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"};
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 int traceline_endcontents;
42
43 static entity_render_t *traceline_entity[MAX_EDICTS];
44 static int traceline_entities;
45
46 // builds list of entities for TraceLine to check later
47 void TraceLine_ScanForBModels(void)
48 {
49         int i;
50         entity_render_t *ent;
51         model_t *model;
52         traceline_entities = 0;
53         for (i = 1;i < MAX_EDICTS;i++)
54         {
55                 ent = &cl_entities[i].render;
56                 model = ent->model;
57                 // look for embedded brush models only
58                 if (model && model->name[0] == '*')
59                 {
60                         // this does nothing for * models currently...
61                         //Mod_CheckLoaded(model);
62                         if (model->type == mod_brush)
63                         {
64                                 traceline_entity[traceline_entities++] = ent;
65                                 if (ent->angles[0] || ent->angles[2])
66                                 {
67                                         // pitch or roll
68                                         VectorAdd(ent->origin, model->rotatedmins, ent->mins);
69                                         VectorAdd(ent->origin, model->rotatedmaxs, ent->maxs);
70                                 }
71                                 else if (ent->angles[1])
72                                 {
73                                         // yaw
74                                         VectorAdd(ent->origin, model->yawmins, ent->mins);
75                                         VectorAdd(ent->origin, model->yawmaxs, ent->maxs);
76                                 }
77                                 else
78                                 {
79                                         VectorAdd(ent->origin, model->normalmins, ent->mins);
80                                         VectorAdd(ent->origin, model->normalmaxs, ent->maxs);
81                                 }
82                         }
83                 }
84         }
85 }
86
87 float TraceLine (vec3_t start, vec3_t end, vec3_t impact, vec3_t normal, int contents, int hitbmodels)
88 {
89         float maxfrac;
90         trace_t trace;
91
92 // FIXME: broken, fix it
93 //      if (impact == NULL && normal == NULL && contents == 0)
94 //              return SV_TestLine (cl.worldmodel->hulls, 0, start, end);
95
96         Mod_CheckLoaded(cl.worldmodel);
97         memset (&trace, 0, sizeof(trace));
98         VectorCopy (end, trace.endpos);
99         trace.fraction = 1;
100         trace.startcontents = contents;
101         VectorCopy(start, RecursiveHullCheckInfo.start);
102         VectorSubtract(end, start, RecursiveHullCheckInfo.dist);
103         RecursiveHullCheckInfo.hull = cl.worldmodel->hulls;
104         RecursiveHullCheckInfo.trace = &trace;
105         SV_RecursiveHullCheck (0, 0, 1, start, end);
106         if (impact)
107                 VectorCopy (trace.endpos, impact);
108         if (normal)
109                 VectorCopy (trace.plane.normal, normal);
110         traceline_endcontents = trace.endcontents;
111         maxfrac = trace.fraction;
112
113         if (hitbmodels && traceline_entities)
114         {
115                 int n;
116                 entity_render_t *ent;
117                 vec3_t start2, end2, tracemins, tracemaxs;
118                 tracemins[0] = min(start[0], end[0]);
119                 tracemaxs[0] = max(start[0], end[0]);
120                 tracemins[1] = min(start[1], end[1]);
121                 tracemaxs[1] = max(start[1], end[1]);
122                 tracemins[2] = min(start[2], end[2]);
123                 tracemaxs[2] = max(start[2], end[2]);
124
125                 // look for embedded bmodels
126                 for (n = 0;n < traceline_entities;n++)
127                 {
128                         ent = traceline_entity[n];
129                         if (ent->mins[0] > tracemaxs[0] || ent->maxs[0] < tracemins[0]
130                          || ent->mins[1] > tracemaxs[1] || ent->maxs[1] < tracemins[1]
131                          || ent->mins[2] > tracemaxs[2] || ent->maxs[2] < tracemins[2])
132                                 continue;
133
134                         softwaretransformforentity(ent);
135                         softwareuntransform(start, start2);
136                         softwareuntransform(end, end2);
137
138                         memset (&trace, 0, sizeof(trace));
139                         VectorCopy (end2, trace.endpos);
140                         trace.fraction = 1;
141                         trace.startcontents = contents;
142                         VectorCopy(start2, RecursiveHullCheckInfo.start);
143                         VectorSubtract(end2, start2, RecursiveHullCheckInfo.dist);
144                         RecursiveHullCheckInfo.hull = ent->model->hulls;
145                         RecursiveHullCheckInfo.trace = &trace;
146                         SV_RecursiveHullCheck (ent->model->hulls->firstclipnode, 0, 1, start2, end2);
147
148                         if (trace.allsolid || trace.startsolid || trace.fraction < maxfrac)
149                         {
150                                 maxfrac = trace.fraction;
151                                 if (impact)
152                                 {
153                                         softwaretransform(trace.endpos, impact);
154                                 }
155                                 if (normal)
156                                 {
157                                         softwaretransformdirection(trace.plane.normal, normal);
158                                 }
159                                 traceline_endcontents = trace.endcontents;
160                         }
161                 }
162         }
163         return maxfrac;
164 }
165
166 void Chase_Update (void)
167 {
168         vec3_t  forward, stop, chase_dest, normal;
169         float   dist;
170
171         chase_back.value = bound(0, chase_back.value, 128);
172         chase_up.value = bound(-48, chase_up.value, 96);
173
174         AngleVectors (cl.viewangles, forward, NULL, NULL);
175
176         dist = -chase_back.value - 8;
177         chase_dest[0] = r_refdef.vieworg[0] + forward[0] * dist;
178         chase_dest[1] = r_refdef.vieworg[1] + forward[1] * dist;
179         chase_dest[2] = r_refdef.vieworg[2] + forward[2] * dist + chase_up.value;
180
181         TraceLine (r_refdef.vieworg, chase_dest, stop, normal, 0, true);
182         chase_dest[0] = stop[0] + forward[0] * 8 + normal[0] * 4;
183         chase_dest[1] = stop[1] + forward[1] * 8 + normal[1] * 4;
184         chase_dest[2] = stop[2] + forward[2] * 8 + normal[2] * 4;
185
186         VectorCopy (chase_dest, r_refdef.vieworg);
187 }
188