float CL_TraceLine(const vec3_t start, const vec3_t end, vec3_t impact, vec3_t normal, int hitbmodels, entity_render_t **hitent, int hitsupercontentsmask)
{
- float maxfrac;
+ float maxfrac, maxrealfrac;
int n;
entity_render_t *ent;
float tracemins[3], tracemaxs[3];
matrix4x4_t matrix, imatrix;
float tempnormal[3], starttransformed[3], endtransformed[3];
+ memset (&trace, 0 , sizeof(trace_t));
+ trace.fraction = 1;
+ trace.realfraction = 1;
+ VectorCopy (end, trace.endpos);
+
if (hitent)
*hitent = &cl_entities[0].render;
Mod_CheckLoaded(cl.worldmodel);
if (cl.worldmodel && cl.worldmodel->TraceBox)
cl.worldmodel->TraceBox(cl.worldmodel, 0, &trace, start, start, end, end, hitsupercontentsmask);
- if (impact)
- VectorLerp(start, trace.fraction, end, impact);
if (normal)
VectorCopy(trace.plane.normal, normal);
cl_traceline_startsupercontents = trace.startsupercontents;
maxfrac = trace.fraction;
+ maxrealfrac = trace.realfraction;
if (hitbmodels && cl_num_brushmodel_entities)
{
ent->model->TraceBox(ent->model, 0, &trace, starttransformed, starttransformed, endtransformed, endtransformed, hitsupercontentsmask);
cl_traceline_startsupercontents |= trace.startsupercontents;
- if (maxfrac > trace.fraction)
+ if (maxrealfrac > trace.realfraction)
{
if (hitent)
*hitent = ent;
maxfrac = trace.fraction;
- if (impact)
- VectorLerp(start, trace.fraction, end, impact);
+ maxrealfrac = trace.realfraction;
if (normal)
{
VectorCopy(trace.plane.normal, tempnormal);
}
}
if (maxfrac < 0 || maxfrac > 1) Con_Printf("fraction out of bounds %f %s:%d\n", maxfrac, __FILE__, __LINE__);
+ if (impact)
+ VectorLerp(start, maxfrac, end, impact);
return maxfrac;
}