What is AABB - Collision detection?
Asked Answered
T

2

64

Hi I'm making a voxel game in Java and while researching all the different things I'd need to learn, I noticed that a lot of games use AABB for collision detection. And then I remembered seeing AABB in Minecraft also. But when I google what AABB is, it only comes up with other peoples code, or some organization out the history book. Stackoverflow, what is AABB?

Tosh answered 19/3, 2014 at 16:32 Comment(0)
B
76

AABB stands for "Axis-Aligned Bounding Box."

It is a fairly computationally- and memory-efficient way of representing a volume, typically used to see if two objects might be touching.

Since it is axis-aligned, it does not necessarily "fit" your real 3D object very well. AABB checks are often used as a coarse first-approximation to see if objects might be colliding. Then, if the AABB check passes, more detailed checks are made.

Example:

Imagine your world is 2D, and you draw it on a sheet of graph paper. You have some objects in the world (a ball, a tree, whatever). To make an AABB for one of the objects, you draw a rectangle around the object, making your lines parallel to the grid lines on the paper.

If you have the AABB for two objects, you can do some pretty simple math to see if those AABBs overlap. If they don't overlap, those two objects couldn't possibly be touching, so it's an easy early-out for your collision algorithm.

This generalizes to 3D (and more-Ds) fairly easily.

You might want to check out gamedev.stackexchange.com, too.

Backstay answered 19/3, 2014 at 16:35 Comment(2)
also since a voxel game is mostly cubes i dont think that it being axis-aligned is a problem though if i were making an rpg and i wanted my person to look realistic withought hitting a wall that is a fair distance away...Tosh
@FeatheredOrcian: Yes, if your voxels are already axis-aligned, then AABBs are great. You might not even need to store them separately, but could derive their data from your voxel data.Backstay
F
10

Axis Aligned Bounding Box

Basically its the smallest Axis Aligned Cuboid that can completely contain the shape. It is usually defined by a pair of 3d co-ordinates.

It's very fast to check for collisions between two AABB as all you need to do is check the range of the X, Y and Z values for the corners so that is used as a fast first-step to prune the number of possible collisions where a more sophisticated but computationally intensive way can be used.

Foolhardy answered 19/3, 2014 at 16:35 Comment(3)
How is this correct? Shouldn't oriented bounding boxes be the the smallest cuboid that can contain the shape? Axis aligned bounding box is the smallest cuboid aligned with the global axis that can completely contain the shape.Cantone
oriented boxes are smaller, but they are slower to test. If you get AABB collision you continue with some more refined collision method test - for example stencil buffer test.Narco
Yes, I should have said - the smallest Axis Aligned cuboid, I've added that.Foolhardy

© 2022 - 2024 — McMap. All rights reserved.