- {
- if (t2 < 0)
- {
- num = node->children[1];
- goto loc0;
- }
- // put the crosspoint DIST_EPSILON pixels on the near side
- side = 1;
- }
-
- frac = t1 / (t1 - t2);
- frac = bound(0.0f, frac, 1.0);
-
- midf = p1f + ((p2f - p1f) * frac);
- mid[0] = RHC.start[0] + midf * RHC.dist[0];
- mid[1] = RHC.start[1] + midf * RHC.dist[1];
- mid[2] = RHC.start[2] + midf * RHC.dist[2];
-
- // front side first
- ret = SV_RecursiveHullCheck (node->children[side], p1f, midf, p1, mid);
- if (ret != HULLCHECKSTATE_EMPTY)
- return ret; // solid or done
- ret = SV_RecursiveHullCheck (node->children[!side], midf, p2f, mid, p2);
- if (ret != HULLCHECKSTATE_SOLID)
- return ret; // empty or done
-
- // front is air and back is solid, this is the impact point...
- SV_RecursiveHullCheck_Impact(RHC.hull->planes + node->planenum, side);
-
- return HULLCHECKSTATE_DONE;
-}
-
-/*
-==================
-SV_ClipMoveToEntity
-
-Handles selection or creation of a clipping hull, and offseting (and
-eventually rotation) of the end points
-==================
-*/
-trace_t SV_ClipMoveToEntity (edict_t *ent, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)
-{
- trace_t trace;
- vec3_t offset, forward, left, up;
- double startd[3], endd[3], tempd[3];
- hull_t *hull;
-
-// fill in a default trace
- memset (&trace, 0, sizeof(trace_t));
- trace.fraction = 1;
- trace.allsolid = true;
-
-// get the clipping hull
- hull = SV_HullForEntity (ent, mins, maxs, offset);
-
- VectorSubtract(start, offset, startd);
- VectorSubtract(end, offset, endd);
-
- // rotate start and end into the models frame of reference
- if (ent->v.solid == SOLID_BSP && (ent->v.angles[0] || ent->v.angles[1] || ent->v.angles[2]))
- {
- AngleVectorsFLU (ent->v.angles, forward, left, up);
- VectorCopy(startd, tempd);
- startd[0] = DotProduct (tempd, forward);
- startd[1] = DotProduct (tempd, left);
- startd[2] = DotProduct (tempd, up);
- VectorCopy(endd, tempd);
- endd[0] = DotProduct (tempd, forward);
- endd[1] = DotProduct (tempd, left);
- endd[2] = DotProduct (tempd, up);
- }
-
- VectorCopy(end, trace.endpos);
-
-// trace a line through the appropriate clipping hull
- VectorCopy(startd, RecursiveHullCheckInfo.start);
- VectorSubtract(endd, startd, RecursiveHullCheckInfo.dist);
- RecursiveHullCheckInfo.hull = hull;
- RecursiveHullCheckInfo.trace = &trace;
- SV_RecursiveHullCheck (hull->firstclipnode, 0, 1, startd, endd);
-
- // if we hit, unrotate endpos and normal, and store the entity we hit
- if (trace.fraction != 1)
- {
- // rotate endpos back to world frame of reference
- if (ent->v.solid == SOLID_BSP && (ent->v.angles[0] || ent->v.angles[1] || ent->v.angles[2]))
- {
- VectorNegate (ent->v.angles, offset);
- AngleVectorsFLU (offset, forward, left, up);
-
- VectorCopy (trace.endpos, tempd);
- trace.endpos[0] = DotProduct (tempd, forward);
- trace.endpos[1] = DotProduct (tempd, left);
- trace.endpos[2] = DotProduct (tempd, up);
-
- VectorCopy (trace.plane.normal, tempd);
- trace.plane.normal[0] = DotProduct (tempd, forward);
- trace.plane.normal[1] = DotProduct (tempd, left);
- trace.plane.normal[2] = DotProduct (tempd, up);
- }
- // fix offset
- VectorAdd (trace.endpos, offset, trace.endpos);
- trace.ent = ent;
- }
- else if (trace.allsolid || trace.startsolid)
- trace.ent = ent;