Bounding box

From Valve Developer Community
Revision as of 09:31, 3 April 2011 by TomEdwards (talk | contribs) (→‎See Also: XNA??)
Jump to navigation Jump to search
The bounding box of npc_metropolice.

A Bounding Box is an invisible box that defines the rough size of an entity. It's used to perform cheap QPhysics collision tests, often before moving on to more expensive ones: for example, bullets are only tested against hitboxes if they are first found to intersect with the given entity's bounding box.

While this optimisation is very worthwhile, it does mean that collisions with parts of an entity that protrude from a bounding box won't be properly detected: bullets will pass straight through and collisions won't occur. It's therefore important for animators, modellers and programmers to all be aware of what each other are doing, and together come to the best compromise on bounding box size.

Rotation

One other caveat of bounding boxes is that they are always aligned to the world's axes, and 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).

Object-aligned

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

Todo: How well do they work?

Defining

Source will automatically create bounding boxes. But if you need to tweak the results:

  • Modellers use the $bbox QC command.
  • Programmers call UTIL_SetSize() or CBaseEntity::SetSize() (assuming SOLID_BBOX).

Uses

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

See Also