Share via


BoundingBox Structure

Defines an axis-aligned box-shaped 3D volume.

Namespace: Microsoft.Xna.Framework
Assembly: Microsoft.Xna.Framework (in microsoft.xna.framework.dll)

Syntax

[TypeConverterAttribute("typeof(Microsoft.Xna.Framework.Design.BoundingBoxConverter)")]
[SerializableAttribute]
public struct BoundingBox : IEquatable<BoundingBox>

Remarks

The BoundingBox Structure represents the space occupied by a box. The bounding box class is axis aligned. Each face of the bounding box is perpendicular to the x-axis, the y-axis, or the z-axis.

There are several benefits of using the bounding box for collision detection.

  • The bounding box class fits rectangular shapes aligned with the axis very well. Compared to the bounding sphere class, the bounding box class provides a much tighter fit for non-rotated rectangular objects.
  • Because the bounding box class is axis aligned, you can make certain assumptions that result in collision checks between bounding boxes being quicker than a bounding box that can be rotated.

There are a few drawbacks of using the bounding box for collision detection.

  • Rotating a bounding box causes it to no longer be axis aligned. Because of this, if you rotate a model being bounded, you will need to recreate the bounding box. Doing so can be slow, since all the points in an object are iterated through to get the bounding box. If the model has not changed orientation, you can translate the bounding box instead of recreating it.
  • If the model being bounded is not aligned to the axis, the bounding box will have some empty space. The amount of empty space will be greatest when the object is rotated 45 degrees from an axis.
  • Empty space in the bounding box can result in false positives when checking for collision.

See Also

Concepts

Collision Detection Overview
Math Overview

Tasks

How to: Detect Whether Two Models Collide
How to: Position the Camera to View All Objects in a Scene

Reference

BoundingBox Members
Microsoft.Xna.Framework Namespace

Platforms

Xbox 360, Windows XP SP2, Windows Vista