AABB format

Started by
6 comments, last by Krohm 11 years ago
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?
Advertisement
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.

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.

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.
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.
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.

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.

I hope this will help you in taking a decision.

Previously "Krohm"

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.
I hope this will help you in taking a decision.


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?

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.

Previously "Krohm"

This topic is closed to new replies.

Advertisement