Removed collision_prefernudgedfraction cvar and trace.realfraction field, this has...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 13 May 2014 17:43:21 +0000 (17:43 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 13 May 2014 17:43:21 +0000 (17:43 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12074 d7cf8633-e32d-0410-b094-e92efae38249

cl_collision.c
collision.c
collision.h
model_alias.c
model_brush.c

index eb316f7..d6637a5 100644 (file)
@@ -4,7 +4,7 @@
 
 float CL_SelectTraceLine(const vec3_t start, const vec3_t end, vec3_t impact, vec3_t normal, int *hitent, entity_render_t *ignoreent)
 {
-       float maxfrac, maxrealfrac;
+       float maxfrac;
        int n;
        entity_render_t *ent;
        vec_t tracemins[3], tracemaxs[3];
@@ -13,7 +13,6 @@ float CL_SelectTraceLine(const vec3_t start, const vec3_t end, vec3_t impact, ve
 
        memset (&trace, 0 , sizeof(trace_t));
        trace.fraction = 1;
-       trace.realfraction = 1;
        VectorCopy (end, trace.endpos);
 
        if (hitent)
@@ -24,7 +23,6 @@ float CL_SelectTraceLine(const vec3_t start, const vec3_t end, vec3_t impact, ve
        if (normal)
                VectorCopy(trace.plane.normal, normal);
        maxfrac = trace.fraction;
-       maxrealfrac = trace.realfraction;
 
        tracemins[0] = min(start[0], end[0]);
        tracemaxs[0] = max(start[0], end[0]);
@@ -53,17 +51,16 @@ float CL_SelectTraceLine(const vec3_t start, const vec3_t end, vec3_t impact, ve
                Matrix4x4_Transform(&ent->inversematrix, start, starttransformed);
                Matrix4x4_Transform(&ent->inversematrix, end, endtransformed);
                Collision_ClipTrace_Box(&trace, ent->model->normalmins, ent->model->normalmaxs, starttransformed, vec3_origin, vec3_origin, endtransformed, SUPERCONTENTS_SOLID, SUPERCONTENTS_SOLID, 0, NULL);
-               if (maxrealfrac < trace.realfraction)
+               if (maxfrac < trace.fraction)
                        continue;
 
                ent->model->TraceLine(ent->model, ent->frameblend, ent->skeleton, &trace, starttransformed, endtransformed, SUPERCONTENTS_SOLID);
 
-               if (maxrealfrac > trace.realfraction)
+               if (maxfrac > trace.fraction)
                {
                        if (hitent)
                                *hitent = n;
                        maxfrac = trace.fraction;
-                       maxrealfrac = trace.realfraction;
                        if (normal)
                        {
                                VectorCopy(trace.plane.normal, tempnormal);
@@ -292,7 +289,7 @@ trace_t CL_TracePoint(const vec3_t start, int type, prvm_edict_t *passedict, int
                        if (!BoxesOverlap(clipboxmins, clipboxmaxs, ent->mins, ent->maxs))
                                continue;
                        Collision_ClipPointToGenericEntity(&trace, ent->model, ent->frameblend, ent->skeleton, vec3_origin, vec3_origin, 0, &ent->matrix, &ent->inversematrix, start, hitsupercontentsmask);
-                       if (cliptrace.realfraction > trace.realfraction && hitnetworkentity)
+                       if (cliptrace.fraction > trace.fraction && hitnetworkentity)
                                *hitnetworkentity = cl.brushmodel_entities[i];
                        Collision_CombineTraces(&cliptrace, &trace, NULL, true);
                }
@@ -338,7 +335,7 @@ trace_t CL_TracePoint(const vec3_t start, int type, prvm_edict_t *passedict, int
                        Matrix4x4_CreateTranslate(&entmatrix, origin[0], origin[1], origin[2]);
                        Matrix4x4_CreateTranslate(&entinversematrix, -origin[0], -origin[1], -origin[2]);
                        Collision_ClipPointToGenericEntity(&trace, NULL, NULL, NULL, cl.playerstandmins, cl.playerstandmaxs, SUPERCONTENTS_BODY, &entmatrix, &entinversematrix, start, hitsupercontentsmask);
-                       if (cliptrace.realfraction > trace.realfraction && hitnetworkentity)
+                       if (cliptrace.fraction > trace.fraction && hitnetworkentity)
                                *hitnetworkentity = i;
                        Collision_CombineTraces(&cliptrace, &trace, NULL, false);
                }
@@ -405,7 +402,7 @@ skipnetworkplayers:
                else
                        Collision_ClipPointToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, hitsupercontentsmask);
 
-               if (cliptrace.realfraction > trace.realfraction && hitnetworkentity)
+               if (cliptrace.fraction > trace.fraction && hitnetworkentity)
                        *hitnetworkentity = 0;
                Collision_CombineTraces(&cliptrace, &trace, (void *)touch, PRVM_clientedictfloat(touch, solid) == SOLID_BSP);
        }
@@ -508,7 +505,7 @@ trace_t CL_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_
                        if (!BoxesOverlap(clipboxmins, clipboxmaxs, ent->mins, ent->maxs))
                                continue;
                        Collision_ClipLineToGenericEntity(&trace, ent->model, ent->frameblend, ent->skeleton, vec3_origin, vec3_origin, 0, &ent->matrix, &ent->inversematrix, start, end, hitsupercontentsmask, extend, hitsurfaces);
-                       if (cliptrace.realfraction > trace.realfraction && hitnetworkentity)
+                       if (cliptrace.fraction > trace.fraction && hitnetworkentity)
                                *hitnetworkentity = cl.brushmodel_entities[i];
                        Collision_CombineTraces(&cliptrace, &trace, NULL, true);
                }
@@ -554,7 +551,7 @@ trace_t CL_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_
                        Matrix4x4_CreateTranslate(&entmatrix, origin[0], origin[1], origin[2]);
                        Matrix4x4_CreateTranslate(&entinversematrix, -origin[0], -origin[1], -origin[2]);
                        Collision_ClipLineToGenericEntity(&trace, NULL, NULL, NULL, cl.playerstandmins, cl.playerstandmaxs, SUPERCONTENTS_BODY, &entmatrix, &entinversematrix, start, end, hitsupercontentsmask, extend, hitsurfaces);
-                       if (cliptrace.realfraction > trace.realfraction && hitnetworkentity)
+                       if (cliptrace.fraction > trace.fraction && hitnetworkentity)
                                *hitnetworkentity = i;
                        Collision_CombineTraces(&cliptrace, &trace, NULL, false);
                }
@@ -621,7 +618,7 @@ skipnetworkplayers:
                else
                        Collision_ClipLineToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, clipend, hitsupercontentsmask, extend, hitsurfaces);
 
-               if (cliptrace.realfraction > trace.realfraction && hitnetworkentity)
+               if (cliptrace.fraction > trace.fraction && hitnetworkentity)
                        *hitnetworkentity = 0;
                Collision_CombineTraces(&cliptrace, &trace, (void *)touch, PRVM_clientedictfloat(touch, solid) == SOLID_BSP);
        }
@@ -751,7 +748,7 @@ trace_t CL_TraceBox(const vec3_t start, const vec3_t mins, const vec3_t maxs, co
                        if (!BoxesOverlap(clipboxmins, clipboxmaxs, ent->mins, ent->maxs))
                                continue;
                        Collision_ClipToGenericEntity(&trace, ent->model, ent->frameblend, ent->skeleton, vec3_origin, vec3_origin, 0, &ent->matrix, &ent->inversematrix, start, mins, maxs, end, hitsupercontentsmask, extend);
-                       if (cliptrace.realfraction > trace.realfraction && hitnetworkentity)
+                       if (cliptrace.fraction > trace.fraction && hitnetworkentity)
                                *hitnetworkentity = cl.brushmodel_entities[i];
                        Collision_CombineTraces(&cliptrace, &trace, NULL, true);
                }
@@ -797,7 +794,7 @@ trace_t CL_TraceBox(const vec3_t start, const vec3_t mins, const vec3_t maxs, co
                        Matrix4x4_CreateTranslate(&entmatrix, origin[0], origin[1], origin[2]);
                        Matrix4x4_CreateTranslate(&entinversematrix, -origin[0], -origin[1], -origin[2]);
                        Collision_ClipToGenericEntity(&trace, NULL, NULL, NULL, cl.playerstandmins, cl.playerstandmaxs, SUPERCONTENTS_BODY, &entmatrix, &entinversematrix, start, mins, maxs, end, hitsupercontentsmask, extend);
-                       if (cliptrace.realfraction > trace.realfraction && hitnetworkentity)
+                       if (cliptrace.fraction > trace.fraction && hitnetworkentity)
                                *hitnetworkentity = i;
                        Collision_CombineTraces(&cliptrace, &trace, NULL, false);
                }
@@ -864,7 +861,7 @@ skipnetworkplayers:
                else
                        Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, clipmins, clipmaxs, clipend, hitsupercontentsmask, extend);
 
-               if (cliptrace.realfraction > trace.realfraction && hitnetworkentity)
+               if (cliptrace.fraction > trace.fraction && hitnetworkentity)
                        *hitnetworkentity = 0;
                Collision_CombineTraces(&cliptrace, &trace, (void *)touch, PRVM_clientedictfloat(touch, solid) == SOLID_BSP);
        }
