Sign in to follow this  
ankhd

Having Trouble converting a Rectangle to a AABB

Recommended Posts

Hi all, I've looked all over the place all day. I have this RECT {0, 0, 5120, 5120} now to convert this to a AABB is this the right way AABB.min.x = 0; AABB.min.y = 0; AABB.min.z = 0; AABB.max.x = 5120; AABB.max.y = 10; AABB.max.z = 5120; please need help I can Get it to work if I use D3DXCreateBox and then use D3DXComputeBoundingBox with bounds but I cant keep calling this all the time in the render function.

Share this post


Link to post
Share on other sites
(asuming C++ here)

that rect initialisation initialises like so

RECT r = {left, top, right, bottom}
RECT r = {0, 0, 5120, 5120}


(from http://msdn2.microsoft.com/en-us/library/a5ch4fda(VS.71).aspx )

therefore your bounding box should look more like

AABB.min.x = r.left;
AABB.min.y = r.bottom;

AABB.max.x = r.right;
AABB.max.y = r.top

No idea where you're grabbing your z components from, but that's the AABB based on the XY dimensions.

Share this post


Link to post
Share on other sites
Quote:
Original post by Winegums
your bounding box should look more like

AABB.min.x = r.left;
AABB.min.y = r.bottom;

AABB.max.x = r.right;
AABB.max.y = r.top


This will make the AABB's width and height be twice the amount of the RECT. Also, with RECTs, bottom is greater than top (because in screen coordinates, y increases down). So it should be:

AABB.min.x = r.left / 2.0f;
AABB.min.y = r.top / 2.0f;

AABB.max.x = r.right / 2.0f;
AABB.max.y = r.bottom / 2.0f;

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