# AABB format

## Recommended Posts

ultramailman    1720
I've seen these two types of AABB:
struct aabb1{
int x, y;
int width, height;
}

struct aabb2{
int left;
int up;
int right;
int down;
}

I am used to the first type (it's what SDL uses), but recently I've encountered the second type, and the symmetry of it seems pretty attractive.

Which format for AABB is more commonly used?

##### Share on other sites
Hodgman    51223
It depends on the functions that are operating on them.
If you're using the first, but are computing 'x+width', then maybe you should be using the second.
If you're using the second, but are computing 'right-left', then maybe you should be using the first.

##### Share on other sites
0r0d    1929

I've seen these two types of AABB:

struct aabb1{
int x, y;
int width, height;
}

struct aabb2{
int left;
int up;
int right;
int down;
}

I am used to the first type (it's what SDL uses), but recently I've encountered the second type, and the symmetry of it seems pretty attractive.

Which format for AABB is more commonly used?

Whichever is more appropriate to your needs.

##### Share on other sites
Khatharr    8812
The first kind can be moved around more easily, the second kind skips a little extra math during collision detection.

You can more or less pick one and stick with it. Hodge hit it on the head, really.

##### Share on other sites
ultramailman    1720
Oh, good point. They are kind of like the complement of the each other, and I just can't have the best of both worlds, eh.

##### Share on other sites
Krohm    5030

Maybe it will help you to know how Bullet deals with the problem.

The box itself only has "half-dimensions" and is always origin-centered. Somithing like

struct AABB {
int hwidth, hheight;
}; 

This box is used to create rigid bodies, which provide a transform. In line of concept, it's like

AABB box(2, 3);
int pos[2] = {52, 37};
CollisionBody *cb = NewCollisionBody(box, pos);


I'm omitting rotations to make this super-extra-easy to understand.

##### Share on other sites
ultramailman    1720

Maybe it will help you to know how Bullet deals with the problem.
The box itself only has "half-dimensions" and is always origin-centered. Somithing like

struct AABB {
int hwidth, hheight;
}; 

This box is used to create rigid bodies, which provide a transform. In line of concept, it's like
AABB box(2, 3);
int pos[2] = {52, 37};
CollisionBody *cb = NewCollisionBody(box, pos);


I'm omitting rotations to make this super-extra-easy to understand.

Wow, another way to represent AABB. Thanks for sharing.

Is the AABB also separated into "position" and "description" inside the CollisionBody object, or are they only used as parameters for the object creation? Edited by ultramailman

##### Share on other sites
Krohm    5030

Bullet has two separated notions of Collision Shapes and Rigid Bodies (previously, Collision Objects).

While the CS itself is AABB, after using it for a rigid body, it is oriented.

The rigid body contains a pointer to the shape used to create it and a transform, besides other things such as mass and the current state. So, yes, I'd say the information is present and separated.

There are another few creation parameters which are not stored in the rigid body either, but I guess they're not relevant for the discussion.