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
Answer
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.
No comments:
Post a Comment