Example #1
0
        public IntersectData IntersectsAABB(AABB _other)
        {
            IntersectData IntersectData = new IntersectData();
            IntersectData.collider = _other;

            return IntersectData;
        }
Example #2
0
        public IntersectData IntersectsAABB(AABB _other)
        {
            IntersectData IntersectData = new IntersectData();
            IntersectData.collider = _other;

            float deltaX = _other.center.X - center.X;
            float pointX = (_other.dimensions.X / 2 + dimensions.X / 2) - Math.Abs(deltaX);

            if (pointX <= 0)
            {
                IntersectData.collision = false;
                return IntersectData;
            }

            float deltaY = _other.center.Y - center.Y;
            float pointY = (_other.dimensions.Y / 2 + dimensions.Y / 2) - Math.Abs(deltaY);

            if (pointY <= 0)
            {
                IntersectData.collision = false;
                return IntersectData;
            }

            if (pointX < pointY)
            {
                float sx = Math.Sign(deltaX);
                IntersectData.Delta = new Vector2(pointX * sx, 0f);
                IntersectData.Normal = new Vector2(sx, 0);
                IntersectData.Point = new Vector2(center.X + ((dimensions.X / 2) * sx), _other.center.Y);
            }
            else
            {
                float sy = Math.Sign(deltaY);
                IntersectData.Delta = new Vector2(0f, pointY * sy);
                IntersectData.Normal = new Vector2(0f, sy);
                IntersectData.Point = new Vector2(_other.center.X, center.Y + ((dimensions.X / 2) * sy));
            }

            IntersectData.collision = true;
            return IntersectData;
        }