CS-184: Computer Graphics Lecture #7: BSP and AABB Trees Prof. James O’Brien University of California, Berkeley V2009-F-07-1.0 BSP-Trees • Binary Space Partition Trees Split space along planes • Allows fast queries of some spatial relations • • Simple construction algorithm Select a plane as sub-tree root • Everything on one side to one child • Everything on the other side to other child • Use random polygon for splitting plane • 2 BSP-Trees a,b,c,d,e,f,g e a d f b g c 3 BSP-Trees a e d a b,c1,d f c2,e,f,g c2 b g c1 4 BSP-Trees a e d a c2,e,f,g b f d c1 c2 b g c1 5 BSP-Trees a d e1 a e2 c2 b f c1 d e1 ,f e2 ,g c2 b g c1 6 BSP-Trees a d e1 a e2 c2 b f e1 d c1 e2 ,g c2 b f g c1 7 BSP-Trees a d e1 a e2 c2 b f c1 d e1 e2 f g c2 b g c1 8 BSP-Trees a + a d b + e1 + e2 + f + c 2 c2 b + - + - c1 d e1 e2 + + f g g c1 8 BSP-Trees • Visibility Traversal Variation of in-order-traversal • Child one • Sub-tree root • Child two • Select “child one” based on location of viewpoint • Child one on same side of sub-tree root as viewpoint • 9 BSP-Trees a d e1 a e2 c2 b f d c1 e1 e2 f g c2 b g c1 c1:b:d:a:f:e1:c2:g:e2 10 BSP-Trees a d e1 a e2 c2 b f c1 d e1 e2 f g c2 b g c1 g:e2:c2:f:e1:a:c1:b:d 11 Bounding Shapes • Bounding shape completely encloses associated object • Rays cannot hit object w/o intersecting bounding shape • Two objects cannot collide if shapes don’t overlap • Simplicity -vs- tightness 12 Axis-Aligned Bounding Boxes Max x,y,z Min x,y,z • Axis-aligned bounding box defined by min and max x,y,z 13 Axis-Aligned Bounding Boxes Transform box Not axis-aligned Min/max of new points Linear cost to compute 14 Axis-Aligned Bounding Boxes Min/max of transformed BB points Constant time Adds slop Cumulative slop if multiple transforms occur sequentially Why would we do this? 15 AABB Trees One of many variations Robot Head Shape Torso Head L.Arm Mouth L.Eye R.Eye R.Arm Leg Shape Group node Geometry node Transformation stored at all nodes L.Leg R.Leg Leg Shape L.Foot RFoot 16 AABB Trees One of many variations Robot Geometry node Head Shape Torso Head L.Arm Mouth L.Eye R.Eye R.Arm Leg Shape Head Shape L.Leg L.Foot R.Leg Leg Shape RFoot Scale 2x Geometry B.Box Transformation XF B.Box 17 AABB Trees One of many variations Robot Group node Head Shape Torso Head L.Arm Mouth L.Eye R.Eye R.Arm Leg Shape L.Leg R.Leg Leg Shape L.Foot RFoot Head Rot -25 Children Union B.Box Transformation XF B.Box XF B.Box 18 AABB Trees One of many variations Robot Head Shape Torso Head L.Arm Mouth L.Eye R.Eye R.Arm Leg Shape L.Leg L.Foot R.Leg Leg Shape RFoot Local Bounding Boxes 19 AABB Trees One of many variations Robot Head Shape Torso Head L.Arm Mouth L.Eye R.Eye R.Arm Leg Shape L.Leg L.Foot R.Leg Leg Shape RFoot Transformed Bounding Boxes 20 AABB Trees One of many variations Robot Head Shape Torso Head L.Arm Mouth L.Eye R.Eye R.Arm Leg Shape L.Leg L.Foot R.Leg Leg Shape RFoot 21 AABB Trees One of many variations Robot Head Shape Torso Head L.Arm Mouth L.Eye R.Eye R.Arm Leg Shape L.Leg L.Foot R.Leg Leg Shape RFoot 22 AABB Trees One of many variations Robot Head Shape Torso Head L.Arm Mouth L.Eye R.Eye R.Arm Leg Shape L.Leg L.Foot R.Leg Leg Shape RFoot 23 AABB Trees One of many variations Robot Head Shape Torso Head L.Arm Mouth L.Eye R.Eye R.Arm Leg Shape L.Leg L.Foot R.Leg Leg Shape RFoot 24 Ray Test Against Bound Tree • RayHitSubTree(&ray,node) • If RayHitsBB(ray,node.xfBB) • ixfRay = Inverse(node.xf)*ray • If RayHitsBB(ixfRay,node.BB) • If node is group • Foreach child in node.children • RayHitSubTree(ixfRay,child) • else // node not group • RayHitGeometry(ixfRay,node.geom) • ray.collisionInfo.update(ixfRay) 25
© Copyright 2026 Paperzz