示例#1
0
        private void ReadBrusheSides()
        {
            //Length of the Lump
            int BrusheSideLength = Header.DirEntries[9].Length;
            //Number of textures to load
            int nbBrusheSides = BrusheSideLength / (sizeof(int) * 2);


            BrusheSides = new brushside[nbBrusheSides];
            for (int i = 0; i < nbBrusheSides; i++)
            {
                //plane
                int plane = ReadInt();

                //texture
                int texture = ReadInt();


                BrusheSides[i] = new brushside(plane, texture);
            }
        }
示例#2
0
        private void CheckBrush(brush pBrush)
        {
            float startFraction = -1.0f;
            float endFraction   = 1.0f;
            bool  startsout     = false;
            bool  endsout       = false;

            for (int i = 0; i < pBrush.N_BrushSides; i++)
            {
                brushside brushside   = file.BrusheSides[pBrush.BrushSide + i];
                plane     plane       = file.Planes[brushside.Plane];
                Vector3   planeNormal = BspRenderer.V3FromFloatArray(plane.Normal);

                float startDistance = 0;
                float endDistance   = 0;

                if (traceType == TT_RAY)
                {
                    startDistance = Vector3.Dot(_inputStart, planeNormal) - plane.Dist;
                    endDistance   = Vector3.Dot(_inputEnd, planeNormal) - plane.Dist;
                }
                else if (traceType == TT_SPHERE)
                {
                    startDistance = Vector3.Dot(_inputStart, planeNormal) - (plane.Dist + traceRadius);
                    endDistance   = Vector3.Dot(_inputEnd, planeNormal) - (plane.Dist + traceRadius);
                }
                else if (traceType == TT_BOX)
                {
                    Vector3 offset = Vector3.Zero;

                    if (planeNormal.X < 0)
                    {
                        offset.X = traceMaxs.X;
                    }
                    else
                    {
                        offset.X = traceMins.X;
                    }

                    if (planeNormal.Y < 0)
                    {
                        offset.Y = traceMaxs.Y;
                    }
                    else
                    {
                        offset.Y = traceMins.Y;
                    }

                    if (planeNormal.Z < 0)
                    {
                        offset.Z = traceMaxs.Z;
                    }
                    else
                    {
                        offset.Z = traceMins.Z;
                    }

                    startDistance = (_inputStart.X + offset.X) * planeNormal.X + (_inputStart.Y + offset.Y) * planeNormal.Y + (_inputStart.Z + offset.Z) * planeNormal.Z - plane.Dist;
                    endDistance   = (_inputEnd.X + offset.X) * planeNormal.X + (_inputEnd.Y + offset.Y) * planeNormal.Y + (_inputEnd.Z + offset.Z) * planeNormal.Z - plane.Dist;
                }


                if (startDistance > 0)
                {
                    startsout = true;
                }
                if (endDistance > 0)
                {
                    endsout = true;
                }

                // make sure the trace isnt on one side of the brush only

                if (startDistance > 0 && endDistance > 0)
                {
                    // both in front of the plane
                    return;
                }
                if (startDistance <= 0 && endDistance <= 0)
                {
                    // both are behind the plane, it will get clipped by an other one
                    continue;
                }


                if (startDistance > endDistance)
                {
                    // line is in the brush
                    float fraction = (startDistance - float.Epsilon) / (startDistance - endDistance);
                    if (fraction > startFraction)
                    {
                        startFraction = fraction;
                    }
                }
                else
                {
                    //line is leaving the brush
                    float fraction = (startDistance + float.Epsilon) / (startDistance - endDistance);
                    if (fraction < endFraction)
                    {
                        endFraction = fraction;
                    }
                }
            }

            if (startsout == false)
            {
                outputStartsOut = false;
                if (endsout)
                {
                    outputAllSolid = true;
                }
                return;
            }

            if (startFraction < endFraction)
            {
                if (startFraction > -1 && startFraction < outputFraction)
                {
                    if (startFraction < 0)
                    {
                        startFraction = 0;
                    }
                    outputFraction = startFraction;
                }
            }
        }