Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url
Fall Introduction BSP: binary space partition CD: collision detection Especially useful for indoor scenes
Fall Kd-Tree and BSP tree kd-tree is a special kind of bsp tree + –
Fall BSP Tree Construction
Fall Equation at a Node Defines the hyperplane, : ax+by+cz+d=0 Subtree polygons are classified according to the coefficients stored at (internal) nodes Coefficients are often “ normalized ” for distance computation between point and plane
Fall Elements of BSP Construction Choosing the partition plane Auto-partition: choose the partition plane from the input set of polygons It is desirable to have a balanced tree, where each leaf contains roughly the same number of polygons. However, there is some cost in achieving this. Partitioning polygons If a polygon happens to span the partition plane, it will be split into two or more pieces. A poor choice of the partition plane can result in many such splits, and a marked increase in the number of polygons.
Fall Elements of BSP Construction (cont) The decision to terminate tree construction can be: when the number of polygons in a leaf node is below a maximum value. until every polygon is placed in an internal node. maximum tree depth.
Fall S3 S2 S3 S1 SIZE=3 Different ordering generates different trees
Fall S3 S2 S2b S2a S2 S3 S3a S3b S1 S2b S3bS2a S3a S1 S2b S3b S2a S3a S2bS2a S3b S3a S3b S3a S3bS3a SIZE=5
Fall Painter ’ s Algorithm What do we mean “sort in z”? That is for a triangle, what is its representative z value? Minimum z Maximum z Polygon ’ s centroid Work cost = sort + draw An object space visibility algorithm
Fall Painter ’ s Algorithm (cont) Pros: No extra memory Relatively fast Easy to understand and implement Cons: Precision issues (and additional work to handle them) Sort stage Intersecting objects
Fall Painter ’ s Algorithm (BSP Version) S(v) need not be drawn!
Fall Example Scene
Fall A B E C F D G
Fall A E C1C1 F D G C2C2 B2B2 B1B1 D A B 1 C 1 B 2 C 2 EFG + –
Fall A E C1C1 F D G C2C2 B2B2 B1B1 D C1C1 F A B 1 C 2 B 2 EG
Fall A E C1C1 F D G C2C2 B2B2 B1B1 D C1C1 F B1B1 C 2 E G B 2 A Tree completed!
Fall A E C1C1 F D G C2C2 B2B2 B1B1 D C1C1 F B1B1 C 2 E G B 2 A eye Rendering BSP [b-to-f]
Fall A E C1C1 F D G C2C2 B2B2 B1B1 D C1C1 F B1B1 C 2 E G B 2 A eye V hv-hv- hv+hv+
Fall A E C1C1 F D G C2C2 B2B2 B1B1 D C1C1 F B1B1 C 2 E G B 2 A eye V C1 hv-hv- hv+hv+
Fall A E C1C1 F D G C2C2 B2B2 B1B1 D C1C1 F B1B1 C 2 E G B 2 A eye V B1 C1 hv-hv- hv+hv+
Fall A E C1C1 F D G C2C2 B2B2 B1B1 D C1C1 F B1B1 C 2 E G B 2 A eye V B1 C1 A
Fall A E C1C1 F D G C2C2 B2B2 B1B1 D C1C1 F B1B1 C 2 E G B 2 A eye V B1 C1 A D hv-hv- hv+hv+
Fall A E C1C1 F D G C2C2 B2B2 B1B1 D C1C1 F B1B1 C 2 E G B 2 A eye V B1 C1 A D hv-hv- hv+hv+
Fall A E C1C1 F D G C2C2 B2B2 B1B1 D C1C1 F B1B1 C 2 E G B 2 A eye V B1 C1 A D hv-hv- hv+hv+
Fall A E C1C1 F D G C2C2 B2B2 B1B1 D C1C1 F B1B1 C 2 E G B 2 A eye V B1 C1 A D B2
Fall A E C1C1 F D G C2C2 B2B2 B1B1 D C1C1 F B1B1 C 2 E G B 2 A eye V B1 C1 A B2 E D hv-hv- hv+hv+
Fall A E C1C1 F D G C2C2 B2B2 B1B1 D C1C1 F B1B1 C 2 E G B 2 A eye V B1 C1 A B2 E D G
Fall A E C1C1 F D G C2C2 B2B2 B1B1 D C1C1 F B1B1 C 2 E G B 2 A eye V B1 C1 A B2 E D F G hv-hv- hv+hv+
Fall A E C1C1 F D G C2C2 B2B2 B1B1 D C1C1 F B1B1 C 2 E G B 2 A eye V B1 C1 A B2 E D F G hv-hv- hv+hv+ C2
Line Equation P 1 (x 1,y 1 ) P 2 (x 2,y 2 ) L = 0 L > 0 (left side) P(x,y) (1,0) (0,1) Check: origin on + (left) side ! Left side correspond to positive side n
Fall BSP in Games (ref)ref To account for character size, use offset planes in BSP Problems when angles between planes are large Character-environment collision detection
Fall Collision Resolution Better to solve a collision by deflecting the motion rather than stopping at the impact point Stepping and climbing
Fall Example L1 L2 L3 L1 L2 L3 (0,4) (6,0) (6,4) L1: (0,4) (6,0) L2: (6,0) (6,4) L3: (6,4) (0,4) + – solid free
Fall Point-Scene Test
Fall Example L1 L2 L3 L1 L2 L3 00 <0 d0d0 d -r r
Fall Example L1 L2 L3 L1 L2 L3 00 <0 d -r r
Fall Example L1 L2 L3 L1 L2 L3 00 <0 d -r solid free
Fall Example L1 L2 L3 L4 L5 L6 L1 L2 L5 L4 L3 L6 + – solid free
Fall Ex: Tree Building 1/4 L1 + – L2 L3 L7 L5 L6 L4 L2,L3,L4,L5,L6L5,L6,L7
Fall Tree Building 2/4 L1 + – L2 L3 L7 L5 L6 L4 L2,L3,L4,L5,L6L5,L6,L7 L4 L2,L3 L5,L6 L7 L5,L6
Fall Tree Building 3/4 L1 + – L2 L3 L7 L5 L6 L4 L2,L3 L5,L6 L7 L6 L5 L2 L3 L5 L6
Fall Tree Building 4/4 L1 + – L2 L3 L7 L5 L6 L4 L7 L6 L5 L2 L3 L5 L6 solid
Fall Dynamic Scenes Moving camera: no problem Moving objects: Fuchs et. al. was to specify a bounding polygon around the area that of the scene that would be changing. Doom: use z-buffer for for dynamic objects (missiles and bullets) Adding objects: no problem Deleting objects: BIG problem (ref)ref
Fall [BSP & Ray Tracing] Speed up ray tracing by: Reaching leaf nodes Determine face through which ray exits Find region-binding faces: collect all parental halfplanes Compute exit points Extending ray into next region … until the ray shoots into infinity reference