Exemplo n.º 1
0
        public bool InsideSquareTest(float ax, float ay, float bx, float @by,
                                     float cx, float cy, float dx, float dy, float px, float py)
        {
            AGSBoundingBox square = new AGSBoundingBox(new Vector2(ax, ay), new Vector2(bx, @by),
                                                       new Vector2(cx, cy), new Vector2(dx, dy));

            return(square.Contains(new Vector2(px, py)));
        }
Exemplo n.º 2
0
        public bool CollidesWith(float x, float y, IViewport viewport)
        {
            var boundingBoxesComponent = _boundingBox;

            if (boundingBoxesComponent == null)
            {
                return(false);
            }
            if (_crop?.IsGuaranteedToFullyCrop() ?? false)
            {
                //This should not be needed as the bounding box should be cropped anyway.
                //However, for a performance optimization if an entity is guaranteed to be fully cropped (like items in the bottom of a long listbox) the bounding box is not calculated, so we need to take it into account here.
                return(false);
            }
            AGSBoundingBox boundingBox           = boundingBoxesComponent.WorldBoundingBox;
            var            pixelPerfectComponent = _pixelPerfect;
            IArea          pixelPerfect          = pixelPerfectComponent == null || !pixelPerfectComponent.IsPixelPerfect ? null : pixelPerfectComponent.PixelPerfectHitTestArea;

            var drawable = _drawableInfo;

            if (drawable != null && !drawable.IgnoreViewport)
            {
                var matrix = viewport.GetMatrix(drawable.RenderLayer);
                matrix.Invert();
                Vector3 xyz = new Vector3(x, y, 0f);
                Vector3.Transform(ref xyz, ref matrix, out xyz);
                //todo: (support ignore scaling areas = false?)
                x = xyz.X;
                y = xyz.Y;
            }

            if (pixelPerfect == null || !pixelPerfect.Enabled)
            {
                if (!boundingBox.IsValid)
                {
                    return(false);
                }
                if (boundingBox.Contains(new Vector2(x, y)))
                {
                    return(true);
                }
            }
            else
            {
                var   obj       = _obj;
                float objScaleX = obj == null ? 1f : obj.CurrentSprite.ScaleX;
                float objScaleY = obj == null ? 1f : obj.CurrentSprite.ScaleY;
                var   scale     = _scale;
                float scaleX    = scale == null ? 1f : scale.ScaleX;
                float scaleY    = scale == null ? 1f : scale.ScaleY;
                if (pixelPerfect.IsInArea(new PointF(x, y), boundingBox, scaleX * objScaleX, scaleY * objScaleY))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        public bool CollidesWith(float x, float y, IViewport viewport)
        {
            var boundingBoxesComponent = _boundingBox;

            if (boundingBoxesComponent == null)
            {
                return(false);
            }
            var boundingBoxes = boundingBoxesComponent.GetBoundingBoxes(viewport);

            if (boundingBoxes == null)
            {
                return(false);
            }
            AGSBoundingBox boundingBox           = boundingBoxes.HitTestBox;
            var            pixelPerfectComponent = _pixelPerfect;
            IArea          pixelPerfect          = pixelPerfectComponent == null ? null : pixelPerfectComponent.PixelPerfectHitTestArea;

            if (_drawableInfo?.IgnoreViewport ?? false)
            {
                //todo: Support viewport rotation (+ ignore scaling areas = false?)
                x = (x - viewport.X) * viewport.ScaleX;
                y = (y - viewport.Y) * viewport.ScaleY;
            }

            if (pixelPerfect == null || !pixelPerfect.Enabled)
            {
                if (!boundingBox.IsValid)
                {
                    return(false);
                }
                if (boundingBox.Contains(new Vector2(x, y)))
                {
                    return(true);
                }
            }
            else
            {
                var   obj       = _obj;
                float objScaleX = obj == null ? 1f : obj.Animation.Sprite.ScaleX;
                float objScaleY = obj == null ? 1f : obj.Animation.Sprite.ScaleY;
                var   scale     = _scale;
                float scaleX    = scale == null ? 1f : scale.ScaleX;
                float scaleY    = scale == null ? 1f : scale.ScaleY;
                if (pixelPerfect.IsInArea(new PointF(x, y), boundingBox, scaleX * objScaleX, scaleY * objScaleY))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 4
0
        public bool CollidesWith(float x, float y, IViewport viewport)
        {
            var boundingBoxesComponent = _boundingBox;

            if (boundingBoxesComponent == null)
            {
                return(false);
            }
            AGSBoundingBox boundingBox           = boundingBoxesComponent.WorldBoundingBox;
            var            pixelPerfectComponent = _pixelPerfect;
            IArea          pixelPerfect          = pixelPerfectComponent == null || !pixelPerfectComponent.IsPixelPerfect ? null : pixelPerfectComponent.PixelPerfectHitTestArea;

            if (!(_drawableInfo?.IgnoreViewport ?? false))
            {
                var matrix = viewport.GetMatrix(_drawableInfo.RenderLayer);
                matrix.Invert();
                Vector3 xyz = new Vector3(x, y, 0f);
                Vector3.Transform(ref xyz, ref matrix, out xyz);
                //todo: (support ignore scaling areas = false?)
                x = xyz.X;
                y = xyz.Y;
            }

            if (pixelPerfect == null || !pixelPerfect.Enabled)
            {
                if (!boundingBox.IsValid)
                {
                    return(false);
                }
                if (boundingBox.Contains(new Vector2(x, y)))
                {
                    return(true);
                }
            }
            else
            {
                var   obj       = _obj;
                float objScaleX = obj == null ? 1f : obj.CurrentSprite.ScaleX;
                float objScaleY = obj == null ? 1f : obj.CurrentSprite.ScaleY;
                var   scale     = _scale;
                float scaleX    = scale == null ? 1f : scale.ScaleX;
                float scaleY    = scale == null ? 1f : scale.ScaleY;
                if (pixelPerfect.IsInArea(new PointF(x, y), boundingBox, scaleX * objScaleX, scaleY * objScaleY))
                {
                    return(true);
                }
            }
            return(false);
        }