示例#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;
        }
示例#2
0
        public static scBoundingBox createFromPositionAndHalfExtents(Vector2 position, Vector2 halfExtents)
        {
            var boundingBox = new scBoundingBox();
            boundingBox.position = position;
            boundingBox.halfExtents = halfExtents;

            return boundingBox;
        }
示例#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;
        }
示例#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);
        }
示例#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;
        }
示例#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);
 }