Beispiel #1
0
    public dbrush_t[] GetBrushes()
    {
        lump_t lump = lumps[18];
        dbrush_t[] brushes = new dbrush_t[lump.filelen / 12];
        stream.Position = lump.fileofs;

        for (int i = 0; i < brushes.Length; i++)
        {
            brushes[i].firstside = FileReader.readInt(stream);
            brushes[i].numsides = FileReader.readInt(stream);
            brushes[i].contents = FileReader.readInt(stream);
        }

        lumpData[18] = brushes;
        return brushes;
    }
Beispiel #2
0
    public dbrush_t[] GetBrushes()
    {
        lump_t lump = lumps[18];

        dbrush_t[] brushes = new dbrush_t[lump.filelen / 12];
        stream.Position = lump.fileofs;

        for (int i = 0; i < brushes.Length; i++)
        {
            brushes[i].firstside = FileReader.readInt(stream);
            brushes[i].numsides  = FileReader.readInt(stream);
            brushes[i].contents  = FileReader.readInt(stream);
        }

        lumpData[18] = brushes;
        return(brushes);
    }
Beispiel #3
0
        static void LoadBrushes(BinaryReader br, Header header)
        {
            // read brushsides
            br.BaseStream.Seek(header.lumps[19].fileofs, SeekOrigin.Begin);
            int numBrushSides = header.lumps[19].filelen / 8;
            for (int i = 0; i < numBrushSides; i++)
            {
                dbrushside_t brushside = new dbrushside_t();
                brushside.planenum = br.ReadUInt16();

                brushside.plane = world.planes[brushside.planenum];
                if (brushside.planenum == 9)
                {
                    int test = 2;
                }
                brushside.texinfo = br.ReadInt16();
                brushside.dispinfo = br.ReadInt16();
                brushside.bevel = br.ReadInt16();

                world.brushsides.Add(brushside);
            }

            // read brushes
            br.BaseStream.Seek(header.lumps[18].fileofs, SeekOrigin.Begin);
            //brushes = new dbrush_t[];
            int numBrushes = header.lumps[18].filelen / 12;
            for (int i = 0; i < numBrushes; i++)
            {
                dbrush_t brush = new dbrush_t();
                brush.firstside = br.ReadInt32();
                brush.numsides = br.ReadInt32();
                brush.sides = new dbrushside_t[brush.numsides];
                for (int j = 0; j < brush.numsides; j++)
                {
                    brush.sides[j] = world.brushsides[brush.firstside + j];
                }
                brush.contents = (brushflags)br.ReadInt32();
                brush.boundsmin = Vector3.Zero;
                brush.boundsmax = Vector3.Zero;
                brush.boundsmin[0] = -brush.sides[0].plane.dist;
                brush.boundsmax[0] = brush.sides[1].plane.dist;
                brush.boundsmin[1] = -brush.sides[2].plane.dist;
                brush.boundsmax[1] = brush.sides[3].plane.dist;
                brush.boundsmin[2] = -brush.sides[4].plane.dist;
                brush.boundsmax[2] = brush.sides[5].plane.dist;
                world.brushes.Add(brush);
            }
        }
