3 #include "cl_collision.h"
7 typedef struct physentity_s
9 // this may be a entity_t, or a edict_t, or whatever
12 // can be NULL if it is a bbox object
15 // node this entity crosses
16 // for avoiding unnecessary collisions
19 // matrix for converting from model to world coordinates
20 double modeltoworldmatrix[3][4];
22 // matrix for converting from world to model coordinates
23 double worldtomodelmatrix[3][4];
25 // if this is a bmodel, this is used for culling it quickly
26 // if this is not a bmodel, this is used for actual collisions
27 double mins[3], maxs[3];
32 int cl_traceline_endcontents;
34 float CL_TraceLine (const vec3_t start, const vec3_t end, vec3_t impact, vec3_t normal, int contents, int hitbmodels, entity_render_t **hitent)
39 float tracemins[3], tracemaxs[3];
44 Mod_CheckLoaded(cl.worldmodel);
45 if (cl.worldmodel && cl.worldmodel->brush.TraceBox)
46 cl.worldmodel->brush.TraceBox(cl.worldmodel, vec3_origin, vec3_origin, &trace, NULL, start, vec3_origin, vec3_origin, end);
48 Collision_ClipTrace(&trace, NULL, cl.worldmodel, vec3_origin, vec3_origin, vec3_origin, vec3_origin, start, vec3_origin, vec3_origin, end);
51 VectorCopy (trace.endpos, impact);
53 VectorCopy (trace.plane.normal, normal);
54 cl_traceline_endcontents = trace.endcontents;
55 maxfrac = trace.fraction;
56 if (hitent && trace.fraction < 1)
57 *hitent = &cl_entities[0].render;
59 if (hitbmodels && cl_num_brushmodel_entities)
61 tracemins[0] = min(start[0], end[0]);
62 tracemaxs[0] = max(start[0], end[0]);
63 tracemins[1] = min(start[1], end[1]);
64 tracemaxs[1] = max(start[1], end[1]);
65 tracemins[2] = min(start[2], end[2]);
66 tracemaxs[2] = max(start[2], end[2]);
68 // look for embedded bmodels
69 for (n = 0;n < cl_num_brushmodel_entities;n++)
71 ent = cl_brushmodel_entities[n];
72 if (ent->mins[0] > tracemaxs[0] || ent->maxs[0] < tracemins[0]
73 || ent->mins[1] > tracemaxs[1] || ent->maxs[1] < tracemins[1]
74 || ent->mins[2] > tracemaxs[2] || ent->maxs[2] < tracemins[2])
77 if (ent->model && ent->model->brush.TraceBox)
78 ent->model->brush.TraceBox(ent->model, ent->origin, ent->angles, &trace, NULL, start, vec3_origin, vec3_origin, end);
80 Collision_ClipTrace(&trace, ent, ent->model, ent->origin, ent->angles, ent->mins, ent->maxs, start, vec3_origin, vec3_origin, end);
82 if (trace.allsolid || trace.startsolid || trace.fraction < maxfrac)
84 maxfrac = trace.fraction;
86 VectorCopy(trace.endpos, impact);
88 VectorCopy(trace.plane.normal, normal);
89 cl_traceline_endcontents = trace.endcontents;
95 if (maxfrac < 0 || maxfrac > 1) Con_Printf("fraction out of bounds %f %s:%d\n", maxfrac, __LINE__, __FILE__);
99 void CL_FindNonSolidLocation(const vec3_t in, vec3_t out, vec_t radius)
101 // FIXME: check multiple brush models
102 if (cl.worldmodel && cl.worldmodel->brush.FindNonSolidLocation)
103 cl.worldmodel->brush.FindNonSolidLocation(cl.worldmodel, in, out, radius);
106 int CL_PointContents(const vec3_t p)
108 // FIXME: check multiple brush models
109 if (cl.worldmodel && cl.worldmodel->brush.PointContents)
110 return cl.worldmodel->brush.PointContents(cl.worldmodel, p);
111 return CONTENTS_EMPTY;