index 0797f26..e574773 100644 (file)
@@ -14,7 +14,6 @@ cvar_t collision_startnudge = {0, "collision_startnudge", "0", "how much to bias
 cvar_t collision_endnudge = {0, "collision_endnudge", "0", "how much to bias collision trace end"};
 cvar_t collision_enternudge = {0, "collision_enternudge", "0", "how much to bias collision entry fraction"};
 cvar_t collision_leavenudge = {0, "collision_leavenudge", "0", "how much to bias collision exit fraction"};
-cvar_t collision_prefernudgedfraction = {0, "collision_prefernudgedfraction", "1", "whether to sort collision events by nudged fraction (1) or real fraction (0)"};
 cvar_t collision_extendmovelength = {0, "collision_extendmovelength", "16", "internal bias on trace length to ensure detection of collisions within the collision_impactnudge/collision_enternudge/collision_leavenudge distance so that short moves do not degrade across frames (this does not alter the final trace length)"};
 cvar_t collision_extendtraceboxlength = {0, "collision_extendtraceboxlength", "1", "internal bias for tracebox() qc builtin to account for collision_impactnudge/collision_enternudge/collision_leavenudge (this does not alter the final trace length)"};
 cvar_t collision_extendtracelinelength = {0, "collision_extendtracelinelength", "1", "internal bias for traceline() qc builtin to account for collision_impactnudge/collision_enternudge/collision_leavenudge (this does not alter the final trace length)"};
@@ -33,7 +32,6 @@ void Collision_Init (void)
        Cvar_RegisterVariable(&collision_endnudge);
        Cvar_RegisterVariable(&collision_enternudge);
        Cvar_RegisterVariable(&collision_leavenudge);
-       Cvar_RegisterVariable(&collision_prefernudgedfraction);
        Cvar_RegisterVariable(&collision_extendmovelength);
        Cvar_RegisterVariable(&collision_extendtracelinelength);
        Cvar_RegisterVariable(&collision_extendtraceboxlength);
@@ -685,14 +683,14 @@ void Collision_TraceBrushBrushFloat(trace_t *trace, const colbrushf_t *trace_sta
                                        // if the collision time range is now empty, no collision
                                        if (enterfrac > leavefrac)
                                                return;
+                                       // calculate the nudged fraction and impact normal we'll
+                                       // need if we accept this collision later
+                                       enterfrac2 = (startdist - collision_impactnudge.value) * imove;
                                        // if the collision would be further away than the trace's
                                        // existing collision data, we don't care about this
                                        // collision
-                                       if (enterfrac > trace->realfraction)
+                                       if (enterfrac2 >= trace->fraction)
                                                return;
-                                       // calculate the nudged fraction and impact normal we'll
-                                       // need if we accept this collision later
-                                       enterfrac2 = (startdist - collision_impactnudge.value) * imove;
                                        ie = 1.0f - enterfrac;
                                        newimpactplane[0] = startplane[0] * ie + endplane[0] * enterfrac;
                                        newimpactplane[1] = startplane[1] * ie + endplane[1] * enterfrac;
@@ -757,10 +755,7 @@ void Collision_TraceBrushBrushFloat(trace_t *trace, const colbrushf_t *trace_sta
                        trace->hitsupercontents = other_start->supercontents;
                        trace->hitq3surfaceflags = hitq3surfaceflags;
                        trace->hittexture = hittexture;
-                       trace->realfraction = bound(0, enterfrac, 1);
                        trace->fraction = bound(0, enterfrac2, 1);
-                       if (collision_prefernudgedfraction.integer)
-                               trace->realfraction = trace->fraction;
                        VectorCopy(newimpactplane, trace->plane.normal);
                        trace->plane.dist = newimpactplane[3];
                }
@@ -857,14 +852,14 @@ void Collision_TraceLineBrushFloat(trace_t *trace, const vec3_t linestart, const
                                        // if the collision time range is now empty, no collision
                                        if (enterfrac > leavefrac)
                                                return;
+                                       // calculate the nudged fraction and impact normal we'll
+                                       // need if we accept this collision later
+                                       enterfrac2 = (startdist - collision_impactnudge.value) * imove;
                                        // if the collision would be further away than the trace's
                                        // existing collision data, we don't care about this
                                        // collision
-                                       if (enterfrac > trace->realfraction)
+                                       if (enterfrac2 >= trace->fraction)
                                                return;
-                                       // calculate the nudged fraction and impact normal we'll
-                                       // need if we accept this collision later
-                                       enterfrac2 = (startdist - collision_impactnudge.value) * imove;
                                        ie = 1.0f - enterfrac;
                                        newimpactplane[0] = startplane[0] * ie + endplane[0] * enterfrac;
                                        newimpactplane[1] = startplane[1] * ie + endplane[1] * enterfrac;
@@ -912,10 +907,7 @@ void Collision_TraceLineBrushFloat(trace_t *trace, const vec3_t linestart, const
                        trace->hitsupercontents = other_start->supercontents;
                        trace->hitq3surfaceflags = hitq3surfaceflags;
                        trace->hittexture = hittexture;
-                       trace->realfraction = bound(0, enterfrac, 1);
                        trace->fraction = bound(0, enterfrac2, 1);
-                       if (collision_prefernudgedfraction.integer)
-                               trace->realfraction = trace->fraction;
                        VectorCopy(newimpactplane, trace->plane.normal);
                        trace->plane.dist = newimpactplane[3];
                }
@@ -1234,9 +1226,7 @@ float Collision_ClipTrace_Line_Sphere(double *linestart, double *lineend, double
 
 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, const texture_t *texture)
 {
-#if 1
-       // more optimized
-       float d1, d2, d, f, impact[3], edgenormal[3], faceplanenormal[3], faceplanedist, faceplanenormallength2, edge01[3], edge21[3], edge02[3];
+       float d1, d2, d, f, f2, impact[3], edgenormal[3], faceplanenormal[3], faceplanedist, faceplanenormallength2, edge01[3], edge21[3], edge02[3];
 
        // this function executes:
        // 32 ops when line starts behind triangle
@@ -1293,11 +1283,12 @@ void Collision_TraceLineTriangleFloat(trace_t *trace, const vec3_t linestart, co
        // and subtracting the face plane distance (this is the distance of the
        // triangle along that same normal)
        // then multiply by the recipricol distance delta
-       // 2 ops
+       // 4 ops
        f = (d1 - faceplanedist) * d;
+       f2  = f - collision_impactnudge.value * d;
        // skip out if this impact is further away than previous ones
        // 1 ops
-       if (f > trace->realfraction)
+       if (f2 >= trace->fraction)
                return;
        // calculate the perfect impact point for classification of insidedness
        // 9 ops
@@ -1332,14 +1323,7 @@ void Collision_TraceLineTriangleFloat(trace_t *trace, const vec3_t linestart, co
        // 8 ops (rare)
 
        // store the new trace fraction
-       trace->realfraction = f;
-
-       // calculate a nudged fraction to keep it out of the surface
-       // (the main fraction remains perfect)
-       trace->fraction = f - collision_impactnudge.value * d;
-
-       if (collision_prefernudgedfraction.integer)
-               trace->realfraction = trace->fraction;
+       trace->fraction = f2;
 
        // store the new trace plane (because collisions only happen from
        // the front this is always simply the triangle normal, never flipped)
@@ -1350,103 +1334,6 @@ void Collision_TraceLineTriangleFloat(trace_t *trace, const vec3_t linestart, co
        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];
-
-       // this code is designed for clockwise triangles, conversion to
-       // counterclockwise would require swapping some things around...
-       // it is easier to simply swap the point0 and point2 parameters to this
-       // function when calling it than it is to rewire the internals.
-
-       // calculate the unnormalized faceplanenormal of the triangle,
-       // this represents the front side
-       TriangleNormal(point0, point1, point2, faceplanenormal);
-       // there's no point in processing a degenerate triangle
-       // (GIGO - Garbage In, Garbage Out)
-       if (DotProduct(faceplanenormal, faceplanenormal) < 0.0001f)
-               return;
-       // calculate the unnormalized distance
-       faceplanedist = DotProduct(point0, faceplanenormal);
-
-       // calculate the unnormalized start distance
-       d1 = DotProduct(faceplanenormal, linestart) - faceplanedist;
-       // if start point is on the back side there is no collision
-       // (we don't care about traces going through the triangle the wrong way)
-       if (d1 <= 0)
-               return;
-
-       // calculate the unnormalized end distance
-       d2 = DotProduct(faceplanenormal, lineend) - faceplanedist;
-       // if both are in front, there is no collision
-       if (d2 >= 0)
-               return;
-
-       // from here on we know d1 is >= 0 and d2 is < 0
-       // this means the line starts infront and ends behind, passing through it
-
-       // calculate the recipricol of the distance delta,
-       // so we can use it multiple times cheaply (instead of division)
-       d = 1.0f / (d1 - d2);
-       // calculate the impact fraction by taking the start distance (> 0)
-       // and subtracting the face plane distance (this is the distance of the
-       // triangle along that same normal)
-       // then multiply by the recipricol distance delta
-       f = d1 * d;
-       // skip out if this impact is further away than previous ones
-       if (f > trace->realfraction)
-               return;
-       // calculate the perfect impact point for classification of insidedness
-       impact[0] = linestart[0] + f * (lineend[0] - linestart[0]);
-       impact[1] = linestart[1] + f * (lineend[1] - linestart[1]);
-       impact[2] = linestart[2] + f * (lineend[2] - linestart[2]);
-
-       // calculate the edge normal and reject if impact is outside triangle
-       // (an edge normal faces away from the triangle, to get the desired normal
-       //  a crossproduct with the faceplanenormal is used, and because of the way
-       // the insidedness comparison is written it does not need to be normalized)
-
-       VectorSubtract(point2, point0, edge);
-       CrossProduct(edge, faceplanenormal, edgenormal);
-       if (DotProduct(impact, edgenormal) > DotProduct(point0, edgenormal))
-               return;
-
-       VectorSubtract(point0, point1, edge);
-       CrossProduct(edge, faceplanenormal, edgenormal);
-       if (DotProduct(impact, edgenormal) > DotProduct(point1, edgenormal))
-               return;
-
-       VectorSubtract(point1, point2, edge);
-       CrossProduct(edge, faceplanenormal, edgenormal);
-       if (DotProduct(impact, edgenormal) > DotProduct(point2, edgenormal))
-               return;
-
-       // store the new trace fraction
-       trace->realfraction = bound(0, f, 1);
-
-       // store the new trace plane (because collisions only happen from
-       // the front this is always simply the triangle normal, never flipped)
-       VectorNormalize(faceplanenormal);
-       VectorCopy(faceplanenormal, trace->plane.normal);
-       trace->plane.dist = DotProduct(point0, faceplanenormal);
-
-       // calculate the normalized start and end distances
-       d1 = DotProduct(trace->plane.normal, linestart) - trace->plane.dist;
-       d2 = DotProduct(trace->plane.normal, lineend) - trace->plane.dist;
-
-       // calculate a nudged fraction to keep it out of the surface
-       // (the main fraction remains perfect)
-       fnudged = (d1 - collision_impactnudge.value) / (d1 - d2);
-       trace->fraction = bound(0, fnudged, 1);
-
-       // store the new trace endpos
-       // not needed, it's calculated later when the trace is finished
-       //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
 }
 
 void Collision_BoundingBoxOfBrushTraceSegment(const colbrushf_t *start, const colbrushf_t *end, vec3_t mins, vec3_t maxs, float startfrac, float endfrac)
@@ -1814,7 +1701,7 @@ extendtraceinfo_t;
 static void Collision_ClipExtendPrepare(extendtraceinfo_t *extendtraceinfo, trace_t *trace, const vec3_t tstart, const vec3_t tend, float textend)
 {
        memset(trace, 0, sizeof(*trace));
-       trace->fraction = trace->realfraction = 1;
+       trace->fraction = 1;
 
        extendtraceinfo->trace = trace;
        VectorCopy(tstart, extendtraceinfo->realstart);
@@ -1846,7 +1733,6 @@ static void Collision_ClipExtendFinish(extendtraceinfo_t *extendtraceinfo)
        {
                // undo the extended trace length
                trace->fraction *= extendtraceinfo->scaletoextend;
-               trace->realfraction *= extendtraceinfo->scaletoextend;
 
                // if the extended trace hit something that the unextended trace did not hit (even considering the collision_impactnudge), then we have to clear the hit information
                if (trace->fraction > 1.0f)
@@ -1863,7 +1749,6 @@ static void Collision_ClipExtendFinish(extendtraceinfo_t *extendtraceinfo)
 
        // clamp things
        trace->fraction = bound(0, trace->fraction, 1);
-       trace->realfraction = bound(0, trace->realfraction, 1);
 
        // calculate the end position
        VectorMA(extendtraceinfo->realstart, trace->fraction, extendtraceinfo->realdelta, trace->endpos);
@@ -1965,7 +1850,7 @@ void Collision_ClipPointToGenericEntity(trace_t *trace, dp_model_t *model, const
 {
        float starttransformed[3];
        memset(trace, 0, sizeof(*trace));
-       trace->fraction = trace->realfraction = 1;
+       trace->fraction = 1;
 
        Matrix4x4_Transform(inversematrix, start, starttransformed);
 #if COLLISIONPARANOID >= 3
@@ -1986,7 +1871,7 @@ void Collision_ClipPointToGenericEntity(trace_t *trace, dp_model_t *model, const
 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;
+       trace->fraction = 1;
        if (model && model->TracePoint)
                model->TracePoint(model, NULL, NULL, trace, start, hitsupercontents);
        VectorCopy(start, trace->endpos);
@@ -2002,7 +1887,7 @@ void Collision_CombineTraces(trace_t *cliptrace, const trace_t *trace, void *tou
                if (isbmodel)
                        cliptrace->bmodelstartsolid = true;
                cliptrace->startsolid = true;
-               if (cliptrace->realfraction == 1)
+               if (cliptrace->fraction == 1)
                        cliptrace->ent = touch;
                if (cliptrace->startdepth > trace->startdepth)
                {
@@ -2017,10 +1902,9 @@ 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) && (VectorLength2(trace->plane.normal) > 0))
+       if ((trace->fraction < cliptrace->fraction) && (VectorLength2(trace->plane.normal) > 0))
        {
                cliptrace->fraction = trace->fraction;
-               cliptrace->realfraction = trace->realfraction;
                VectorCopy(trace->endpos, cliptrace->endpos);
                cliptrace->plane = trace->plane;
                cliptrace->ent = touch;
@@ -2030,22 +1914,3 @@ void Collision_CombineTraces(trace_t *cliptrace, const trace_t *trace, void *tou
        }
        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;
-       }
-}
index afc12bc..f4f4761 100644 (file)
@@ -27,12 +27,9 @@ typedef struct trace_s
        // (set only by Q1BSP tracing)
        int inwater;
        // fraction of the total distance that was traveled before impact
+       // in case of impact this is actually nudged a bit off the surface
        // (1.0 = did not hit anything)
        double fraction;
-       // like fraction but is not nudged away from the surface (better for
-       // comparisons between two trace structs, as only one nudge for the final
-       // result is ever needed)
-       double realfraction;
        // final position of the trace (simply a point between start and end)
        double endpos[3];
        // surface normal at impact (not really correct for edge collisions)
@@ -182,6 +179,5 @@ extern cvar_t collision_impactnudge;
 extern cvar_t collision_extendtracelinelength;
 extern cvar_t collision_extendtraceboxlength;
 extern cvar_t collision_extendmovelength;
-extern cvar_t collision_prefernudgedfraction;
 
 #endif
index ddcd849..3da3b62 100644 (file)
@@ -761,7 +761,6 @@ static void Mod_MDLMD2MD3_TraceLine(dp_model_t *model, const frameblend_t *frame
        float *vertex3f = vertex3fbuf;
        memset(trace, 0, sizeof(*trace));
        trace->fraction = 1;
-       trace->realfraction = 1;
        trace->hitsupercontentsmask = hitsupercontentsmask;
        if (model->surfmesh.num_vertices > 1024)
                vertex3f = (float *)Mem_Alloc(tempmempool, model->surfmesh.num_vertices * sizeof(float[3]));
@@ -801,7 +800,6 @@ static void Mod_MDLMD2MD3_TraceBox(dp_model_t *model, const frameblend_t *frameb
        // box trace, performed as brush trace
        memset(trace, 0, sizeof(*trace));
        trace->fraction = 1;
-       trace->realfraction = 1;
        trace->hitsupercontentsmask = hitsupercontentsmask;
        if (model->surfmesh.num_vertices > 1024)
                vertex3f = (float *)Mem_Alloc(tempmempool, model->surfmesh.num_vertices * sizeof(float[3]));
index f4789ce..1ae93a4 100644 (file)
@@ -793,19 +793,12 @@ static int Mod_Q1BSP_RecursiveHullCheck(RecursiveHullCheckTraceInfo_t *t, int nu
                                VectorCopy (plane->normal, t->trace->plane.normal);
                        }
 
-                       // calculate the true fraction
+                       // calculate the return fraction which is nudged off the surface a bit
                        t1 = DotProduct(t->trace->plane.normal, t->start) - t->trace->plane.dist;
                        t2 = DotProduct(t->trace->plane.normal, t->end) - t->trace->plane.dist;
-                       midf = t1 / (t1 - t2);
-                       t->trace->realfraction = bound(0, midf, 1);
-
-                       // calculate the return fraction which is nudged off the surface a bit
                        midf = (t1 - collision_impactnudge.value) / (t1 - t2);
                        t->trace->fraction = bound(0, midf, 1);
 
-                       if (collision_prefernudgedfraction.integer)
-                               t->trace->realfraction = t->trace->fraction;
-
 #if COLLISIONPARANOID >= 3
                        Con_Print("D");
 #endif
@@ -898,7 +891,6 @@ static void Mod_Q1BSP_TracePoint(struct model_s *model, const frameblend_t *fram
        memset(trace, 0, sizeof(trace_t));
        rhc.trace = trace;
        rhc.trace->fraction = 1;
-       rhc.trace->realfraction = 1;
        rhc.trace->allsolid = true;
        rhc.hull = &model->brushq1.hulls[0]; // 0x0x0
        VectorCopy(start, rhc.start);
@@ -930,7 +922,6 @@ static void Mod_Q1BSP_TraceLine(struct model_s *model, const frameblend_t *frame
        rhc.trace = trace;
        rhc.trace->hitsupercontentsmask = hitsupercontentsmask;
        rhc.trace->fraction = 1;
-       rhc.trace->realfraction = 1;
        rhc.trace->allsolid = true;
        rhc.hull = &model->brushq1.hulls[0]; // 0x0x0
        VectorCopy(start, rhc.start);
@@ -948,7 +939,6 @@ static void Mod_Q1BSP_TraceLine(struct model_s *model, const frameblend_t *frame
                rhc.trace = &testtrace;
                rhc.trace->hitsupercontentsmask = hitsupercontentsmask;
                rhc.trace->fraction = 1;
-               rhc.trace->realfraction = 1;
                rhc.trace->allsolid = true;
                VectorCopy(test, rhc.start);
                VectorCopy(test, rhc.end);
@@ -987,7 +977,6 @@ static void Mod_Q1BSP_TraceBox(struct model_s *model, const frameblend_t *frameb
        rhc.trace = trace;
        rhc.trace->hitsupercontentsmask = hitsupercontentsmask;
        rhc.trace->fraction = 1;
-       rhc.trace->realfraction = 1;
        rhc.trace->allsolid = true;
        VectorSubtract(boxmaxs, boxmins, boxsize);
        if (boxsize[0] < 3)
@@ -1030,7 +1019,6 @@ static void Mod_Q1BSP_TraceBox(struct model_s *model, const frameblend_t *frameb
                rhc.trace = &testtrace;
                rhc.trace->hitsupercontentsmask = hitsupercontentsmask;
                rhc.trace->fraction = 1;
-               rhc.trace->realfraction = 1;
                rhc.trace->allsolid = true;
                VectorCopy(test, rhc.start);
                VectorCopy(test, rhc.end);
@@ -1099,7 +1087,6 @@ void Collision_ClipTrace_Box(trace_t *trace, const vec3_t cmins, const vec3_t cm
        memset(trace, 0, sizeof(trace_t));
        trace->hitsupercontentsmask = hitsupercontentsmask;
        trace->fraction = 1;
-       trace->realfraction = 1;
        Collision_TraceLineBrushFloat(trace, start, end, &cbox, &cbox);
 #else
        RecursiveHullCheckTraceInfo_t rhc;
@@ -1157,7 +1144,6 @@ void Collision_ClipTrace_Box(trace_t *trace, const vec3_t cmins, const vec3_t cm
        rhc.trace = trace;
        rhc.trace->hitsupercontentsmask = hitsupercontentsmask;
        rhc.trace->fraction = 1;
-       rhc.trace->realfraction = 1;
        rhc.trace->allsolid = true;
        VectorCopy(start, rhc.start);
        VectorCopy(end, rhc.end);
@@ -1173,7 +1159,6 @@ void Collision_ClipTrace_Point(trace_t *trace, const vec3_t cmins, const vec3_t
 {
        memset(trace, 0, sizeof(trace_t));
        trace->fraction = 1;
-       trace->realfraction = 1;
        if (BoxesOverlap(start, start, cmins, cmaxs))
        {
                trace->startsupercontents |= boxsupercontents;
@@ -1398,19 +1383,12 @@ static const texture_t *Mod_Q1BSP_TraceLineAgainstSurfacesFindTextureOnNode(Recu
                VectorCopy(normal, t->trace->plane.normal);
                t->trace->plane.dist = DotProduct(normal, p);
 
-               // calculate the true fraction
+               // calculate the return fraction which is nudged off the surface a bit
                t1 = DotProduct(t->start, t->trace->plane.normal) - t->trace->plane.dist;
                t2 = DotProduct(t->end, t->trace->plane.normal) - t->trace->plane.dist;
-               midf = t1 / (t1 - t2);
-               t->trace->realfraction = midf;
-
-               // calculate the return fraction which is nudged off the surface a bit
                midf = (t1 - collision_impactnudge.value) / (t1 - t2);
                t->trace->fraction = bound(0, midf, 1);
 
-               if (collision_prefernudgedfraction.integer)
-                       t->trace->realfraction = t->trace->fraction;
-
                t->trace->hittexture = surface->texture->currentframe;
                t->trace->hitq3surfaceflags = t->trace->hittexture->surfaceflags;
                t->trace->hitsupercontents = t->trace->hittexture->supercontents;
@@ -1521,7 +1499,6 @@ static void Mod_Q1BSP_TraceLineAgainstSurfaces(struct model_s *model, const fram
        rhc.trace = trace;
        rhc.trace->hitsupercontentsmask = hitsupercontentsmask;
        rhc.trace->fraction = 1;
-       rhc.trace->realfraction = 1;
        rhc.trace->allsolid = true;
        rhc.hull = &model->brushq1.hulls[0]; // 0x0x0
        VectorCopy(start, rhc.start);
@@ -6243,7 +6220,6 @@ void Mod_CollisionBIH_TracePoint(dp_model_t *model, const frameblend_t *frameble
 
        memset(trace, 0, sizeof(*trace));
        trace->fraction = 1;
-       trace->realfraction = 1;
        trace->hitsupercontentsmask = hitsupercontentsmask;
 
        bih = &model->collision_bih;
@@ -6319,7 +6295,6 @@ static void Mod_CollisionBIH_TraceLineShared(dp_model_t *model, const frameblend
 
        memset(trace, 0, sizeof(*trace));
        trace->fraction = 1;
-       trace->realfraction = 1;
        trace->hitsupercontentsmask = hitsupercontentsmask;
 
        // push first node
@@ -6459,7 +6434,6 @@ void Mod_CollisionBIH_TraceBrush(dp_model_t *model, const frameblend_t *frameble
        // box trace, performed as brush trace
        memset(trace, 0, sizeof(*trace));
        trace->fraction = 1;
-       trace->realfraction = 1;
        trace->hitsupercontentsmask = hitsupercontentsmask;
 
        // calculate tracebox-like parameters for efficient culling
@@ -6606,14 +6580,12 @@ void Mod_CollisionBIH_TracePoint_Mesh(dp_model_t *model, const frameblend_t *fra
 #endif
        memset(trace, 0, sizeof(*trace));
        trace->fraction = 1;
-       trace->realfraction = 1;
        trace->hitsupercontentsmask = hitsupercontentsmask;
 #if 0
        Mod_CollisionBIH_TraceLine(model, frameblend, skeleton, trace, start, end, hitsupercontentsmask);
        hitsupercontents = trace->hitsupercontents;
        memset(trace, 0, sizeof(*trace));
        trace->fraction = 1;
-       trace->realfraction = 1;
        trace->hitsupercontentsmask = hitsupercontentsmask;
        trace->startsupercontents = hitsupercontents;
 #endif
@@ -6628,7 +6600,6 @@ int Mod_CollisionBIH_PointSuperContents_Mesh(struct model_s *model, int frame, c
        VectorSet(end, start[0], start[1], model->normalmins[2]);
        memset(&trace, 0, sizeof(trace));
        trace.fraction = 1;
-       trace.realfraction = 1;
        trace.hitsupercontentsmask = 0;
        Mod_CollisionBIH_TraceLine(model, frameblend, skeleton, trace, start, end, hitsupercontentsmask);
        return trace.hitsupercontents;
@@ -6710,7 +6681,7 @@ static void Mod_Q3BSP_TraceLine_RecursiveBSPNode(trace_t *trace, dp_model_t *mod
                        Mod_Q3BSP_TraceLine_RecursiveBSPNode(trace, model, node->children[startside], start, mid, startfrac, midfrac, linestart, lineend, markframe, segmentmins, segmentmaxs);
                        // if we found an impact on the front side, don't waste time
                        // exploring the far side
-                       if (midfrac <= trace->realfraction)
+                       if (midfrac <= trace->fraction)
                                Mod_Q3BSP_TraceLine_RecursiveBSPNode(trace, model, node->children[endside], mid, end, midfrac, endfrac, linestart, lineend, markframe, segmentmins, segmentmaxs);
                        return;
                }
@@ -6858,7 +6829,6 @@ static void Mod_Q3BSP_TracePoint(dp_model_t *model, const frameblend_t *frameble
        q3mbrush_t *brush;
        memset(trace, 0, sizeof(*trace));
        trace->fraction = 1;
-       trace->realfraction = 1;
        trace->hitsupercontentsmask = hitsupercontentsmask;
        if (mod_collision_bih.integer)
                Mod_CollisionBIH_TracePoint(model, frameblend, skeleton, trace, start, hitsupercontentsmask);
@@ -6887,7 +6857,6 @@ static void Mod_Q3BSP_TraceLine(dp_model_t *model, const frameblend_t *frameblen
 
        memset(trace, 0, sizeof(*trace));
        trace->fraction = 1;
-       trace->realfraction = 1;
        trace->hitsupercontentsmask = hitsupercontentsmask;
        segmentmins[0] = min(start[0], end[0]) - 1;
        segmentmins[1] = min(start[1], end[1]) - 1;
@@ -6930,7 +6899,6 @@ static void Mod_Q3BSP_TraceBrush(dp_model_t *model, const frameblend_t *frameble
        // box trace, performed as brush trace
        memset(trace, 0, sizeof(*trace));
        trace->fraction = 1;
-       trace->realfraction = 1;
        trace->hitsupercontentsmask = hitsupercontentsmask;
        segmentmins[0] = min(start->mins[0], end->mins[0]) - 1;
        segmentmins[1] = min(start->mins[1], end->mins[1]) - 1;