Beispiel #4
0
        void TraceThroughBrush(traceWork_t tw, dbrush_t brush)
        {
            float enterFrac = -9999f;
            float leaveFrac = 1f;
            cplane_t clipplane = null;

            if (brush.numsides <= 0)
                return;

            c_brush_traces++;
            bool getout = false;
            bool getoutTemp = false;
            bool startout = false;
            bool startoutTemp = false;
            dbrushside_t leadside = null;
            cplane_t plane = null;
            //
            // compare the trace against all planes of the brush
            // find the latest time the trace crosses a plane towards the interior
            // and the earliest time the trace crosses a plane towards the exterior
            //
            for (int i = 0; i < brush.numsides; ++i)
            {
                dbrushside_t side = brushsides[brush.firstside + i];
                plane = side.plane;

                // sanity check
                if (side.plane.normal.X == 0f && side.plane.normal.Y == 0f && side.plane.normal.Z == 0f)
                    continue;

                float dist;
                if (!tw.isPoint)
                    dist = plane.dist - Vector3.Dot(tw.offsets[plane.signbits], plane.normal);
                else // ray
                {
                    dist = plane.dist;
                    // dont trace rays against bevel planes
                    if (side.bevel > 0)
                        continue;
                }

                float d1 = Vector3.Dot(tw.start, plane.normal) - dist;
                float d2 = Vector3.Dot(tw.end, plane.normal) - dist;

                // if completely in front of face, no intersection
                if (d1 > 0.0f)
                {

                    startout = true;
                    // d1 > 0.f && d2 > 0.f
                    if (d2 > 0.0f)
                        return;

                }
                else
                {
                    // d1 <= 0.f && d2 <= 0.f
                    if (d2 <= 0.0f)
                        continue;

                    // d2 > 0.f
                    getout = true;  // endpoint is not in solid
                }

                //startout = startoutTemp;
                //getout = getoutTemp;

                // crosses face
                if (d1 > d2)    // enter
                {
                    // enter
                    // JAY: This could be negative if d1 is less than the epsilon.
                    // If the trace is short (d1-d2 is small) then it could produce a large
                    // negative fraction.  I can't believe this didn't break Q2!
                    float f = (d1 - EPSILON);
                    if (f < 0.0f)
                        f = 0.0f;
                    f = f / (d1 - d2);
                    if (f > enterFrac)
                    {
                        enterFrac = f;

                        clipplane = plane;
                        leadside = side;

                    }
                }
                else // leave
                {
                    float f = (d1 + EPSILON) / (d1 - d2);
                    //if (f > 1)
                    //    f = 1;
                    if (f < leaveFrac)
                    {
                        leaveFrac = f;

                    }
                }
            }

                ////when this happens, we entered the brush *after* leaving the previous brush.
                //// Therefore, we're still outside!

                //// NOTE: We only do this test against points because fractionleftsolid is
                //// not possible to compute for brush sweeps without a *lot* more computation
                //// So, client code will never get fractionleftsolid for box sweeps
                //if (tw.isPoint && startout)
                //{
                //    // Add a little sludge.  The sludge should already be in the fractionleftsolid
                //    // (for all intents and purposes is a leavefrac value) and enterfrac values.
                //    // Both of these values have +/- DIST_EPSILON values calculated in.  Thus, I
                //    // think the test should be against "0.0."  If we experience new "left solid"
                //    // problems you may want to take a closer look here!
                //    //		if ((trace->fractionleftsolid - enterfrac) > -1e-6)
                //    if (tw.trace.fractionleftsolid - enterFrac > 0.0f)
                //        startout = false;
                //}

            //
            // all planes have been checked, and the trace was not
            // completely outside the brush
            //
            if (!startout)
            {
                // original point was inside brush
                tw.trace.startsolid = true;
                tw.trace.contents = (int)brush.contents;

                if (!getout)
                {
                    tw.trace.allsolid = true;
                    //tw.trace.plane = plane;
                    tw.trace.fraction = 0f;
                    //tw.trace.fractionleftsolid = 1.0f;
                }
                else
                {
                    // if leavefrac == 1, this means it's never been updated or we're in allsolid
                    // the allsolid case was handled above
                    //if ((leaveFrac != 1.0f) && (leaveFrac > tw.trace.fractionleftsolid))
                    //{
                    //    tw.trace.fractionleftsolid = leaveFrac;

                    //    // This could occur if a previous trace didn't start us in solid
                    //    if (tw.trace.fraction <= leaveFrac)
                    //    {
                    //        tw.trace.fraction = 1.0f;
                    //    }
                    //}
                }
                return;
            }

            // We haven't hit anything at all until we've left...
            if (enterFrac < leaveFrac)
            {
                if (enterFrac > -9999.0f && enterFrac < tw.trace.fraction)
                {
                    if (enterFrac < 0)
                        enterFrac = 0;
                    tw.trace.fraction = enterFrac;
                    tw.trace.plane = clipplane;
                    if(leadside.texinfo != -1)
                        tw.trace.surfaceFlags = (int)texinfos[leadside.texinfo].flags;
                    //tw.trace.surfaceFlags = leadside.bevel;
                    tw.trace.contents = (int)brush.contents;

                }
            }
        }
