Пример #1
0
        public VisibilityCheck(World world)
        {
            this.world = world;

            trace = new DivLine();

            occluder = new DivLine();
        }
Пример #2
0
        /// <summary>
        /// Calculate on which side of the line the point is.
        /// </summary>
        /// <returns>
        /// 0 (front) or 1 (back).
        /// </returns>
        public static int PointOnDivLineSide(Fixed x, Fixed y, DivLine line)
        {
            if (line.Dx == Fixed.Zero)
            {
                if (x <= line.X)
                {
                    return(line.Dy > Fixed.Zero ? 1 : 0);
                }
                else
                {
                    return(line.Dy < Fixed.Zero ? 1 : 0);
                }
            }

            if (line.Dy == Fixed.Zero)
            {
                if (y <= line.Y)
                {
                    return(line.Dx < Fixed.Zero ? 1 : 0);
                }
                else
                {
                    return(line.Dx > Fixed.Zero ? 1 : 0);
                }
            }

            var dx = (x - line.X);
            var dy = (y - line.Y);

            // Try to quickly decide by looking at sign bits.
            if (((line.Dy.Data ^ line.Dx.Data ^ dx.Data ^ dy.Data) & 0x80000000) != 0)
            {
                if (((line.Dy.Data ^ dx.Data) & 0x80000000) != 0)
                {
                    // Left is negative.
                    return(1);
                }
                else
                {
                    return(0);
                }
            }

            var left  = new Fixed(line.Dy.Data >> 8) * new Fixed(dx.Data >> 8);
            var right = new Fixed(dy.Data >> 8) * new Fixed(line.Dx.Data >> 8);

            if (right < left)
            {
                // Front side.
                return(0);
            }
            else
            {
                // Back side.
                return(1);
            }
        }
Пример #3
0
        /// <summary>
        /// Calculate on which side of the line the point is.
        /// </summary>
        /// <returns>
        /// 0 (front) or 1 (back), or 2 if the box crosses the line.
        /// </returns>
        public static int DivLineSide(Fixed x, Fixed y, DivLine line)
        {
            if (line.Dx == Fixed.Zero)
            {
                if (x == line.X)
                {
                    return(2);
                }

                if (x <= line.X)
                {
                    return(line.Dy > Fixed.Zero ? 1 : 0);
                }

                return(line.Dy < Fixed.Zero ? 1 : 0);
            }

            if (line.Dy == Fixed.Zero)
            {
                if (x == line.Y)
                {
                    return(2);
                }

                if (y <= line.Y)
                {
                    return(line.Dx < Fixed.Zero ? 1 : 0);
                }

                return(line.Dx > Fixed.Zero ? 1 : 0);
            }

            var dx = (x - line.X);
            var dy = (y - line.Y);

            var left  = new Fixed((line.Dy.Data >> Fixed.FracBits) * (dx.Data >> Fixed.FracBits));
            var right = new Fixed((dy.Data >> Fixed.FracBits) * (line.Dx.Data >> Fixed.FracBits));

            if (right < left)
            {
                // Front side.
                return(0);
            }

            if (left == right)
            {
                return(2);
            }
            else
            {
                // Back side.
                return(1);
            }
        }
Пример #4
0
        private Fixed InterceptVector(DivLine v2, DivLine v1)
        {
            var den = (v1.Dy >> 8) * v2.Dx - (v1.Dx >> 8) * v2.Dy;

            if (den == Fixed.Zero)
            {
                return(Fixed.Zero);
            }

            var num = ((v1.X - v2.X) >> 8) * v1.Dy + ((v2.Y - v1.Y) >> 8) * v1.Dx;

            var frac = num / den;

            return(frac);
        }
Пример #5
0
        public PathTraversal(World world)
        {
            this.world = world;

            intercepts = new Intercept[256];
            for (var i = 0; i < intercepts.Length; i++)
            {
                intercepts[i] = new Intercept();
            }

            target = new DivLine();
            trace  = new DivLine();

            lineInterceptFunc  = AddLineIntercepts;
            thingInterceptFunc = AddThingIntercepts;
        }