6 typedef struct physentity_s
8 // this may be a entity_t, or a edict_t, or whatever
11 // can be NULL if it is a bbox object
14 // node this entity crosses
15 // for avoiding unnecessary collisions
18 // matrix for converting from model to world coordinates
19 double modeltoworldmatrix[3][4];
21 // matrix for converting from world to model coordinates
22 double worldtomodelmatrix[3][4];
24 // if this is a bmodel, this is used for culling it quickly
25 // if this is not a bmodel, this is used for actual collisions
26 double mins[3], maxs[3];
31 int cl_traceline_endcontents;
33 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)
40 Mod_CheckLoaded(cl.worldmodel);
41 Collision_ClipTrace(&trace, NULL, cl.worldmodel, vec3_origin, vec3_origin, vec3_origin, vec3_origin, start, vec3_origin, vec3_origin, end);
44 VectorCopy (trace.endpos, impact);
46 VectorCopy (trace.plane.normal, normal);
47 cl_traceline_endcontents = trace.endcontents;
48 maxfrac = trace.fraction;
49 if (hitent && trace.fraction < 1)
50 *hitent = &cl_entities[0].render;
52 if (hitbmodels && cl_num_brushmodel_entities)
56 double tracemins[3], tracemaxs[3];
57 tracemins[0] = min(start[0], end[0]);
58 tracemaxs[0] = max(start[0], end[0]);
59 tracemins[1] = min(start[1], end[1]);
60 tracemaxs[1] = max(start[1], end[1]);
61 tracemins[2] = min(start[2], end[2]);
62 tracemaxs[2] = max(start[2], end[2]);
64 // look for embedded bmodels
65 for (n = 0;n < cl_num_brushmodel_entities;n++)
67 ent = cl_brushmodel_entities[n];
68 if (ent->mins[0] > tracemaxs[0] || ent->maxs[0] < tracemins[0]
69 || ent->mins[1] > tracemaxs[1] || ent->maxs[1] < tracemins[1]
70 || ent->mins[2] > tracemaxs[2] || ent->maxs[2] < tracemins[2])
73 Collision_ClipTrace(&trace, ent, ent->model, ent->origin, ent->angles, ent->mins, ent->maxs, start, vec3_origin, vec3_origin, end);
75 if (trace.allsolid || trace.startsolid || trace.fraction < maxfrac)
77 maxfrac = trace.fraction;
79 VectorCopy(trace.endpos, impact);
81 VectorCopy(trace.plane.normal, normal);
82 cl_traceline_endcontents = trace.endcontents;