Beispiel #5
0
 void ReadBrushes(Header header, BinaryReader br)
 {
     // read brushes
     br.BaseStream.Seek(header.lumps[18].fileofs, SeekOrigin.Begin);
     //brushes = new dbrush_t[];
     int numBrushes = header.lumps[18].filelen / 12;
     for (int i = 0; i < numBrushes; i++)
     {
         dbrush_t brush = new dbrush_t();
         brush.firstside = br.ReadInt32();
         brush.numsides = br.ReadInt32();
         brush.sides = new dbrushside_t[brush.numsides];
         for (int j = 0; j < brush.numsides; j++)
         {
             brush.sides[j] = brushsides[brush.firstside + j];
         }
         brush.contents = (brushflags)br.ReadInt32();
         brush.boundsmin = Vector3.Zero;
         brush.boundsmax = Vector3.Zero;
         brush.boundsmin[0] = -brush.sides[0].plane.dist;
         brush.boundsmax[0] = brush.sides[1].plane.dist;
         brush.boundsmin[1] = -brush.sides[2].plane.dist;
         brush.boundsmax[1] = brush.sides[3].plane.dist;
         brush.boundsmin[2] = -brush.sides[4].plane.dist;
         brush.boundsmax[2] = brush.sides[5].plane.dist;
         brushes.Add(brush);
     }
 }
Beispiel #6
0
        /*
        ===================
        CM_InitBoxHull

        Set up the planes and nodes so that the six floats of a bounding box
        can just be stored out and get a proper clipping hull structure.
        ===================
        */
        void InitHullBox()
        {
            //box_planes =

            dbrush_t boxbrush = new dbrush_t();
            boxbrush.numsides = 6;
            boxbrush.contents = brushflags.CONTENTS_PLAYERCLIP;
            brushes.Add(boxbrush);
            box_brush = boxbrush;

            box_model = new cmodel_t();
            box_model.leaf = new dleaf_t();
            box_model.leaf.numleafbrushes = 1;
            box_model.leaf.firstleafbrush = (ushort)leafbrushes.Count;
            leafbrushes.Add(brushes.Count);

            cplane_t[] plan = new cplane_t[6*2];
            for (int i = 0; i < 12; i++)
            {
                plan[i] = new cplane_t();
            }

            dbrushside_t[] sides = new dbrushside_t[6];
            for (int i = 0; i < 6; i++)
            {
                sides[i] = new dbrushside_t();
            }

            int numBrushSides = brushsides.Count;
            for (int i = 0; i < 6; i++)
            {
                int side = i & 1;
                dbrushside_t s = sides[i];
                s.plane = plan[i * 2 + side];

                // planes
                cplane_t p = plan[i * 2];
                p.type = i >> 1;
                p.signbits = 0;
                p.normal = Vector3.Zero;
                p.normal[i >> 1] = 1;

                p = planes[i * 2 + 1];
                p.type = 3 + (i >> 1);
                p.signbits = 0;
                p.normal = Vector3.Zero;
                p.normal[i >> 1] = -1;

                Common.SetPlaneSignbits(p);
            }

            box_planes.AddRange(plan);
            planes.AddRange(plan);
            brushsides.AddRange(sides);
        }
Beispiel #7
0
 public void ClearMap()
 {
     name = null;
     numBrushSides = 0;
     brushsides = new List<dbrushside_t>();
     planes = new List<cplane_t>();
     numNodes = 0;
     nodes = null;
     numLeafs = 0;
     leafs = null;
     numLeafBrushes = 0;
     leafbrushes = new List<int>();
     leafFaces = new List<int>();
     numSubModels = 0;
     cmodels = null;
     brushes = new List<dbrush_t>();
     numClusters = 0;
     clusterBytes = 0;
     visibility = null;
     vised = false;			// if false, visibility is just a single cluster of ffs
     entityString = null;
     numAreas = 0;
     numSurfaces = 0;
     floodvalid = 0;
     checkcount = 0;					// incremented on each trace
     c_traces = 0;
     c_brush_traces = 0;
     texinfos = null;
     box_model = new cmodel_t();
     box_planes = new List<cplane_t>();
     box_brush = new dbrush_t();
     vis = new dvis_t();
     edges  = null;
     DispIndexToFaceIndex  = null;
     ddispinfos  = null;
     dispLightmapSamples  = null;
     dispVerts  = null;
     dispTris  = null;
     dispCollTrees  = null;
     surfEdges = null;
 }