Beispiel #1
0
        public bool contains(scBoundingBox other)
        {
            var deltaUpperLeft = other.upperLeft - upperLeft;
            var deltaLowerRight = lowerRight - other.lowerRight;

            return deltaUpperLeft.X >= 0 && deltaUpperLeft.Y >= 0 && deltaLowerRight.X >= 0 && deltaLowerRight.Y >= 0;
        }
Beispiel #2
0
        public static scBoundingBox createFromPositionAndHalfExtents(Vector2 position, Vector2 halfExtents)
        {
            var boundingBox = new scBoundingBox();
            boundingBox.position = position;
            boundingBox.halfExtents = halfExtents;

            return boundingBox;
        }
Beispiel #3
0
        public static scBoundingBox createFromBoundingVertices(Vector2 upperLeft, Vector2 lowerRight)
        {
            var boundingBox = new scBoundingBox();
            boundingBox.halfExtents = (lowerRight - upperLeft) / 2.0f;
            boundingBox.position = upperLeft + boundingBox.halfExtents;

            return boundingBox;
        }
Beispiel #4
0
        public static scBoundingBox union(scBoundingBox first, scBoundingBox second)
        {
            Vector2 firstUpper = first.upperLeft;
            Vector2 firstLower = first.lowerRight;
            Vector2 secondUpper = second.upperLeft;
            Vector2 secondLower = second.lowerRight;

            var newUpper = new Vector2(Math.Min(firstUpper.X, secondUpper.X), Math.Min(firstUpper.Y, secondUpper.Y));
            var newLower = new Vector2(Math.Max(firstLower.X, secondLower.X), Math.Max(firstLower.Y, secondLower.Y));
            return createFromBoundingVertices(newUpper, newLower);
        }
Beispiel #5
0
        public static Rectangle toXNARectangle(scBoundingBox boundingBox)
        {
            var rectangle = new Rectangle();
            Vector2 upperLeft = boundingBox.upperLeft;
            Vector2 lowerRight = boundingBox.lowerRight;
            Vector2 size = lowerRight - upperLeft;

            rectangle.Offset((int)upperLeft.X, (int)upperLeft.Y);
            rectangle.Width = (int)size.X;
            rectangle.Height = (int)size.Y;

            return rectangle;
        }
Beispiel #6
0
 public static bool overlaps(scBoundingBox first, scBoundingBox second)
 {
     return first.contains(second.upperLeft)
         || first.contains(second.upperRight)
         || first.contains(second.lowerLeft)
         || first.contains(second.lowerRight)
         || second.contains(first.upperLeft)
         || second.contains(first.upperRight)
         || second.contains(first.lowerLeft)
         || second.contains(first.lowerRight);
 }