]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - collision.c
q3bsp transparency support (note: makes maps that abuse alpha in shaders for special...
[xonotic/darkplaces.git] / collision.c
index 1c4a4fe6b323149fe10be628f71c5b312c99c416..b95ab4087a7d46b712a8924db35c69b62f84af03 100644 (file)
@@ -153,8 +153,6 @@ loc0:
        midf = t1 / (t1 - t2);
        t->trace->fraction = bound(0.0f, midf, 1.0);
 
-       VectorMA(t->start, t->trace->fraction, t->dist, t->trace->endpos);
-
        return HULLCHECKSTATE_DONE;
 }
 
@@ -259,6 +257,7 @@ void Collision_ClipTrace_Box(trace_t *trace, const vec3_t cmins, const vec3_t cm
        VectorCopy(end, rhc.end);
        VectorSubtract(rhc.end, rhc.start, rhc.dist);
        RecursiveHullCheck(&rhc, rhc.hull->firstclipnode, 0, 1, rhc.start, rhc.end);
+       VectorMA(rhc.start, rhc.trace->fraction, rhc.dist, rhc.trace->endpos);
 }
 
 
@@ -363,11 +362,11 @@ float furthestplanedist_float(const float *normal, const colpointf_t *points, in
 }
 
 
-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 mplane_t *originalplanes, int supercontents, winding_t *temp1, winding_t *temp2)
 {
        int j, k, m;
        int numpoints, maxpoints, numplanes, maxplanes, numelements, maxelements, numtriangles, numpolypoints, maxpolypoints;
-       winding_t *w;
+       winding_t *w, *temp, *othertemp;
        colbrushf_t *brush;
        colpointf_t pointsbuf[256];
        colplanef_t planesbuf[256];
@@ -399,19 +398,24 @@ colbrushf_t *Collision_NewBrushFromPlanes(mempool_t *mempool, int numoriginalpla
                }
 
                // create a large polygon from the plane
-               w = Winding_NewFromPlane(originalplanes[j].normal[0], originalplanes[j].normal[1], originalplanes[j].normal[2], originalplanes[j].dist);
+               w = temp1;
+               othertemp = temp2;
+               BufWinding_NewFromPlane(w, originalplanes[j].normal[0], originalplanes[j].normal[1], originalplanes[j].normal[2], originalplanes[j].dist);
                // clip it by all other planes
-               for (k = 0;k < numoriginalplanes && w;k++)
+               for (k = 0;k < numoriginalplanes && w->numpoints;k++)
                {
                        if (k != j)
                        {
                                // we want to keep the inside of the brush plane so we flip
                                // the cutting plane
-                               w = Winding_Clip(w, -originalplanes[k].normal[0], -originalplanes[k].normal[1], -originalplanes[k].normal[2], -originalplanes[k].dist, true);
+                               BufWinding_Divide(w, -originalplanes[k].normal[0], -originalplanes[k].normal[1], -originalplanes[k].normal[2], -originalplanes[k].dist, othertemp, NULL, NULL, NULL);
+                               temp = w;
+                               w = othertemp;
+                               othertemp = temp;
                        }
                }
                // if nothing is left, skip it
-               if (!w)
+               if (!w->numpoints)
                        continue;
 
                // copy off the number of points for later when the winding is freed
@@ -456,8 +460,9 @@ colbrushf_t *Collision_NewBrushFromPlanes(mempool_t *mempool, int numoriginalpla
                        // store the index into a buffer
                        polypointbuf[k] = m;
                }
-               Winding_Free(w);
                w = NULL;
+               othertemp = NULL;
+               temp = NULL;
 
                // add the triangles for the polygon
                // (this particular code makes a triangle fan)