Sign in to follow this  
ultramailman

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

I hope this will help you in taking a decision.

Share this post


Link to post
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.
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? Edited by ultramailman

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this