Example #1
0
        public bool CollidesWith(IVector2D movement, Rectangle rectangle)
        {
            IVector2D envelopeOrigin = Origin.Add(movement);
            var envelope = new Rectangle(envelopeOrigin, Size);
            envelope = envelope.EnlargeRectangleRectangle(this);

            if (envelope.CollidesWith(rectangle))
            {
                float min = Size.X.Minimum(Size.Y) / 4.0f;
                float minimumMoveDistance = min.Maximum(Helper.Epsilon);

                if (movement.Length() < minimumMoveDistance)
                {
                    return true;
                }

                IVector2D halfMovement = movement.Divide(2.0f);

                envelope = new Rectangle(Origin.Add(halfMovement), Size);

                return CollidesWith(halfMovement, rectangle) ||
                       envelope.CollidesWith(halfMovement, rectangle);
            }

            return false;
        }
Example #2
0
        public bool CollidesWith(IVector2D movement, Rectangle rectangle)
        {
            IVector2D halfMovement = movement.Divide(2.0f);
            float movementDistance = movement.Length();
            IVector2D envelopeCenter = Center.Add(halfMovement);
            float envelopeRadius = Radius + movementDistance / 2.0f;
            var envelope = new Circle(envelopeCenter, envelopeRadius);

            if (envelope.CollidesWith(rectangle))
            {
                float minimumMoveDistance = (Radius / 4.0f).Maximum(Helper.Epsilon);

                if (movementDistance < minimumMoveDistance)
                {
                    return true;
                }

                envelope = new Circle(envelope.Center, Radius);

                return CollidesWith(halfMovement, rectangle) ||
                       envelope.CollidesWith(halfMovement, rectangle);
            }

            return false;
        }