Exemplo n.º 1
0
        private bool LoadBrushSideLump(Q3BSPDirEntry dir, BinaryReader fileReader)
        {
            int brushSideCount = dir.Length / Q3BSPConstants.sizeBrushSide;

            brushSides = new Q3BSPBrushSide[brushSideCount];
            for (int i = 0; i < brushSideCount; i++)
            {
                brushSides[i] = Q3BSPBrushSide.FromStream(fileReader);
            }
            return(true);
        }
Exemplo n.º 2
0
        private void CheckBrush(ref Q3BSPBrush brush, ref Q3BSPCollisionData cd)
        {
            float startFraction = -1.0f;
            float endFraction   = 1.0f;
            bool  startsOut     = false;
            bool  endsOut       = false;

            for (int i = 0; i < brush.BrushSideCount; i++)
            {
                Q3BSPBrushSide brushSide = brushSides[brush.StartBrushSide + i];
                Plane          plane     = planes[brushSide.PlaneIndex];

                float startDistance = Vector3.Dot(cd.startPosition, plane.Normal) - plane.D;
                float endDistance   = Vector3.Dot(cd.endPosition, plane.Normal) - plane.D;

                if (startDistance > 0)
                {
                    startsOut = true;
                }
                if (endDistance > 0)
                {
                    endsOut = true;
                }

                if (startDistance > 0 && endDistance > 0)
                {
                    return;
                }

                if (startDistance <= 0 && endDistance <= 0)
                {
                    continue;
                }

                if (startDistance > endDistance)
                {
                    float fraction = (startDistance - Q3BSPConstants.epsilon) / (startDistance - endDistance);
                    if (fraction > startFraction)
                    {
                        startFraction = fraction;
                    }
                }
                else
                {
                    float fraction = (startDistance + Q3BSPConstants.epsilon) / (startDistance - endDistance);
                    if (fraction < endFraction)
                    {
                        endFraction = fraction;
                    }
                }
            }

            if (false == startsOut)
            {
                cd.startOutside = false;
                if (false == endsOut)
                {
                    cd.inSolid = true;
                }

                return;
            }

            if (startFraction < endFraction)
            {
                if (startFraction > -1.0f && startFraction < cd.ratio)
                {
                    if (startFraction < 0)
                    {
                        startFraction = 0;
                    }
                    cd.ratio = startFraction;
                }
            }
        }