Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can't work out how to find the position in which my AABB should be corresponding to my object. enter image description here

share|improve this question
The code in that picture is a little tough to read. Maybe I'm just older today than I have been previously... Consider copy/pasting it here to make it easier to read. – chaosTechnician Jun 10 '12 at 21:08
up vote 1 down vote accepted

I assume you're using that code in the picture and it's giving you the incorrect box shown on the right? The algorithm looks sound enough to find the minimum and maximum X and Y values in your list so are you sure your vertex list is properly representing the triangle you're trying to determine a box for?

It looks like your bounding box is the right size, just shifted in the X direction. Are you sure that the vertex locations you're sending are accurate for that triangle? Have you tried shifting it in different directions to make sure the disparity is consistent? What have you tried?

Additionally, I notice you aren't setting your AABB rectangle to an initial value, that's going to potentially cause a problem when setting it for some objects. Whether that's the problem here or not, I'm not sure. I'd recommend setting AABB initially to represent the first vertex you send in--so you know it starts with valid data, then iterating through the rest of the list: AABB = verts[0] (or, if Flash is different, however you'd do it there).

share|improve this answer
All the code does is calculate the extents of the vertices and puts them into a Rectangle object. I need to work out the position of the AABB relative to the vertices. Look: Notice the centre / position of the box changes as it rotates. – SyntheCypher Jun 10 '12 at 21:33
Yes, for a list of vertices, the extents are the corners of an AABB surrounding it. Here's the Wikipedia link on bounding volumes, check the paragraphs about Bounding Boxes. AABBs aren't intended to be rotated, perhaps you're looking for a different kind of bounding box? – chaosTechnician Jun 10 '12 at 22:05
BB stands for bounding box and I want an Axis-Aligned Bounding Box... – SyntheCypher Jun 10 '12 at 23:47
And the "AA" is Axis Aligned, meaning they're not intended to be rotated. If you want to rotate it with the object, consider an oriented bounding box. If you don't want it to rotate, I'm not sure what the problem is. – chaosTechnician Jun 11 '12 at 2:31

You could create the AABB using two points, from the bottom left of the triangle as a minimum point, and the maximum point being the top right, i.e. x is the point on the right, and y is the top left point.

share|improve this answer
This is all good and well but it still won't give me the position the AABB needs to be relative to the polygon. – SyntheCypher Jun 10 '12 at 21:28
@SyntheCypher it will, the bottom left corner of the triangle will be the AABBs origin, or (0,0). – Soapy Jun 10 '12 at 21:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.