X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=collision.c;h=b97a0df351f37177a1940be71f86afa7faa70636;hb=c2b8c4445746e076b248030967926d49d4108b2b;hp=fbe340f088c5f883dcf7a4cec593fd9490d10ca6;hpb=4d1f179f3ee23adbcc112e4b0e20d093b5c7060b;p=xonotic%2Fdarkplaces.git diff --git a/collision.c b/collision.c index fbe340f0..b97a0df3 100644 --- a/collision.c +++ b/collision.c @@ -561,11 +561,13 @@ colbrushf_t *Collision_AllocBrushFromPermanentPolygonFloat(mempool_t *mempool, i 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, hitq3surfaceflags = 0; - float enterfrac = -1, leavefrac = 1, d1, d2, f, imove, newimpactnormal[3], enterfrac2 = -1; + float enterfrac = -1, leavefrac = 1, d1, d2, s, e, ie, f, imove, enterfrac2 = -1; const colplanef_t *startplane, *endplane; + plane_t newimpactplane; texture_t *hittexture = NULL; - VectorClear(newimpactnormal); + VectorClear(newimpactplane.normal); + newimpactplane.dist = 0; for (nplane = 0;nplane < thatbrush_start->numplanes + thisbrush_start->numplanes;nplane++) { @@ -587,8 +589,10 @@ void Collision_TraceBrushBrushFloat(trace_t *trace, const colbrushf_t *thisbrush if (fabs(f - startplane->dist) > COLLISION_PLANE_DIST_EPSILON) Con_Printf("startplane->dist %f != calculated %f (thisbrush_start)\n", startplane->dist, f); } - d1 = nearestplanedist_float(startplane->normal, thisbrush_start->points, thisbrush_start->numpoints) - furthestplanedist_float(startplane->normal, thatbrush_start->points, thatbrush_start->numpoints) - collision_startnudge.value; - d2 = nearestplanedist_float(endplane->normal, thisbrush_end->points, thisbrush_end->numpoints) - furthestplanedist_float(endplane->normal, thatbrush_end->points, thatbrush_end->numpoints) - collision_endnudge.value; + s = furthestplanedist_float(startplane->normal, thatbrush_start->points, thatbrush_start->numpoints); + e = furthestplanedist_float(endplane->normal, thatbrush_end->points, thatbrush_end->numpoints); + d1 = nearestplanedist_float(startplane->normal, thisbrush_start->points, thisbrush_start->numpoints) - s - collision_startnudge.value; + d2 = nearestplanedist_float(endplane->normal, thisbrush_end->points, thisbrush_end->numpoints) - e - collision_endnudge.value; } else { @@ -606,8 +610,10 @@ void Collision_TraceBrushBrushFloat(trace_t *trace, const colbrushf_t *thisbrush if (fabs(f - startplane->dist) > COLLISION_PLANE_DIST_EPSILON) Con_Printf("startplane->dist %f != calculated %f (thatbrush_start)\n", startplane->dist, f); } - d1 = nearestplanedist_float(startplane->normal, thisbrush_start->points, thisbrush_start->numpoints) - startplane->dist - collision_startnudge.value; - d2 = nearestplanedist_float(endplane->normal, thisbrush_end->points, thisbrush_end->numpoints) - endplane->dist - collision_endnudge.value; + s = startplane->dist; + e = endplane->dist; + d1 = nearestplanedist_float(startplane->normal, thisbrush_start->points, thisbrush_start->numpoints) - s - collision_startnudge.value; + d2 = nearestplanedist_float(endplane->normal, thisbrush_end->points, thisbrush_end->numpoints) - e - collision_endnudge.value; } //Con_Printf("%c%i: d1 = %f, d2 = %f, d1 / (d1 - d2) = %f\n", nplane2 != nplane ? 'b' : 'a', nplane2, d1, d2, d1 / (d1 - d2)); @@ -639,7 +645,11 @@ void Collision_TraceBrushBrushFloat(trace_t *trace, const colbrushf_t *thisbrush // calculate the nudged fraction and impact normal we'll // need if we accept this collision later enterfrac2 = (d1 - collision_impactnudge.value) * imove; - VectorLerp(startplane->normal, enterfrac, endplane->normal, newimpactnormal); + ie = 1.0f - enterfrac; + newimpactplane.normal[0] = startplane->normal[0] * ie + endplane->normal[0] * enterfrac; + newimpactplane.normal[1] = startplane->normal[1] * ie + endplane->normal[1] * enterfrac; + newimpactplane.normal[2] = startplane->normal[2] * ie + endplane->normal[2] * enterfrac; + newimpactplane.dist = s * ie + e * enterfrac; hitq3surfaceflags = startplane->q3surfaceflags; hittexture = startplane->texture; } @@ -686,7 +696,7 @@ void Collision_TraceBrushBrushFloat(trace_t *trace, const colbrushf_t *thisbrush trace->fraction = bound(0, enterfrac2, 1); if (collision_prefernudgedfraction.integer) trace->realfraction = trace->fraction; - VectorCopy(newimpactnormal, trace->plane.normal); + trace->plane = newimpactplane; } } else @@ -698,6 +708,7 @@ void Collision_TraceBrushBrushFloat(trace_t *trace, const colbrushf_t *thisbrush trace->startsolid = true; if (leavefrac < 1) trace->allsolid = true; + trace->plane = newimpactplane; } } } @@ -706,11 +717,13 @@ void Collision_TraceBrushBrushFloat(trace_t *trace, const colbrushf_t *thisbrush 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, hitq3surfaceflags = 0; - float enterfrac = -1, leavefrac = 1, d1, d2, f, imove, newimpactnormal[3], enterfrac2 = -1; + float enterfrac = -1, leavefrac = 1, d1, d2, ie, f, imove, enterfrac2 = -1; const colplanef_t *startplane, *endplane; + plane_t newimpactplane; texture_t *hittexture = NULL; - VectorClear(newimpactnormal); + VectorClear(newimpactplane.normal); + newimpactplane.dist = 0; for (nplane = 0;nplane < thatbrush_start->numplanes;nplane++) { @@ -762,7 +775,11 @@ void Collision_TraceLineBrushFloat(trace_t *trace, const vec3_t linestart, const // calculate the nudged fraction and impact normal we'll // need if we accept this collision later enterfrac2 = (d1 - collision_impactnudge.value) * imove; - VectorLerp(startplane->normal, enterfrac, endplane->normal, newimpactnormal); + ie = 1.0f - enterfrac; + newimpactplane.normal[0] = startplane->normal[0] * ie + endplane->normal[0] * enterfrac; + newimpactplane.normal[1] = startplane->normal[1] * ie + endplane->normal[1] * enterfrac; + newimpactplane.normal[2] = startplane->normal[2] * ie + endplane->normal[2] * enterfrac; + newimpactplane.dist = startplane->dist * ie + endplane->dist * enterfrac; hitq3surfaceflags = startplane->q3surfaceflags; hittexture = startplane->texture; } @@ -807,7 +824,7 @@ void Collision_TraceLineBrushFloat(trace_t *trace, const vec3_t linestart, const trace->fraction = bound(0, enterfrac2, 1); if (collision_prefernudgedfraction.integer) trace->realfraction = trace->fraction; - VectorCopy(newimpactnormal, trace->plane.normal); + trace->plane = newimpactplane; } } else @@ -819,6 +836,7 @@ void Collision_TraceLineBrushFloat(trace_t *trace, const vec3_t linestart, const trace->startsolid = true; if (leavefrac < 1) trace->allsolid = true; + trace->plane = newimpactplane; } } } @@ -1465,9 +1483,9 @@ void Collision_BoundingBoxOfBrushTraceSegment(const colbrushf_t *start, const co //=========================================== -void Collision_ClipToGenericEntity(trace_t *trace, 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 mins, const vec3_t maxs, const vec3_t end, int hitsupercontentsmask) +void Collision_ClipToGenericEntity(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 mins, const vec3_t maxs, const vec3_t end, int hitsupercontentsmask) { - float tempnormal[3], starttransformed[3], endtransformed[3]; + float starttransformed[3], endtransformed[3]; memset(trace, 0, sizeof(*trace)); trace->fraction = trace->realfraction = 1; @@ -1486,16 +1504,13 @@ void Collision_ClipToGenericEntity(trace_t *trace, model_t *model, int frame, co trace->fraction = bound(0, trace->fraction, 1); trace->realfraction = bound(0, trace->realfraction, 1); - if (trace->fraction < 1) - { - VectorLerp(start, trace->fraction, end, trace->endpos); - VectorCopy(trace->plane.normal, tempnormal); - Matrix4x4_Transform3x3(matrix, tempnormal, trace->plane.normal); - // FIXME: should recalc trace->plane.dist - } + 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_ClipToWorld(trace_t *trace, model_t *model, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int hitsupercontents) +void Collision_ClipToWorld(trace_t *trace, dp_model_t *model, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int hitsupercontents) { memset(trace, 0, sizeof(*trace)); trace->fraction = trace->realfraction = 1; @@ -1526,7 +1541,7 @@ void Collision_CombineTraces(trace_t *cliptrace, const trace_t *trace, void *tou // cliptrace->inopen = true; if (trace->inwater) cliptrace->inwater = true; - if (trace->realfraction < cliptrace->realfraction) + if ((trace->realfraction <= cliptrace->realfraction) && (VectorLength2(trace->plane.normal) > 0)) { cliptrace->fraction = trace->fraction; cliptrace->realfraction = trace->realfraction;