+void Collision_TraceBrushPolygonFloat(trace_t *trace, const colbrushf_t *thisbrush_start, const colbrushf_t *thisbrush_end, int numpoints, const float *points, int supercontents)
+{
+ if (numpoints > 256)
+ {
+ Con_Printf("Polygon with more than 256 points not supported yet (fixme!)\n");
+ return;
+ }
+ polyf_brush.numpoints = numpoints;
+ polyf_brush.numplanes = numpoints + 2;
+ polyf_brush.points = (colpointf_t *)points;
+ polyf_brush.planes = polyf_planes;
+ polyf_brush.supercontents = supercontents;
+ Collision_CalcPlanesForPolygonBrushFloat(&polyf_brush);
+ //Collision_PrintBrushAsQHull(&polyf_brush, "polyf_brush");
+ Collision_TraceBrushBrushFloat(trace, thisbrush_start, thisbrush_end, &polyf_brush, &polyf_brush);
+}
+
+void Collision_TraceBrushTriangleMeshFloat(trace_t *trace, const colbrushf_t *thisbrush_start, const colbrushf_t *thisbrush_end, int numtriangles, const int *element3i, const float *vertex3f, int supercontents, const vec3_t segmentmins, const vec3_t segmentmaxs)
+{
+ int i;
+ float facemins[3], facemaxs[3];
+ polyf_brush.numpoints = 3;
+ polyf_brush.numplanes = 5;
+ polyf_brush.points = polyf_points;
+ polyf_brush.planes = polyf_planes;
+ polyf_brush.supercontents = supercontents;
+ for (i = 0;i < numtriangles;i++, element3i += 3)
+ {
+ VectorCopy(vertex3f + element3i[0] * 3, polyf_points[0].v);
+ VectorCopy(vertex3f + element3i[1] * 3, polyf_points[1].v);
+ VectorCopy(vertex3f + element3i[2] * 3, polyf_points[2].v);
+ facemins[0] = min(polyf_points[0].v[0], min(polyf_points[1].v[0], polyf_points[2].v[0]));
+ facemins[1] = min(polyf_points[0].v[1], min(polyf_points[1].v[1], polyf_points[2].v[1]));
+ facemins[2] = min(polyf_points[0].v[2], min(polyf_points[1].v[2], polyf_points[2].v[2]));
+ facemaxs[0] = max(polyf_points[0].v[0], max(polyf_points[1].v[0], polyf_points[2].v[0]));
+ facemaxs[1] = max(polyf_points[0].v[1], max(polyf_points[1].v[1], polyf_points[2].v[1]));
+ facemaxs[2] = max(polyf_points[0].v[2], max(polyf_points[1].v[2], polyf_points[2].v[2]));
+ if (BoxesOverlap(segmentmins, segmentmaxs, facemins, facemaxs))
+ {
+ Collision_CalcPlanesForPolygonBrushFloat(&polyf_brush);
+ //Collision_PrintBrushAsQHull(&polyf_brush, "polyf_brush");
+ Collision_TraceBrushBrushFloat(trace, thisbrush_start, thisbrush_end, &polyf_brush, &polyf_brush);
+ }
+ }
+}
+
+void Collision_TraceLinePolygonFloat(trace_t *trace, const vec3_t linestart, const vec3_t lineend, int numpoints, const float *points, int supercontents)
+{
+ if (numpoints > 256)
+ {
+ Con_Printf("Polygon with more than 256 points not supported yet (fixme!)\n");
+ return;
+ }
+ polyf_brush.numpoints = numpoints;
+ polyf_brush.numplanes = numpoints + 2;
+ polyf_brush.points = (colpointf_t *)points;
+ polyf_brush.planes = polyf_planes;
+ polyf_brush.supercontents = supercontents;
+ Collision_CalcPlanesForPolygonBrushFloat(&polyf_brush);
+ //Collision_PrintBrushAsQHull(&polyf_brush, "polyf_brush");
+ Collision_TraceLineBrushFloat(trace, linestart, lineend, &polyf_brush, &polyf_brush);
+}
+
+void Collision_TraceLineTriangleMeshFloat(trace_t *trace, const vec3_t linestart, const vec3_t lineend, int numtriangles, const int *element3i, const float *vertex3f, int supercontents, const vec3_t segmentmins, const vec3_t segmentmaxs)
+{
+ int i;
+#if 1
+ for (i = 0;i < numtriangles;i++, element3i += 3)
+ Collision_TraceLineTriangleFloat(trace, linestart, lineend, vertex3f + element3i[0] * 3, vertex3f + element3i[1] * 3, vertex3f + element3i[2] * 3);
+#else
+ polyf_brush.numpoints = 3;
+ polyf_brush.numplanes = 5;
+ polyf_brush.points = polyf_points;
+ polyf_brush.planes = polyf_planes;
+ polyf_brush.supercontents = supercontents;
+ for (i = 0;i < numtriangles;i++, element3i += 3)
+ {
+ float facemins[3], facemaxs[3];
+ VectorCopy(vertex3f + element3i[0] * 3, polyf_points[0].v);
+ VectorCopy(vertex3f + element3i[1] * 3, polyf_points[1].v);
+ VectorCopy(vertex3f + element3i[2] * 3, polyf_points[2].v);
+ facemins[0] = min(polyf_points[0].v[0], min(polyf_points[1].v[0], polyf_points[2].v[0]));
+ facemins[1] = min(polyf_points[0].v[1], min(polyf_points[1].v[1], polyf_points[2].v[1]));
+ facemins[2] = min(polyf_points[0].v[2], min(polyf_points[1].v[2], polyf_points[2].v[2]));
+ facemaxs[0] = max(polyf_points[0].v[0], max(polyf_points[1].v[0], polyf_points[2].v[0]));
+ facemaxs[1] = max(polyf_points[0].v[1], max(polyf_points[1].v[1], polyf_points[2].v[1]));
+ facemaxs[2] = max(polyf_points[0].v[2], max(polyf_points[1].v[2], polyf_points[2].v[2]));
+ if (BoxesOverlap(segmentmins, segmentmaxs, facemins, facemaxs))
+ {
+ Collision_CalcPlanesForPolygonBrushFloat(&polyf_brush);
+ //Collision_PrintBrushAsQHull(&polyf_brush, "polyf_brush");
+ Collision_TraceLineBrushFloat(trace, linestart, lineend, &polyf_brush, &polyf_brush);
+ }
+ }
+#endif
+}
+
+
+static colpointf_t polyf_pointsstart[256], polyf_pointsend[256];
+static colplanef_t polyf_planesstart[256 + 2], polyf_planesend[256 + 2];
+static colbrushf_t polyf_brushstart, polyf_brushend;
+
+void Collision_TraceBrushPolygonTransformFloat(trace_t *trace, const colbrushf_t *thisbrush_start, const colbrushf_t *thisbrush_end, int numpoints, const float *points, const matrix4x4_t *polygonmatrixstart, const matrix4x4_t *polygonmatrixend, int supercontents)
+{
+ int i;
+ if (numpoints > 256)
+ {
+ Con_Printf("Polygon with more than 256 points not supported yet (fixme!)\n");
+ return;
+ }
+ polyf_brushstart.numpoints = numpoints;
+ polyf_brushstart.numplanes = numpoints + 2;
+ polyf_brushstart.points = polyf_pointsstart;//(colpointf_t *)points;
+ polyf_brushstart.planes = polyf_planesstart;
+ polyf_brushstart.supercontents = supercontents;
+ for (i = 0;i < numpoints;i++)
+ Matrix4x4_Transform(polygonmatrixstart, points + i * 3, polyf_brushstart.points[i].v);
+ polyf_brushend.numpoints = numpoints;
+ polyf_brushend.numplanes = numpoints + 2;
+ polyf_brushend.points = polyf_pointsend;//(colpointf_t *)points;
+ polyf_brushend.planes = polyf_planesend;
+ polyf_brushend.supercontents = supercontents;
+ for (i = 0;i < numpoints;i++)
+ Matrix4x4_Transform(polygonmatrixend, points + i * 3, polyf_brushend.points[i].v);
+ Collision_CalcPlanesForPolygonBrushFloat(&polyf_brushstart);
+ Collision_CalcPlanesForPolygonBrushFloat(&polyf_brushend);
+
+ //Collision_PrintBrushAsQHull(&polyf_brushstart, "polyf_brushstart");
+ //Collision_PrintBrushAsQHull(&polyf_brushend, "polyf_brushend");
+
+ Collision_TraceBrushBrushFloat(trace, thisbrush_start, thisbrush_end, &polyf_brushstart, &polyf_brushend);
+}
+
+
+
+#define MAX_BRUSHFORBOX 16
+static int brushforbox_index = 0;
+static colpointf_t brushforbox_point[MAX_BRUSHFORBOX*8];
+static colplanef_t brushforbox_plane[MAX_BRUSHFORBOX*6];
+static colbrushf_t brushforbox_brush[MAX_BRUSHFORBOX];
+static colbrushf_t brushforpoint_brush[MAX_BRUSHFORBOX];
+
+void Collision_InitBrushForBox(void)
+{
+ int i;
+ for (i = 0;i < MAX_BRUSHFORBOX;i++)
+ {
+ brushforbox_brush[i].supercontents = SUPERCONTENTS_SOLID;
+ brushforbox_brush[i].numpoints = 8;
+ brushforbox_brush[i].numplanes = 6;
+ brushforbox_brush[i].points = brushforbox_point + i * 8;
+ brushforbox_brush[i].planes = brushforbox_plane + i * 6;
+ brushforpoint_brush[i].supercontents = SUPERCONTENTS_SOLID;
+ brushforpoint_brush[i].numpoints = 1;
+ brushforpoint_brush[i].numplanes = 0;
+ brushforpoint_brush[i].points = brushforbox_point + i * 8;
+ brushforpoint_brush[i].planes = brushforbox_plane + i * 6;
+ }
+}