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 static entity_render_t *traceline_entity[MAX_EDICTS];
44 static int traceline_entities;
46 // builds list of entities for TraceLine to check later
47 void TraceLine_ScanForBModels(void)
52 traceline_entities = 0;
53 for (i = 1;i < MAX_EDICTS;i++)
55 ent = &cl_entities[i].render;
57 // look for embedded brush models only
58 if (model && model->name[0] == '*')
60 // this does nothing for * models currently...
61 //Mod_CheckLoaded(model);
62 if (model->type == mod_brush)
64 traceline_entity[traceline_entities++] = ent;
65 if (ent->angles[0] || ent->angles[2])
68 VectorAdd(ent->origin, model->rotatedmins, ent->mins);
69 VectorAdd(ent->origin, model->rotatedmaxs, ent->maxs);
71 else if (ent->angles[1])
74 VectorAdd(ent->origin, model->yawmins, ent->mins);
75 VectorAdd(ent->origin, model->yawmaxs, ent->maxs);
79 VectorAdd(ent->origin, model->normalmins, ent->mins);
80 VectorAdd(ent->origin, model->normalmaxs, ent->maxs);
87 float TraceLine (vec3_t start, vec3_t end, vec3_t impact, vec3_t normal, int contents, int hitbmodels)
92 // FIXME: broken, fix it
93 // if (impact == NULL && normal == NULL && contents == 0)
94 // return SV_TestLine (cl.worldmodel->hulls, 0, start, end);
96 Mod_CheckLoaded(cl.worldmodel);
97 memset (&trace, 0, sizeof(trace));
98 VectorCopy (end, trace.endpos);
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);
107 VectorCopy (trace.endpos, impact);
109 VectorCopy (trace.plane.normal, normal);
110 traceline_endcontents = trace.endcontents;
111 maxfrac = trace.fraction;
113 if (hitbmodels && traceline_entities)
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]);
125 // look for embedded bmodels
126 for (n = 0;n < traceline_entities;n++)
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])
134 softwaretransformforentity(ent);
135 softwareuntransform(start, start2);
136 softwareuntransform(end, end2);
138 memset (&trace, 0, sizeof(trace));
139 VectorCopy (end2, trace.endpos);
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);
148 if (trace.allsolid || trace.startsolid || trace.fraction < maxfrac)
150 maxfrac = trace.fraction;
153 softwaretransform(trace.endpos, impact);
157 softwaretransformdirection(trace.plane.normal, normal);
159 traceline_endcontents = trace.endcontents;
166 void Chase_Update (void)
168 vec3_t forward, stop, chase_dest, normal;
171 chase_back.value = bound(0, chase_back.value, 128);
172 chase_up.value = bound(-48, chase_up.value, 96);
174 AngleVectors (cl.viewangles, forward, NULL, NULL);
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;
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;
186 VectorCopy (chase_dest, r_refdef.vieworg);