if (hitent)
*hitent = cl.brushmodel_entities[n];
Matrix4x4_Transform3x3(&ent->matrix, trace.plane.normal, cliptrace.plane.normal);
+ cliptrace.hitsupercontents = trace.hitsupercontents;
+ cliptrace.hitq3surfaceflags = trace.hitq3surfaceflags;
+ cliptrace.hittexture = trace.hittexture;
}
cliptrace.startsupercontents |= trace.startsupercontents;
}
if (hitent)
*hitent = n;
Matrix4x4_Transform3x3(&ent->matrix, trace.plane.normal, cliptrace.plane.normal);
+ cliptrace.hitsupercontents = trace.hitsupercontents;
+ cliptrace.hitq3surfaceflags = trace.hitq3surfaceflags;
+ cliptrace.hittexture = trace.hittexture;
}
cliptrace.startsupercontents |= trace.startsupercontents;
}
{
VectorRandom(org2);
VectorMA(org, maxdist, org2, org2);
- trace = CL_TraceBox(org, vec3_origin, vec3_origin, org2, true, &hitent, SUPERCONTENTS_SOLID, false);
- if (bestfrac > trace.fraction)
+ trace = CL_TraceBox(org, vec3_origin, vec3_origin, org2, true, &hitent, SUPERCONTENTS_SOLID | SUPERCONTENTS_SKY, false);
+ // take the closest trace result that doesn't end up hitting a NOMARKS
+ // surface (sky for example)
+ if (bestfrac > trace.fraction && !(trace.hitq3surfaceflags & Q3SURFACEFLAG_NOMARKS))
{
bestfrac = trace.fraction;
besthitent = hitent;
VectorCopy(p->org, org);
if (p->bounce)
{
- if (p->type == particletype + pt_rain)
+ trace = CL_TraceBox(oldorg, vec3_origin, vec3_origin, p->org, true, &hitent, SUPERCONTENTS_SOLID | (p->type == particletype + pt_rain ? SUPERCONTENTS_LIQUIDSMASK : 0), false);
+ // if the trace started in or hit something of SUPERCONTENTS_NODROP
+ // or if the trace hit something flagged as NOIMPACT
+ // then remove the particle
+ if (trace.hitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT || ((trace.startsupercontents | trace.hitsupercontents) & SUPERCONTENTS_NODROP))
{
- // raindrop - splash on solid/water/slime/lava
- trace = CL_TraceBox(oldorg, vec3_origin, vec3_origin, p->org, true, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_LIQUIDSMASK, false);
- if (trace.fraction < 1)
+ p->type = NULL;
+ continue;
+ }
+ // react if the particle hit something
+ if (trace.fraction < 1)
+ {
+ VectorCopy(trace.endpos, p->org);
+ if (p->type == particletype + pt_rain)
{
+ // raindrop - splash on solid/water/slime/lava
int count;
// convert from a raindrop particle to a rainsplash decal
- VectorCopy(trace.endpos, p->org);
VectorCopy(trace.plane.normal, p->vel);
VectorAdd(p->org, p->vel, p->org);
p->type = particletype + pt_raindecal;
while(count--)
particle(particletype + pt_spark, 0x000000, 0x707070, tex_particle, 0.25f, lhrandom(64, 255), 512, 1, 0, p->org[0], p->org[1], p->org[2], p->vel[0]*16, p->vel[1]*16, 32 + p->vel[2]*16, 0, 0, 32);
}
- }
- else if (p->type == particletype + pt_blood)
- {
- // blood - splash on solid
- trace = CL_TraceBox(oldorg, vec3_origin, vec3_origin, p->org, true, &hitent, SUPERCONTENTS_SOLID, false);
- if (trace.fraction < 1)
+ else if (p->type == particletype + pt_blood)
{
- // convert from a blood particle to a blood decal
- VectorCopy(trace.endpos, p->org);
- VectorCopy(trace.plane.normal, p->vel);
- VectorAdd(p->org, p->vel, p->org);
- if (cl_stainmaps.integer)
- R_Stain(p->org, 32, 32, 16, 16, p->alpha * p->size * (1.0f / 40.0f), 192, 48, 48, p->alpha * p->size * (1.0f / 40.0f));
+ // blood - splash on solid
+ if (trace.hitq3surfaceflags & Q3SURFACEFLAG_NOMARKS)
+ {
+ p->type = NULL;
+ continue;
+ }
if (!cl_decals.integer)
{
p->type = NULL;
continue;
}
+ // convert from a blood particle to a blood decal
+ VectorCopy(trace.plane.normal, p->vel);
+ VectorAdd(p->org, p->vel, p->org);
+ if (cl_stainmaps.integer)
+ R_Stain(p->org, 32, 32, 16, 16, p->alpha * p->size * (1.0f / 40.0f), 192, 48, 48, p->alpha * p->size * (1.0f / 40.0f));
p->type = particletype + pt_decal;
p->texnum = tex_blooddecal[rand()&7];
p->gravity = 0;
p->size *= 2.0f;
}
- }
- else
- {
- trace = CL_TraceBox(oldorg, vec3_origin, vec3_origin, p->org, true, NULL, SUPERCONTENTS_SOLID, false);
- if (trace.fraction < 1)
+ else if (p->bounce < 0)
{
- VectorCopy(trace.endpos, p->org);
- if (p->bounce < 0)
- {
- p->type = NULL;
- continue;
- }
- else
- {
- dist = DotProduct(p->vel, trace.plane.normal) * -p->bounce;
- VectorMA(p->vel, dist, trace.plane.normal, p->vel);
- if (DotProduct(p->vel, p->vel) < 0.03)
- VectorClear(p->vel);
- }
+ // bounce -1 means remove on impact
+ p->type = NULL;
+ continue;
+ }
+ else
+ {
+ // anything else - bounce off solid
+ dist = DotProduct(p->vel, trace.plane.normal) * -p->bounce;
+ VectorMA(p->vel, dist, trace.plane.normal, p->vel);
+ if (DotProduct(p->vel, p->vel) < 0.03)
+ VectorClear(p->vel);
}
}
}
}
-colbrushf_t *Collision_NewBrushFromPlanes(mempool_t *mempool, int numoriginalplanes, const mplane_t *originalplanes, int supercontents)
+colbrushf_t *Collision_NewBrushFromPlanes(mempool_t *mempool, int numoriginalplanes, const colplanef_t *originalplanes)
{
+ // TODO: planesbuf could be replaced by a remapping table
int j, k, m, w;
int numpointsbuf = 0, maxpointsbuf = 256, numplanesbuf = 0, maxplanesbuf = 256, numelementsbuf = 0, maxelementsbuf = 256;
colbrushf_t *brush;
// add the new plane
VectorCopy(originalplanes[j].normal, planesbuf[numplanesbuf].normal);
planesbuf[numplanesbuf].dist = originalplanes[j].dist;
+ planesbuf[numplanesbuf].supercontents = originalplanes[j].supercontents;
+ planesbuf[numplanesbuf].q3surfaceflags = originalplanes[j].q3surfaceflags;
+ planesbuf[numplanesbuf].texture = originalplanes[j].texture;
numplanesbuf++;
}
}
// allocate the brush and copy to it
- brush = Collision_AllocBrushFloat(mempool, numpointsbuf, numplanesbuf, numelementsbuf / 3, supercontents);
+ brush = (colbrushf_t *)Mem_Alloc(mempool, sizeof(colbrushf_t) + sizeof(colpointf_t) * numpointsbuf + sizeof(colplanef_t) * numplanesbuf + sizeof(int) * numelementsbuf);
+ brush->numplanes = numplanesbuf;
+ brush->numpoints = numpointsbuf;
+ brush->numtriangles = numelementsbuf / 3;
+ brush->planes = (colplanef_t *)(brush + 1);
+ brush->points = (colpointf_t *)(brush->planes + brush->numplanes);
+ brush->elements = (int *)(brush->points + brush->numpoints);
for (j = 0;j < brush->numpoints;j++)
{
brush->points[j].v[0] = pointsbuf[j].v[0];
brush->planes[j].normal[1] = planesbuf[j].normal[1];
brush->planes[j].normal[2] = planesbuf[j].normal[2];
brush->planes[j].dist = planesbuf[j].dist;
+ brush->planes[j].supercontents = planesbuf[j].supercontents;
+ brush->planes[j].q3surfaceflags = planesbuf[j].q3surfaceflags;
+ brush->planes[j].texture = planesbuf[j].texture;
+ brush->supercontents |= brush->planes[j].supercontents;
}
for (j = 0;j < brush->numtriangles * 3;j++)
brush->elements[j] = elementsbuf[j];
-colbrushf_t *Collision_AllocBrushFloat(mempool_t *mempool, int numpoints, int numplanes, int numtriangles, int supercontents)
-{
- colbrushf_t *brush;
- brush = (colbrushf_t *)Mem_Alloc(mempool, sizeof(colbrushf_t) + sizeof(colpointf_t) * numpoints + sizeof(colplanef_t) * numplanes + sizeof(int[3]) * numtriangles);
- brush->supercontents = supercontents;
- brush->numplanes = numplanes;
- brush->numpoints = numpoints;
- brush->numtriangles = numtriangles;
- brush->planes = (colplanef_t *)(brush + 1);
- brush->points = (colpointf_t *)(brush->planes + brush->numplanes);
- brush->elements = (int *)(brush->points + brush->numpoints);
- return brush;
-}
-
void Collision_CalcPlanesForPolygonBrushFloat(colbrushf_t *brush)
{
int i;
// NOTE: start and end of each brush pair must have same numplanes/numpoints
void Collision_TraceBrushBrushFloat(trace_t *trace, const colbrushf_t *thisbrush_start, const colbrushf_t *thisbrush_end, const colbrushf_t *thatbrush_start, const colbrushf_t *thatbrush_end)
{
- int nplane, nplane2, fstartsolid, fendsolid, brushsolid;
- float enterfrac, leavefrac, d1, d2, f, imove, newimpactnormal[3], enterfrac2;
+ int nplane, nplane2, fstartsolid = true, fendsolid = true, brushsolid, hitsupercontents = 0, hitq3surfaceflags = 0;
+ float enterfrac = -1, leavefrac = 1, d1, d2, f, imove, newimpactnormal[3], enterfrac2 = -1;
const colplanef_t *startplane, *endplane;
+ texture_t *hittexture = NULL;
VectorClear(newimpactnormal);
- enterfrac = -1;
- enterfrac2 = -1;
- leavefrac = 1;
- fstartsolid = true;
- fendsolid = true;
for (nplane = 0;nplane < thatbrush_start->numplanes + thisbrush_start->numplanes;nplane++)
{
enterfrac = f;
enterfrac2 = f - collision_impactnudge.value * imove;
VectorLerp(startplane->normal, enterfrac, endplane->normal, newimpactnormal);
+ hitsupercontents = startplane->supercontents;
+ hitq3surfaceflags = startplane->q3surfaceflags;
+ hittexture = startplane->texture;
}
}
}
if (enterfrac < trace->realfraction)
{
enterfrac2 = enterfrac - collision_impactnudge.value * imove;
+ trace->hitsupercontents = thatbrush_start->planes[0].supercontents;
+ trace->hitq3surfaceflags = thatbrush_start->planes[0].q3surfaceflags;
+ trace->hittexture = thatbrush_start->planes[0].texture;
trace->realfraction = bound(0, enterfrac, 1);
trace->fraction = bound(0, enterfrac2, 1);
VectorLerp(thatbrush_start->planes[0].normal, enterfrac, thatbrush_end->planes[0].normal, trace->plane.normal);
else
#endif
{
+ trace->hitsupercontents = hitsupercontents;
+ trace->hitq3surfaceflags = hitq3surfaceflags;
+ trace->hittexture = hittexture;
trace->realfraction = bound(0, enterfrac, 1);
trace->fraction = bound(0, enterfrac2, 1);
VectorCopy(newimpactnormal, trace->plane.normal);
// NOTE: start and end brush pair must have same numplanes/numpoints
void Collision_TraceLineBrushFloat(trace_t *trace, const vec3_t linestart, const vec3_t lineend, const colbrushf_t *thatbrush_start, const colbrushf_t *thatbrush_end)
{
- int nplane, fstartsolid, fendsolid, brushsolid;
- float enterfrac, leavefrac, d1, d2, f, imove, newimpactnormal[3], enterfrac2;
+ int nplane, fstartsolid = true, fendsolid = true, brushsolid, hitsupercontents = 0, hitq3surfaceflags = 0;
+ float enterfrac = -1, leavefrac = 1, d1, d2, f, imove, newimpactnormal[3], enterfrac2 = -1;
const colplanef_t *startplane, *endplane;
+ texture_t *hittexture = NULL;
VectorClear(newimpactnormal);
- enterfrac = -1;
- enterfrac2 = -1;
- leavefrac = 1;
- fstartsolid = true;
- fendsolid = true;
for (nplane = 0;nplane < thatbrush_start->numplanes;nplane++)
{
enterfrac = f;
enterfrac2 = f - collision_impactnudge.value * imove;
VectorLerp(startplane->normal, enterfrac, endplane->normal, newimpactnormal);
+ hitsupercontents = startplane->supercontents;
+ hitq3surfaceflags = startplane->q3surfaceflags;
+ hittexture = startplane->texture;
}
}
}
if (enterfrac < trace->realfraction)
{
enterfrac2 = enterfrac - collision_impactnudge.value * imove;
+ trace->hitsupercontents = hitsupercontents;
+ trace->hitq3surfaceflags = hitq3surfaceflags;
+ trace->hittexture = hittexture;
trace->realfraction = bound(0, enterfrac, 1);
trace->fraction = bound(0, enterfrac2, 1);
VectorLerp(thatbrush_start->planes[0].normal, enterfrac, thatbrush_end->planes[0].normal, trace->plane.normal);
else
#endif
{
+ trace->hitsupercontents = hitsupercontents;
+ trace->hitq3surfaceflags = hitq3surfaceflags;
+ trace->hittexture = hittexture;
trace->realfraction = bound(0, enterfrac, 1);
trace->fraction = bound(0, enterfrac2, 1);
VectorCopy(newimpactnormal, trace->plane.normal);
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)
+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)
{
int i;
float facemins[3], facemaxs[3];
polyf_brush.points = polyf_points;
polyf_brush.planes = polyf_planes;
polyf_brush.supercontents = supercontents;
+ for (i = 0;i < polyf_brush.numplanes;i++)
+ {
+ polyf_brush.planes[i].supercontents = supercontents;
+ polyf_brush.planes[i].q3surfaceflags = q3surfaceflags;
+ polyf_brush.planes[i].texture = texture;
+ }
for (i = 0;i < numtriangles;i++, element3i += 3)
{
VectorCopy(vertex3f + element3i[0] * 3, polyf_points[0].v);
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)
+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)
{
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);
+ 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;
polyf_brush.points = polyf_points;
polyf_brush.planes = polyf_planes;
polyf_brush.supercontents = supercontents;
+ for (i = 0;i < polyf_brush.numplanes;i++)
+ {
+ polyf_brush.planes[i].supercontents = supercontents;
+ polyf_brush.planes[i].q3surfaceflags = q3surfaceflags;
+ polyf_brush.planes[i].texture = texture;
+ }
for (i = 0;i < numtriangles;i++, element3i += 3)
{
float facemins[3], facemaxs[3];
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)
+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 q3surfaceflags, texture_t *texture)
{
int i;
if (numpoints > 256)
polyf_brushend.supercontents = supercontents;
for (i = 0;i < numpoints;i++)
Matrix4x4_Transform(polygonmatrixend, points + i * 3, polyf_brushend.points[i].v);
+ for (i = 0;i < polyf_brushstart.numplanes;i++)
+ {
+ polyf_brushstart.planes[i].supercontents = supercontents;
+ polyf_brushstart.planes[i].q3surfaceflags = q3surfaceflags;
+ polyf_brushstart.planes[i].texture = texture;
+ }
Collision_SnapCopyPoints(numpoints, polyf_pointsstart, polyf_pointsstart, COLLISION_SNAPSCALE, COLLISION_SNAP);
Collision_SnapCopyPoints(numpoints, polyf_pointsend, polyf_pointsend, COLLISION_SNAPSCALE, COLLISION_SNAP);
Collision_CalcPlanesForPolygonBrushFloat(&polyf_brushstart);
}
}
-colbrushf_t *Collision_BrushForBox(const matrix4x4_t *matrix, const vec3_t mins, const vec3_t maxs)
+colbrushf_t *Collision_BrushForBox(const matrix4x4_t *matrix, const vec3_t mins, const vec3_t maxs, int supercontents, int q3surfaceflags, texture_t *texture)
{
int i, j;
vec3_t v;
VectorNormalize(brush->planes[i].normal);
}
}
+ brush->supercontents = supercontents;
for (j = 0;j < brush->numplanes;j++)
+ {
+ brush->planes[j].supercontents = supercontents;
+ brush->planes[j].q3surfaceflags = q3surfaceflags;
+ brush->planes[j].texture = texture;
brush->planes[j].dist = furthestplanedist_float(brush->planes[j].normal, brush->points, brush->numpoints);
+ }
VectorCopy(brush->points[0].v, brush->mins);
VectorCopy(brush->points[0].v, brush->maxs);
for (j = 1;j < brush->numpoints;j++)
return brush;
}
-void Collision_ClipTrace_BrushBox(trace_t *trace, const vec3_t cmins, const vec3_t cmaxs, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int hitsupercontentsmask)
+void Collision_ClipTrace_BrushBox(trace_t *trace, const vec3_t cmins, const vec3_t cmaxs, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int hitsupercontentsmask, int supercontents, int q3surfaceflags, texture_t *texture)
{
colbrushf_t *boxbrush, *thisbrush_start, *thisbrush_end;
vec3_t startmins, startmaxs, endmins, endmaxs;
VectorAdd(start, maxs, startmaxs);
VectorAdd(end, mins, endmins);
VectorAdd(end, maxs, endmaxs);
- boxbrush = Collision_BrushForBox(&identitymatrix, cmins, cmaxs);
- thisbrush_start = Collision_BrushForBox(&identitymatrix, startmins, startmaxs);
- thisbrush_end = Collision_BrushForBox(&identitymatrix, endmins, endmaxs);
+ boxbrush = Collision_BrushForBox(&identitymatrix, cmins, cmaxs, supercontents, q3surfaceflags, texture);
+ thisbrush_start = Collision_BrushForBox(&identitymatrix, startmins, startmaxs, 0, 0, NULL);
+ thisbrush_end = Collision_BrushForBox(&identitymatrix, endmins, endmaxs, 0, 0, NULL);
memset(trace, 0, sizeof(trace_t));
trace->hitsupercontentsmask = hitsupercontentsmask;
return impactdist / linelength;
}
-void Collision_TraceLineTriangleFloat(trace_t *trace, const vec3_t linestart, const vec3_t lineend, const float *point0, const float *point1, const float *point2)
+void Collision_TraceLineTriangleFloat(trace_t *trace, const vec3_t linestart, const vec3_t lineend, const float *point0, const float *point1, const float *point2, int supercontents, int q3surfaceflags, texture_t *texture)
{
#if 1
// more optimized
d = 1.0 / sqrt(faceplanenormallength2);
VectorScale(faceplanenormal, d, trace->plane.normal);
trace->plane.dist = faceplanedist * d;
+
+ trace->hitsupercontents = supercontents;
+ trace->hitq3surfaceflags = q3surfaceflags;
+ trace->hittexture = texture;
#else
float d1, d2, d, f, fnudged, impact[3], edgenormal[3], faceplanenormal[3], faceplanedist, edge[3];
//trace->endpos[0] = linestart[0] + fnudged * (lineend[0] - linestart[0]);
//trace->endpos[1] = linestart[1] + fnudged * (lineend[1] - linestart[1]);
//trace->endpos[2] = linestart[2] + fnudged * (lineend[2] - linestart[2]);
+ trace->hitsupercontents = supercontents;
+ trace->hitq3surfaceflags = q3surfaceflags;
+ trace->hittexture = texture;
#endif
}
}
plane_t;
+struct texture_s;
typedef struct trace_s
{
// if true, the entire trace was in solid (see hitsupercontentsmask)
int hitsupercontentsmask;
// the supercontents mask at the start point
int startsupercontents;
+ // the supercontents of the impacted surface
+ int hitsupercontents;
+ // the q3 surfaceflags of the impacted surface
+ int hitq3surfaceflags;
+ // the texture of the impacted surface
+ struct texture_s *hittexture;
// initially false, set when the start leaf is found
// (set only by Q1BSP tracing and entity box tracing)
int startfound;
{
float normal[3];
float dist;
+ int supercontents;
+ int q3surfaceflags;
+ struct texture_s *texture;
}
colplanef_t;
}
colbrushf_t;
-colbrushf_t *Collision_AllocBrushFloat(mempool_t *mempool, int numpoints, int numplanes, int numtriangles, int supercontents);
void Collision_CalcPlanesForPolygonBrushFloat(colbrushf_t *brush);
colbrushf_t *Collision_AllocBrushFromPermanentPolygonFloat(mempool_t *mempool, int numpoints, float *points, int supercontents);
-colbrushf_t *Collision_NewBrushFromPlanes(mempool_t *mempool, int numoriginalplanes, const mplane_t *originalplanes, int supercontents);
+colbrushf_t *Collision_NewBrushFromPlanes(mempool_t *mempool, int numoriginalplanes, const colplanef_t *originalplanes);
void Collision_TraceBrushBrushFloat(trace_t *trace, const colbrushf_t *thisbrush_start, const colbrushf_t *thisbrush_end, const colbrushf_t *thatbrush_start, const colbrushf_t *thatbrush_end);
void Collision_TraceBrushPolygonFloat(trace_t *trace, const colbrushf_t *thisbrush_start, const colbrushf_t *thisbrush_end, int numpoints, const float *points, int supercontents);
-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);
+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_TraceLineBrushFloat(trace_t *trace, const vec3_t linestart, const vec3_t lineend, const colbrushf_t *thatbrush_start, const colbrushf_t *thatbrush_end);
void Collision_TraceLinePolygonFloat(trace_t *trace, const vec3_t linestart, const vec3_t lineend, int numpoints, const float *points, int supercontents);
-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);
+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_TracePointBrushFloat(trace_t *trace, const vec3_t point, const colbrushf_t *thatbrush);
-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);
+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 q3surfaceflags, texture_t *texture);
-colbrushf_t *Collision_BrushForBox(const matrix4x4_t *matrix, const vec3_t mins, const vec3_t maxs);
+colbrushf_t *Collision_BrushForBox(const matrix4x4_t *matrix, const vec3_t mins, const vec3_t maxs, int supercontents, int q3surfaceflags, texture_t *texture);
void Collision_BoundingBoxOfBrushTraceSegment(const colbrushf_t *start, const colbrushf_t *end, vec3_t mins, vec3_t maxs, float startfrac, float endfrac);
float Collision_ClipTrace_Line_Sphere(double *linestart, double *lineend, double *sphereorigin, double sphereradius, double *impactpoint, double *impactnormal);
-void Collision_TraceLineTriangleFloat(trace_t *trace, const vec3_t linestart, const vec3_t lineend, const float *point0, const float *point1, const float *point2);
+void Collision_TraceLineTriangleFloat(trace_t *trace, const vec3_t linestart, const vec3_t lineend, const float *point0, const float *point1, const float *point2, int supercontents, int q3surfaceflags, texture_t *texture);
// this enables rather large debugging spew!
// settings:
vertex3f = Z_Malloc(maxvertices * sizeof(float[3]));
}
Mod_Alias_GetMesh_Vertex3f(model, frameblend, mesh, vertex3f);
- Collision_TraceLineTriangleMeshFloat(trace, start, end, mesh->num_triangles, mesh->data_element3i, vertex3f, SUPERCONTENTS_SOLID, segmentmins, segmentmaxs);
+ Collision_TraceLineTriangleMeshFloat(trace, start, end, mesh->num_triangles, mesh->data_element3i, vertex3f, SUPERCONTENTS_SOLID, 0, surface->texture, segmentmins, segmentmaxs);
}
}
else
VectorAdd(start, boxmaxs, boxstartmaxs);
VectorAdd(end, boxmins, boxendmins);
VectorAdd(end, boxmaxs, boxendmaxs);
- thisbrush_start = Collision_BrushForBox(&identitymatrix, boxstartmins, boxstartmaxs);
- thisbrush_end = Collision_BrushForBox(&identitymatrix, boxendmins, boxendmaxs);
+ thisbrush_start = Collision_BrushForBox(&identitymatrix, boxstartmins, boxstartmaxs, 0, 0, NULL);
+ thisbrush_end = Collision_BrushForBox(&identitymatrix, boxendmins, boxendmaxs, 0, 0, NULL);
for (i = 0, surface = model->data_surfaces;i < model->num_surfaces;i++, surface++)
{
mesh = surface->groupmesh;
vertex3f = Z_Malloc(maxvertices * sizeof(float[3]));
}
Mod_Alias_GetMesh_Vertex3f(model, frameblend, mesh, vertex3f);
- Collision_TraceBrushTriangleMeshFloat(trace, thisbrush_start, thisbrush_end, mesh->num_triangles, mesh->data_element3i, vertex3f, SUPERCONTENTS_SOLID, segmentmins, segmentmaxs);
+ Collision_TraceBrushTriangleMeshFloat(trace, thisbrush_start, thisbrush_end, mesh->num_triangles, mesh->data_element3i, vertex3f, SUPERCONTENTS_SOLID, 0, surface->texture, segmentmins, segmentmaxs);
}
}
}
cvar_t mod_q3bsp_optimizedtraceline = {0, "mod_q3bsp_optimizedtraceline", "1", "whether to use optimized traceline code for line traces (as opposed to tracebox code)"};
cvar_t mod_q3bsp_debugtracebrush = {0, "mod_q3bsp_debugtracebrush", "0", "selects different tracebrush bsp recursion algorithms (for debugging purposes only)"};
+static texture_t mod_q1bsp_texture_solid;
+static texture_t mod_q1bsp_texture_sky;
+static texture_t mod_q1bsp_texture_lava;
+static texture_t mod_q1bsp_texture_slime;
+static texture_t mod_q1bsp_texture_water;
+
void Mod_BrushInit(void)
{
// Cvar_RegisterVariable(&r_subdivide_size);
Cvar_RegisterVariable(&mod_q3bsp_curves_collisions);
Cvar_RegisterVariable(&mod_q3bsp_optimizedtraceline);
Cvar_RegisterVariable(&mod_q3bsp_debugtracebrush);
+
+ memset(&mod_q1bsp_texture_solid, 0, sizeof(mod_q1bsp_texture_solid));
+ strlcpy(mod_q1bsp_texture_solid.name, "solid" , sizeof(mod_q1bsp_texture_solid.name));
+ mod_q1bsp_texture_solid.surfaceflags = 0;
+ mod_q1bsp_texture_solid.supercontents = SUPERCONTENTS_SOLID;
+
+ mod_q1bsp_texture_sky = mod_q1bsp_texture_solid;
+ strlcpy(mod_q1bsp_texture_sky.name, "sky", sizeof(mod_q1bsp_texture_sky.name));
+ mod_q1bsp_texture_sky.surfaceflags = Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NOIMPACT | Q3SURFACEFLAG_NOMARKS | Q3SURFACEFLAG_NODLIGHT | Q3SURFACEFLAG_NOLIGHTMAP;
+ mod_q1bsp_texture_sky.supercontents = SUPERCONTENTS_SKY | SUPERCONTENTS_NODROP;
+
+ mod_q1bsp_texture_lava = mod_q1bsp_texture_solid;
+ strlcpy(mod_q1bsp_texture_lava.name, "*lava", sizeof(mod_q1bsp_texture_lava.name));
+ mod_q1bsp_texture_lava.surfaceflags = Q3SURFACEFLAG_NOMARKS;
+ mod_q1bsp_texture_lava.supercontents = SUPERCONTENTS_LAVA | SUPERCONTENTS_NODROP;
+
+ mod_q1bsp_texture_slime = mod_q1bsp_texture_solid;
+ strlcpy(mod_q1bsp_texture_slime.name, "*slime", sizeof(mod_q1bsp_texture_slime.name));
+ mod_q1bsp_texture_slime.surfaceflags = Q3SURFACEFLAG_NOMARKS;
+ mod_q1bsp_texture_slime.supercontents = SUPERCONTENTS_SLIME;
+
+ mod_q1bsp_texture_water = mod_q1bsp_texture_solid;
+ strlcpy(mod_q1bsp_texture_water.name, "*water", sizeof(mod_q1bsp_texture_water.name));
+ mod_q1bsp_texture_water.surfaceflags = Q3SURFACEFLAG_NOMARKS;
+ mod_q1bsp_texture_water.supercontents = SUPERCONTENTS_WATER;
}
static mleaf_t *Mod_Q1BSP_PointInLeaf(model_t *model, const vec3_t p)
case CONTENTS_SLIME:
return SUPERCONTENTS_SLIME;
case CONTENTS_LAVA:
- return SUPERCONTENTS_LAVA;
+ return SUPERCONTENTS_LAVA | SUPERCONTENTS_NODROP;
case CONTENTS_SKY:
- return SUPERCONTENTS_SKY;
+ return SUPERCONTENTS_SKY | SUPERCONTENTS_NODROP;
}
return 0;
}
t->trace->inwater = true;
if (num == 0)
t->trace->inopen = true;
+ if (num & SUPERCONTENTS_SOLID)
+ t->trace->hittexture = &mod_q1bsp_texture_solid;
+ else if (num & SUPERCONTENTS_SKY)
+ t->trace->hittexture = &mod_q1bsp_texture_sky;
+ else if (num & SUPERCONTENTS_LAVA)
+ t->trace->hittexture = &mod_q1bsp_texture_lava;
+ else if (num & SUPERCONTENTS_SLIME)
+ t->trace->hittexture = &mod_q1bsp_texture_slime;
+ else
+ t->trace->hittexture = &mod_q1bsp_texture_water;
+ t->trace->hitq3surfaceflags = t->trace->hittexture->surfaceflags;
+ t->trace->hitsupercontents = num;
if (num & t->trace->hitsupercontentsmask)
{
// if the first leaf is solid, set startsolid
else
Mod_Q1BSP_RecursiveHullCheckPoint(&rhc, rhc.hull->firstclipnode);
#endif
+ if (trace->fraction == 1)
+ {
+ trace->hitsupercontents = 0;
+ trace->hitq3surfaceflags = 0;
+ trace->hittexture = NULL;
+ }
}
void Collision_ClipTrace_Box(trace_t *trace, const vec3_t cmins, const vec3_t cmaxs, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int hitsupercontentsmask, int boxsupercontents)
if (i == loadmodel->num_textures - 1)
{
tx->basematerialflags |= MATERIALFLAG_WATER | MATERIALFLAG_LIGHTBOTHSIDES;
- tx->supercontents = SUPERCONTENTS_WATER;
+ tx->supercontents = mod_q1bsp_texture_water.supercontents;
+ tx->surfaceflags = mod_q1bsp_texture_water.surfaceflags;
}
else
{
tx->basematerialflags |= MATERIALFLAG_WALL;
- tx->supercontents = SUPERCONTENTS_SOLID;
+ tx->supercontents = mod_q1bsp_texture_solid.supercontents;
+ tx->surfaceflags = mod_q1bsp_texture_solid.surfaceflags;
}
tx->currentframe = tx;
}
tx->basematerialflags = 0;
if (tx->name[0] == '*')
{
- // turb does not block movement
- tx->basematerialflags |= MATERIALFLAG_WATER | MATERIALFLAG_LIGHTBOTHSIDES;
// LordHavoc: some turbulent textures should not be affected by wateralpha
if (strncmp(tx->name,"*lava",5)
&& strncmp(tx->name,"*teleport",9)
&& strncmp(tx->name,"*rift",5)) // Scourge of Armagon texture
tx->basematerialflags |= MATERIALFLAG_WATERALPHA;
if (!strncmp(tx->name, "*lava", 5))
- tx->supercontents = SUPERCONTENTS_LAVA;
+ {
+ tx->supercontents = mod_q1bsp_texture_lava.supercontents;
+ tx->surfaceflags = mod_q1bsp_texture_lava.surfaceflags;
+ }
else if (!strncmp(tx->name, "*slime", 6))
- tx->supercontents = SUPERCONTENTS_SLIME;
+ {
+ tx->supercontents = mod_q1bsp_texture_slime.supercontents;
+ tx->surfaceflags = mod_q1bsp_texture_slime.surfaceflags;
+ }
else
- tx->supercontents = SUPERCONTENTS_WATER;
+ {
+ tx->supercontents = mod_q1bsp_texture_water.supercontents;
+ tx->surfaceflags = mod_q1bsp_texture_water.surfaceflags;
+ }
+ tx->basematerialflags |= MATERIALFLAG_WATER | MATERIALFLAG_LIGHTBOTHSIDES;
}
else if (tx->name[0] == 's' && tx->name[1] == 'k' && tx->name[2] == 'y')
{
- tx->supercontents = SUPERCONTENTS_SKY;
+ tx->supercontents = mod_q1bsp_texture_sky.supercontents;
+ tx->surfaceflags = mod_q1bsp_texture_sky.surfaceflags;
tx->basematerialflags |= MATERIALFLAG_SKY;
}
else
{
- tx->supercontents = SUPERCONTENTS_SOLID;
+ tx->supercontents = mod_q1bsp_texture_solid.supercontents;
+ tx->surfaceflags = mod_q1bsp_texture_solid.surfaceflags;
tx->basematerialflags |= MATERIALFLAG_WALL;
}
if (tx->skin.fog)
q3dbrush_t *in;
q3mbrush_t *out;
int i, j, n, c, count, maxplanes;
- mplane_t *planes;
+ colplanef_t *planes;
in = (q3dbrush_t *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
maxplanes = out->numbrushsides;
if (planes)
Mem_Free(planes);
- planes = (mplane_t *)Mem_Alloc(tempmempool, sizeof(mplane_t) * maxplanes);
+ planes = (colplanef_t *)Mem_Alloc(tempmempool, sizeof(colplanef_t) * maxplanes);
}
for (j = 0;j < out->numbrushsides;j++)
{
VectorCopy(out->firstbrushside[j].plane->normal, planes[j].normal);
planes[j].dist = out->firstbrushside[j].plane->dist;
+ planes[j].supercontents = out->firstbrushside[j].texture->supercontents;
+ planes[j].q3surfaceflags = out->firstbrushside[j].texture->surfaceflags;
+ planes[j].texture = out->firstbrushside[j].texture;
}
// make the colbrush from the planes
- out->colbrushf = Collision_NewBrushFromPlanes(loadmodel->mempool, out->numbrushsides, planes, out->texture->supercontents);
+ out->colbrushf = Collision_NewBrushFromPlanes(loadmodel->mempool, out->numbrushsides, planes);
}
if (planes)
Mem_Free(planes);
if (surface->num_collisiontriangles && surface->collisionmarkframe != markframe && BoxesOverlap(nodesegmentmins, nodesegmentmaxs, surface->mins, surface->maxs))
{
surface->collisionmarkframe = markframe;
- Collision_TraceLineTriangleMeshFloat(trace, linestart, lineend, surface->num_collisiontriangles, surface->data_collisionelement3i, surface->data_collisionvertex3f, surface->texture->supercontents, segmentmins, segmentmaxs);
+ Collision_TraceLineTriangleMeshFloat(trace, linestart, lineend, surface->num_collisiontriangles, surface->data_collisionelement3i, surface->data_collisionvertex3f, surface->texture->supercontents, surface->texture->surfaceflags, surface->texture, segmentmins, segmentmaxs);
}
}
}
if (surface->num_collisiontriangles && surface->collisionmarkframe != markframe && BoxesOverlap(nodesegmentmins, nodesegmentmaxs, surface->mins, surface->maxs))
{
surface->collisionmarkframe = markframe;
- Collision_TraceBrushTriangleMeshFloat(trace, thisbrush_start, thisbrush_end, surface->num_collisiontriangles, surface->data_collisionelement3i, surface->data_collisionvertex3f, surface->texture->supercontents, segmentmins, segmentmaxs);
+ Collision_TraceBrushTriangleMeshFloat(trace, thisbrush_start, thisbrush_end, surface->num_collisiontriangles, surface->data_collisionelement3i, surface->data_collisionvertex3f, surface->texture->supercontents, surface->texture->surfaceflags, surface->texture, segmentmins, segmentmaxs);
}
}
}
if (mod_q3bsp_curves_collisions.integer)
for (i = 0, surface = model->data_surfaces + model->firstmodelsurface;i < model->nummodelsurfaces;i++, surface++)
if (surface->num_collisiontriangles)
- Collision_TraceLineTriangleMeshFloat(trace, start, end, surface->num_collisiontriangles, surface->data_collisionelement3i, surface->data_collisionvertex3f, surface->texture->supercontents, segmentmins, segmentmaxs);
+ Collision_TraceLineTriangleMeshFloat(trace, start, end, surface->num_collisiontriangles, surface->data_collisionelement3i, surface->data_collisionvertex3f, surface->texture->supercontents, surface->texture->surfaceflags, surface->texture, segmentmins, segmentmaxs);
}
else
Mod_Q3BSP_TraceLine_RecursiveBSPNode(trace, model, model->brush.data_nodes, start, end, 0, 1, start, end, ++markframe, segmentmins, segmentmaxs);
VectorAdd(start, boxmaxs, boxstartmaxs);
VectorAdd(end, boxmins, boxendmins);
VectorAdd(end, boxmaxs, boxendmaxs);
- thisbrush_start = Collision_BrushForBox(&identitymatrix, boxstartmins, boxstartmaxs);
- thisbrush_end = Collision_BrushForBox(&identitymatrix, boxendmins, boxendmaxs);
+ thisbrush_start = Collision_BrushForBox(&identitymatrix, boxstartmins, boxstartmaxs, 0, 0, NULL);
+ thisbrush_end = Collision_BrushForBox(&identitymatrix, boxendmins, boxendmaxs, 0, 0, NULL);
if (model->brush.submodel)
{
for (i = 0, brush = model->brush.data_brushes + model->firstmodelbrush;i < model->nummodelbrushes;i++, brush++)
if (mod_q3bsp_curves_collisions.integer)
for (i = 0, surface = model->data_surfaces + model->firstmodelsurface;i < model->nummodelsurfaces;i++, surface++)
if (surface->num_collisiontriangles)
- Collision_TraceBrushTriangleMeshFloat(trace, thisbrush_start, thisbrush_end, surface->num_collisiontriangles, surface->data_collisionelement3i, surface->data_collisionvertex3f, surface->texture->supercontents, segmentmins, segmentmaxs);
+ Collision_TraceBrushTriangleMeshFloat(trace, thisbrush_start, thisbrush_end, surface->num_collisiontriangles, surface->data_collisionelement3i, surface->data_collisionvertex3f, surface->texture->supercontents, surface->texture->surfaceflags, surface->texture, segmentmins, segmentmaxs);
}
else
Mod_Q3BSP_TraceBrush_RecursiveBSPNode(trace, model, model->brush.data_nodes, thisbrush_start, thisbrush_end, ++markframe, segmentmins, segmentmaxs);
void R_Shadow_DrawEntityLight(entity_render_t *ent, int numsurfaces, int *surfacelist)
{
+ if (!ent->model->DrawLight)
+ return;
R_Shadow_SetupEntityLight(ent);
if (ent == r_refdef.worldentity)
ent->model->DrawLight(ent, numsurfaces, surfacelist);
VectorCopy(trace.endpos, cliptrace.endpos);
cliptrace.plane = trace.plane;
cliptrace.ent = touch;
+ cliptrace.hitsupercontents = trace.hitsupercontents;
+ cliptrace.hitq3surfaceflags = trace.hitq3surfaceflags;
+ cliptrace.hittexture = trace.hittexture;
}
cliptrace.startsupercontents |= trace.startsupercontents;
}
VectorCopy(trace.endpos, cliptrace.endpos);
cliptrace.plane = trace.plane;
cliptrace.ent = touch;
+ cliptrace.hitsupercontents = trace.hitsupercontents;
+ cliptrace.hitq3surfaceflags = trace.hitq3surfaceflags;
+ cliptrace.hittexture = trace.hittexture;
}
cliptrace.startsupercontents |= trace.startsupercontents;
}