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 static entity_render_t *traceline_entity[MAX_EDICTS];
32 static int traceline_entities;
34 // builds list of entities for TraceLine to check later
35 void CL_TraceLine_ScanForBModels(void)
40 traceline_entities = 0;
41 for (i = 1;i < MAX_EDICTS;i++)
43 ent = &cl_entities[i].render;
45 // look for embedded brush models only
46 if (model && model->name[0] == '*')
48 if (model->type == mod_brush)
50 traceline_entity[traceline_entities++] = ent;
51 if (ent->angles[0] || ent->angles[2])
54 VectorAdd(ent->origin, model->rotatedmins, ent->mins);
55 VectorAdd(ent->origin, model->rotatedmaxs, ent->maxs);
57 else if (ent->angles[1])
60 VectorAdd(ent->origin, model->yawmins, ent->mins);
61 VectorAdd(ent->origin, model->yawmaxs, ent->maxs);
65 VectorAdd(ent->origin, model->normalmins, ent->mins);
66 VectorAdd(ent->origin, model->normalmaxs, ent->maxs);
73 int cl_traceline_endcontents;
75 float CL_TraceLine (vec3_t start, vec3_t end, vec3_t impact, vec3_t normal, int contents, int hitbmodels)
80 Mod_CheckLoaded(cl.worldmodel);
81 Collision_ClipTrace(&trace, NULL, cl.worldmodel, vec3_origin, vec3_origin, vec3_origin, vec3_origin, start, vec3_origin, vec3_origin, end);
84 VectorCopy (trace.endpos, impact);
86 VectorCopy (trace.plane.normal, normal);
87 cl_traceline_endcontents = trace.endcontents;
88 maxfrac = trace.fraction;
90 if (hitbmodels && traceline_entities)
94 double tracemins[3], tracemaxs[3];
95 tracemins[0] = min(start[0], end[0]);
96 tracemaxs[0] = max(start[0], end[0]);
97 tracemins[1] = min(start[1], end[1]);
98 tracemaxs[1] = max(start[1], end[1]);
99 tracemins[2] = min(start[2], end[2]);
100 tracemaxs[2] = max(start[2], end[2]);
102 // look for embedded bmodels
103 for (n = 0;n < traceline_entities;n++)
105 ent = traceline_entity[n];
106 if (ent->mins[0] > tracemaxs[0] || ent->maxs[0] < tracemins[0]
107 || ent->mins[1] > tracemaxs[1] || ent->maxs[1] < tracemins[1]
108 || ent->mins[2] > tracemaxs[2] || ent->maxs[2] < tracemins[2])
111 Collision_ClipTrace(&trace, ent, ent->model, ent->origin, ent->angles, ent->mins, ent->maxs, start, vec3_origin, vec3_origin, end);
113 if (trace.allsolid || trace.startsolid || trace.fraction < maxfrac)
115 maxfrac = trace.fraction;
117 VectorCopy(trace.endpos, impact);
119 VectorCopy(trace.plane.normal, normal);
120 cl_traceline_endcontents = trace.endcontents;