Example #1
0
        public bool AxisCollision(Vector2 axis, SATRectangle otherEntity)
        {
            List<int> ScalarsA = new List<int>();
            List<int> ScalarsB = new List<int>();

            ScalarsA.Add(GenerateScalar(otherEntity.TopLeftCorner, axis));
            ScalarsA.Add(GenerateScalar(otherEntity.TopRightCorner, axis));
            ScalarsA.Add(GenerateScalar(otherEntity.BottomLeftCorner, axis));
            ScalarsA.Add(GenerateScalar(otherEntity.BottomRightCorner, axis));

            ScalarsB.Add(GenerateScalar(TopLeftCorner, axis));
            ScalarsB.Add(GenerateScalar(TopRightCorner, axis));
            ScalarsB.Add(GenerateScalar(BottomLeftCorner, axis));
            ScalarsB.Add(GenerateScalar(BottomRightCorner, axis));

            int MinA = ScalarsA.Min();
            int MaxA = ScalarsA.Max();
            int MinB = ScalarsB.Min();
            int MaxB = ScalarsB.Max();

            if (MinB <= MaxA && MaxB >= MaxA)
                return true;
            else if (MinA <= MaxB && MaxA >= MaxB)
                return true;

            return false;
        }
Example #2
0
        public bool Intersects(SATRectangle otherEntity)
        {
            // Calculate the axes to be projected
            List<Vector2> axes = new List<Vector2>();
            axes.Add(TopRightCorner - TopLeftCorner);
            axes.Add(TopRightCorner - BottomRightCorner);
            axes.Add(otherEntity.TopLeftCorner - otherEntity.BottomLeftCorner);
            axes.Add(otherEntity.TopLeftCorner - otherEntity.TopRightCorner);

            foreach (Vector2 axis in axes)
            {
                if (!AxisCollision(axis, otherEntity))
                    return false;
            }
            return true;
        }