Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

How can I generate AABB, OOBB and Sphere from a polygon soup, where the bounding volumes are defined as follows:

  • AABB should be specified by min(x,y,z) max(x,y,z)
  • OOBB should be specified by min(x,y,z) max(x,y,z) and a quaternion for rotation
  • Sphere is specified as position(x,y,z) and radius
share|improve this question
    
OBB cannot be specified by min and max. –  concept3d Nov 16 '13 at 13:40
    
@concept3d How can they be specified then? –  Soapy Nov 16 '13 at 14:00
    
OBB are bounding boxes that are oriented with the object. That means you'll need to define an orientation for your soup. It could be the same as the AABB to start with. Or it could be defined by some other rules, like the direction from the average center to the vertex density center. Totally up to you. –  Byte56 Nov 16 '13 at 18:22
    
@Byte56 So the orientation could be represented by a quaternion? –  Soapy Nov 16 '13 at 19:06
    
Yes. OOBB is similar to a AABB except it rotates with the object. So when the object is at the "default" position, or its local axis is aligned to that of the global axis, the OOBB and AABB are the same bounds. You need to have the rotation defined if you want to get the OOBB. You can do that with a quaternion. –  Byte56 Nov 16 '13 at 19:13
add comment

1 Answer

up vote 2 down vote accepted

Iterate through your soup and collect the following information:

  • Per vertex:
    • Maximum and Minimum x, y and z values

Something like:

for each polygon in soup
    for each vertex in polygon
        if vertex.x > maxX
           maxX = vertex.x
        if vertex.x < minX
           minX = vertex.x

        // and so on for y and z

sphereCenter = minX + (maxX-minX)/2, minY + (maxY-minY)/2, minZ + (maxZ-minZ)/2 
sphereRadius = max((maxX-minX)/2,(maxY-minY)/2,(maxZ-minZ)/2)
boundMin = minX, minY, minZ
boundMax = maxX, maxY, maxZ

That gives you both the bounding sphere and the AABB bounding box.

In order to get an OOBB you'll need some kind of orientation information for the soup. Then you'll have to find the center of the soup, negate the orientation information by rotating all the vertices in the soup around the common center. Now you have an axis aligned soup. You can perform the same steps as above, then rotate everything (including the eight corners of the axis aligned bounding box) back around the common center.

share|improve this answer
    
That will definitely get you a bounding sphere, though not necessarily the smallest one. If you want to get fancy, have a look at en.wikipedia.org/wiki/Smallest-circle_problem –  Incredulous Monk Nov 20 '13 at 23:30
    
That's true. It'll probably get close enough for this problem, but thanks for the link that's an interesting topic. –  Byte56 Nov 20 '13 at 23:37
add comment

Your Answer

 
discard

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.