This article's documentation is for anything that uses the Source engine. Click here for more information.

Bounding box

From Valve Developer Community
Jump to navigation Jump to search

English (en)Español (es)Русский (ru)中文 (zh)Translate (Translate)
Graph of "mins" and "maxs"

A bounding box (Axis-Aligned Bounding Box and Oriented Bounding Box) is an automatically-created invisible box that defines the rough size of an entity. Its purpose is to perform cheap QPhysics collision/trigger test before moving on to more expensive (collision mesh & hitbox) calculations.

As shown in the graph, a bounding box is compromised of two sets of XYZ coordinates: "mins" and "maxs." Both mins and maxs represent the offset from the bound's origin, where mins is always in the (-) negative XYZ direction, and maxs is always in the (+) positive. The sum of the offsets mins and maxs equal the dimensions of the bounding box (see taxicab distance).

Note.pngNote: Positions of mins & max is relative position to the parent not the world

Bounding boxes can be seen used with:

  • QPhysics collision detection (mainly NPCs and players)
  • Prerequisite for hitbox collision detection
  • Line of sight tests
  • Visleaves occupied by an entity

If a bounding box needs to be overridden manually, these can be done:

  • Modellers use the $bbox QC command
  • Mappers and scripters use the mins and maxs keys, if the solid key is set to 2
  • Programmers call the functions UTIL_SetSize() or CBaseEntity::SetSize()
Note.pngNote: Entity parts that protrude its bounding box will not pass QPhysics collision tests. This includes hitboxes.

Rotation

Bounding boxes are always aligned to the world's axes; they never rotate. This is presumably because of their use for collision detection of players: it would be impossible to turn around in a tight corridor if the four corners of your bounding box rotated with you. Axis-aligned boxes are also far cheaper to compute.

While this isn't a huge issue for objects that are roughly square from above, it makes oblong dimensions difficult to manage without switching to VPhysics. When VPhysics isn't an option there isn't much that can be done: a Day of Defeat: Source player who has gone prone has an oblong shape that can rotate through a full 360°, which Valve could only accommodate for by creating a "squished" bounding box that leaves the head and feet sticking out at all times (an image of this would be nice).

Todo: Image

Object-Aligned

Object-aligned bounding boxes rotate with their entity. They appear to be linked to VPhysics to some extent.

Todo: Is there more to describe, like how well do they work? Merge with earlier section if there isn't anything else.

Industry Terms

Source and its community does not make use of all the industry terms to bounding boxes, however development in or outside Source may use these variants of bounding box terms: AABB and OBB, or Axis-Aligned Bounding Box and Oriented Bounding Box.

AABB
"a 3D volume relative to a given origin", a box that is not rotated. Its name is due to the fact that all its edges are parallel to the axes it is aligned to. In most cases including Source, a bounding box is an AABB, as it's very simple to test for intersections—an AABB cannot rotate with its model, only requiring a simple position update. In cases where a bounding box rotates along with its model it is referred to as an OBB.
OBB
"a 3D volume relative to a given origin and angle", a box that is rotated. [Clarify]

Debug-Based

npc_metropolice with ent_bbox.

Bounding boxes are quite involved in debugging; there are not only tools that visualize bounding boxes, but also tools that rely on bounding boxes to work.

Console commands that relate to bounding boxes:

ent_bbox
Visualizes an entity's bounding box, either the one you look at (!picker), a targetname, or a classname.
ent_absbox
Visualizes an entity's AABB, either the one you look at, a targetname, or a classname.

Programmer functions that are related:

  • UTIL_EntitiesInBox - Find all entities within a given bounding box.
  • NDebugOverlay::Box - Draw a box with the given mins and maxs. In Squirrel/Lua, the function DebugDrawBox() may be available.


Console Commands

Box
Draws a box of red lines by specifying 2 corners' coordinates as parameter. It's axis aligned and lasts for 100 seconds before disappearing.

QC

Functions

OBBCenter()
Returns a local vector of the centre of a Bounding Box, interpolates a line between mins and max and returns the half way point.

General

Resources

See also