+// LordHavoc: FIXME: this is not thread safe, if threading matters here, pass
+// this as a struct to RecursiveHullCheck, RecursiveHullCheck_Impact, etc...
+RecursiveHullCheckTraceInfo_t RecursiveHullCheckInfo;
+#define RHC RecursiveHullCheckInfo
+
+void SV_RecursiveHullCheck_Impact (mplane_t *plane, int side)
+{
+ // LordHavoc: using doubles for extra accuracy
+ double t1, t2, frac;
+
+ // LordHavoc: now that we have found the impact, recalculate the impact
+ // point from scratch for maximum accuracy, with an epsilon bias on the
+ // surface distance
+ frac = plane->dist;
+ if (side)
+ {
+ frac -= DIST_EPSILON;
+ VectorNegate (plane->normal, RHC.trace->plane.normal);
+ RHC.trace->plane.dist = -plane->dist;
+ }
+ else
+ {
+ frac += DIST_EPSILON;
+ VectorCopy (plane->normal, RHC.trace->plane.normal);
+ RHC.trace->plane.dist = plane->dist;
+ }
+
+ if (plane->type < 3)
+ {
+ t1 = RHC.start[plane->type] - frac;
+ t2 = RHC.start[plane->type] + RHC.dist[plane->type] - frac;
+ }
+ else
+ {
+ t1 = plane->normal[0] * RHC.start[0] + plane->normal[1] * RHC.start[1] + plane->normal[2] * RHC.start[2] - frac;
+ t2 = plane->normal[0] * (RHC.start[0] + RHC.dist[0]) + plane->normal[1] * (RHC.start[1] + RHC.dist[1]) + plane->normal[2] * (RHC.start[2] + RHC.dist[2]) - frac;
+ }
+
+ frac = t1 / (t1 - t2);
+ frac = bound(0.0f, frac, 1.0f);
+
+ RHC.trace->fraction = frac;
+ RHC.trace->endpos[0] = RHC.start[0] + frac * RHC.dist[0];
+ RHC.trace->endpos[1] = RHC.start[1] + frac * RHC.dist[1];
+ RHC.trace->endpos[2] = RHC.start[2] + frac * RHC.dist[2];
+}
+
+int SV_RecursiveHullCheck (int num, float p1f, float p2f, vec3_t p1, vec3_t p2)