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, int q3surfaceflags, texture_t *texture, const vec3_t segmentmins, const vec3_t segmentmaxs)
+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 stride, float *bbox6f, int supercontents, int q3surfaceflags, texture_t *texture, const vec3_t segmentmins, const vec3_t segmentmaxs)
{
int i;
polyf_brush.numpoints = 3;
polyf_brush.planes[i].q3surfaceflags = q3surfaceflags;
polyf_brush.planes[i].texture = texture;
}
- for (i = 0;i < numtriangles;i++, element3i += 3)
+ if(stride)
{
- if (TriangleOverlapsBox(vertex3f + element3i[0]*3, vertex3f + element3i[1]*3, vertex3f + element3i[2]*3, segmentmins, segmentmaxs))
+ int k, cnt, tri;
+ cnt = (numtriangles + stride - 1) / stride;
+ for(i = 0; i < cnt; ++i)
{
- 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);
- Collision_SnapCopyPoints(polyf_brush.numpoints, polyf_points, polyf_points, COLLISION_SNAPSCALE, COLLISION_SNAP);
- Collision_CalcPlanesForPolygonBrushFloat(&polyf_brush);
- //Collision_PrintBrushAsQHull(&polyf_brush, "polyf_brush");
- Collision_TraceBrushBrushFloat(trace, thisbrush_start, thisbrush_end, &polyf_brush, &polyf_brush);
+ if(BoxesOverlap(bbox6f + i * 6, bbox6f + i * 6 + 3, segmentmins, segmentmaxs))
+ {
+ for(k = 0; k < stride; ++k)
+ {
+ tri = i * stride + k;
+ if(tri >= numtriangles)
+ break;
+ VectorCopy(vertex3f + element3i[tri * 3 + 0] * 3, polyf_points[0].v);
+ VectorCopy(vertex3f + element3i[tri * 3 + 1] * 3, polyf_points[1].v);
+ VectorCopy(vertex3f + element3i[tri * 3 + 2] * 3, polyf_points[2].v);
+ Collision_SnapCopyPoints(polyf_brush.numpoints, polyf_points, polyf_points, COLLISION_SNAPSCALE, COLLISION_SNAP);
+ Collision_CalcPlanesForPolygonBrushFloat(&polyf_brush);
+ //Collision_PrintBrushAsQHull(&polyf_brush, "polyf_brush");
+ Collision_TraceBrushBrushFloat(trace, thisbrush_start, thisbrush_end, &polyf_brush, &polyf_brush);
+ }
+ }
+ }
+ }
+ else
+ {
+ for (i = 0;i < numtriangles;i++, element3i += 3)
+ {
+ if (TriangleOverlapsBox(vertex3f + element3i[0]*3, vertex3f + element3i[1]*3, vertex3f + element3i[2]*3, segmentmins, segmentmaxs))
+ {
+ 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);
+ Collision_SnapCopyPoints(polyf_brush.numpoints, polyf_points, polyf_points, COLLISION_SNAPSCALE, COLLISION_SNAP);
+ Collision_CalcPlanesForPolygonBrushFloat(&polyf_brush);
+ //Collision_PrintBrushAsQHull(&polyf_brush, "polyf_brush");
+ Collision_TraceBrushBrushFloat(trace, thisbrush_start, thisbrush_end, &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, int q3surfaceflags, texture_t *texture, const vec3_t segmentmins, const vec3_t segmentmaxs)
+void Collision_TraceLineTriangleMeshFloat(trace_t *trace, const vec3_t linestart, const vec3_t lineend, int numtriangles, const int *element3i, const float *vertex3f, int stride, float *bbox6f, int supercontents, int q3surfaceflags, texture_t *texture, const vec3_t segmentmins, const vec3_t segmentmaxs)
{
int i;
#if 1
// FIXME: snap vertices?
- 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, supercontents, q3surfaceflags, texture);
+ if(stride)
+ {
+ int k, cnt, tri;
+ cnt = (numtriangles + stride - 1) / stride;
+ for(i = 0; i < cnt; ++i)
+ {
+ if(BoxesOverlap(bbox6f + i * 6, bbox6f + i * 6 + 3, segmentmins, segmentmaxs))
+ {
+ for(k = 0; k < stride; ++k)
+ {
+ tri = i * stride + k;
+ if(tri >= numtriangles)
+ break;
+ Collision_TraceLineTriangleFloat(trace, linestart, lineend, vertex3f + element3i[tri * 3 + 0] * 3, vertex3f + element3i[tri * 3 + 1] * 3, vertex3f + element3i[tri * 3 + 2] * 3, supercontents, q3surfaceflags, texture);
+ }
+ }
+ }
+ }
+ else
+ {
+ 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, supercontents, q3surfaceflags, texture);
+ }
#else
polyf_brush.numpoints = 3;
polyf_brush.numplanes = 5;
memset(trace, 0, sizeof(*trace));
trace->fraction = trace->realfraction = 1;
- VectorCopy(end, trace->endpos);
Matrix4x4_Transform(inversematrix, start, starttransformed);
Matrix4x4_Transform(inversematrix, end, endtransformed);
VectorLerp(start, trace->fraction, end, trace->endpos);
}
+void Collision_ClipLineToGenericEntity(trace_t *trace, dp_model_t *model, int frame, const vec3_t bodymins, const vec3_t bodymaxs, int bodysupercontents, matrix4x4_t *matrix, matrix4x4_t *inversematrix, const vec3_t start, const vec3_t end, int hitsupercontentsmask)
+{
+ float starttransformed[3], endtransformed[3];
+
+ memset(trace, 0, sizeof(*trace));
+ trace->fraction = trace->realfraction = 1;
+
+ Matrix4x4_Transform(inversematrix, start, starttransformed);
+ Matrix4x4_Transform(inversematrix, end, endtransformed);
+#if COLLISIONPARANOID >= 3
+ Con_Printf("trans(%f %f %f -> %f %f %f, %f %f %f -> %f %f %f)", start[0], start[1], start[2], starttransformed[0], starttransformed[1], starttransformed[2], end[0], end[1], end[2], endtransformed[0], endtransformed[1], endtransformed[2]);
+#endif
+
+ if (model && model->TraceLine)
+ model->TraceLine(model, bound(0, frame, (model->numframes - 1)), trace, starttransformed, endtransformed, hitsupercontentsmask);
+ else
+ Collision_ClipTrace_Box(trace, bodymins, bodymaxs, starttransformed, vec3_origin, vec3_origin, endtransformed, hitsupercontentsmask, bodysupercontents, 0, NULL);
+ trace->fraction = bound(0, trace->fraction, 1);
+ trace->realfraction = bound(0, trace->realfraction, 1);
+
+ VectorLerp(start, trace->fraction, end, trace->endpos);
+ // transform plane
+ // NOTE: this relies on plane.dist being directly after plane.normal
+ Matrix4x4_TransformPositivePlane(matrix, trace->plane.normal[0], trace->plane.normal[1], trace->plane.normal[2], trace->plane.dist, trace->plane.normal);
+}
+
+void Collision_ClipLineToWorld(trace_t *trace, dp_model_t *model, const vec3_t start, const vec3_t end, int hitsupercontents)
+{
+ memset(trace, 0, sizeof(*trace));
+ trace->fraction = trace->realfraction = 1;
+ if (model && model->TraceLine)
+ model->TraceLine(model, 0, trace, start, end, hitsupercontents);
+ trace->fraction = bound(0, trace->fraction, 1);
+ trace->realfraction = bound(0, trace->realfraction, 1);
+ VectorLerp(start, trace->fraction, end, trace->endpos);
+}
+
+void Collision_ClipPointToGenericEntity(trace_t *trace, dp_model_t *model, int frame, const vec3_t bodymins, const vec3_t bodymaxs, int bodysupercontents, matrix4x4_t *matrix, matrix4x4_t *inversematrix, const vec3_t start, int hitsupercontentsmask)
+{
+ float starttransformed[3];
+
+ memset(trace, 0, sizeof(*trace));
+ trace->fraction = trace->realfraction = 1;
+
+ Matrix4x4_Transform(inversematrix, start, starttransformed);
+#if COLLISIONPARANOID >= 3
+ Con_Printf("trans(%f %f %f -> %f %f %f)", start[0], start[1], start[2], starttransformed[0], starttransformed[1], starttransformed[2]);
+#endif
+
+ if (model && model->TracePoint)
+ model->TracePoint(model, bound(0, frame, (model->numframes - 1)), trace, starttransformed, hitsupercontentsmask);
+ else
+ Collision_ClipTrace_Point(trace, bodymins, bodymaxs, starttransformed, hitsupercontentsmask, bodysupercontents, 0, NULL);
+
+ VectorCopy(start, trace->endpos);
+ // transform plane
+ // NOTE: this relies on plane.dist being directly after plane.normal
+ Matrix4x4_TransformPositivePlane(matrix, trace->plane.normal[0], trace->plane.normal[1], trace->plane.normal[2], trace->plane.dist, trace->plane.normal);
+}
+
+void Collision_ClipPointToWorld(trace_t *trace, dp_model_t *model, const vec3_t start, int hitsupercontents)
+{
+ memset(trace, 0, sizeof(*trace));
+ trace->fraction = trace->realfraction = 1;
+ if (model && model->TracePoint)
+ model->TracePoint(model, 0, trace, start, hitsupercontents);
+ VectorCopy(start, trace->endpos);
+}
+
void Collision_CombineTraces(trace_t *cliptrace, const trace_t *trace, void *touch, qboolean isbmodel)
{
// take the 'best' answers from the new trace and combine with existing data
// cliptrace->inopen = true;
if (trace->inwater)
cliptrace->inwater = true;
- if ((trace->realfraction <= cliptrace->realfraction) && (VectorLength2(trace->plane->normal) > 0))
+ if ((trace->realfraction <= cliptrace->realfraction) && (VectorLength2(trace->plane.normal) > 0))
{
cliptrace->fraction = trace->fraction;
cliptrace->realfraction = trace->realfraction;
}
cliptrace->startsupercontents |= trace->startsupercontents;
}
+
+void Collision_ShortenTrace(trace_t *trace, float shorten_factor, const vec3_t end)
+{
+ // now undo our moving end 1 qu farther...
+ trace->fraction = bound(trace->fraction, trace->fraction / shorten_factor - 1e-6, 1); // we subtract 1e-6 to guard for roundoff errors
+ trace->realfraction = bound(trace->realfraction, trace->realfraction / shorten_factor - 1e-6, 1); // we subtract 1e-6 to guard for roundoff errors
+ if(trace->fraction >= 1) // trace would NOT hit if not expanded!
+ {
+ trace->fraction = 1;
+ trace->realfraction = 1;
+ VectorCopy(end, trace->endpos);
+ memset(&trace->plane, 0, sizeof(trace->plane));
+ trace->ent = NULL;
+ trace->hitsupercontentsmask = 0;
+ trace->hitsupercontents = 0;
+ trace->hitq3surfaceflags = 0;
+ trace->hittexture = NULL;
+ }
+}