using bsp for cd ref: bsp in deberg et al ’ s book (url)url
TRANSCRIPT
Using BSP for CD
Ref:BSP in deBerg et al’s book (url)
Fall 2010 2
Introduction
BSP: binary space partitionCD: collision detectionEspecially useful for indoor scenes
Fall 2010 3
Kd-Tree and BSP tree
kd-tree is a special kind of bsp tree
+–
Fall 2010 4
BSP Tree Construction
Fall 2010 5
Equation at a Node
Defines the hyperplane, : ax+by+cz+d=0Subtree polygons are classified according to the coefficients stored at (internal) nodesCoefficients are often “normalized” for distance computation between point and plane 222
000),,,(cba
dczbyaxzyxd
Fall 2010 6
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 2010 7
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 2010 8
S3S3S2S2
S2
S2S3
S3
S1
S1
SIZE=3
Different ordering generates different trees
Different ordering generates different trees
Fall 2010 9
S3
S2
S2b
S2a
S2
S3
S3a
S3bS1
S2b S3b S2a S3a
S1
S2b S3b S2a S3aS2b S2a
S3b S3aS3b S3aS3b S3a
SIZE=5
Fall 2010 10
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 + drawAn object space visibility algorithm
Fall 2010 11
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 2010 12
Painter’s Algorithm (BSP Version)
S(v) need not be drawn!
Fall 2010 13
Example Scene
Fall 2010 14
A
B
E
C
F
D
G
Fall 2010 15
A
E
C1
F
D
G
C2B2
B1
D
A B1 C1 B2 C2 EFG
+–
Fall 2010 16
A
E
C1
F
D
G
C2B2
B1
D
C1F
A B1 C2 B2 EG
Fall 2010 17
A
E
C1
F
D
G
C2B2
B1
D
C1F
B1 C2 E
G B2 A
Tree completed!Tree completed!
Fall 2010 18
A
E
C1
F
D
G
C2
B2
B1
D
C1F
B1 C2 E
G B2 Aeye
Rendering BSP [b-to-f]
Fall 2010 19
A
E
C1
F
D
G
C2
B2
B1
D
C1F
B1 C2 E
G B2 Aeye
V
hv-
hv+
Fall 2010 20
A
E
C1
F
D
G
C2
B2
B1
D
C1F
B1 C2 E
G B2 Aeye
V
C1
hv-
hv+
Fall 2010 21
A
E
C1
F
D
G
C2
B2
B1
D
C1F
B1 C2 E
G B2 Aeye
V
B1 C1
hv-
hv+
Fall 2010 22
A
E
C1
F
D
G
C2
B2
B1
D
C1F
B1 C2 E
G B2 Aeye
V
B1 C1A
Fall 2010 23
A
E
C1
F
D
G
C2
B2
B1
D
C1F
B1 C2 E
G B2 Aeye
V
B1 C1AD
hv-
hv+
Fall 2010 24
A
E
C1
F
D
G
C2
B2
B1
D
C1F
B1 C2 E
G B2 Aeye
V
B1 C1AD
hv- hv
+
Fall 2010 25
A
E
C1
F
D
G
C2
B2
B1
D
C1F
B1 C2 E
G B2 Aeye
V
B1 C1AD
hv-hv
+
Fall 2010 26
A
E
C1
F
D
G
C2
B2
B1
D
C1F
B1 C2 E
G B2 Aeye
V
B1 C1ADB2
Fall 2010 27
A
E
C1
F
D
G
C2
B2
B1
D
C1F
B1 C2 E
G B2 Aeye
V
B1 C1AB2 E D
hv-hv
+
Fall 2010 28
A
E
C1
F
D
G
C2
B2
B1
D
C1F
B1 C2 E
G B2 Aeye
V
B1 C1AB2 E D
G
Fall 2010 29
A
E
C1
F
D
G
C2
B2
B1
D
C1F
B1 C2 E
G B2 Aeye
V
B1 C1AB2 E DFG
hv- hv
+
Fall 2010 30
A
E
C1
F
D
G
C2
B2
B1
D
C1F
B1 C2 E
G B2 Aeye
V
B1 C1AB2 E DFG
hv- hv
+
C2
Line Equation
P1(x1,y1)
P2(x2,y2)
L = 0L > 0 (left side)
P(x,y)
(1,0)
(0,1)
01
01,11,1
00,110),01(
yx
yxyx
yx
Check: origin on + (left) side !
Left side correspond to positive side
0
0,,
0:)(0:
90cos90sin
90sin90cos90,
1211211212
111212
11
12
12
12
1221
xxyyyxyxxxyy
yyxxxxyy
PPnsideleftPPnline
xx
yy
yy
xxPProtn
n
Fall 2010 32
BSP in Games (ref)
•To account for character size, use offset planes in BSP•Problems when angles between planes are large
Character-environment collision detection
Fall 2010 33
Collision Resolution
Better to solve a collision by deflecting the motion rather than stopping at the impact pointStepping and climbing
Fall 2010 34
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
free
free
Fall 2010 35
Point-Scene Test
Fall 2010 36
Example
L1 L2
L3
L1
L2
L3
0<0
d0 d-r
r
Fall 2010 37
Example
L1 L2
L3
L1
L2
L3
0<0
d-r
r
d-r
Fall 2010 38
Example
L1 L2
L3
L1
L2
L3
0<0
d-r
d-r
d-r
solid
free
free
free
Fall 2010 39
Example
L1 L2
L3
L4
L5
L6
L1
L2
L5
L4
L3
L6
+–
solid
solid
free
free
free
free
free
Fall 2010 40
Ex: Tree Building1/4 L1
+–
L1
L2
L3
L7
L5
L6
L4
L2,L3,L4,L5,L6L5,L6,L7
Fall 2010 41
Tree Building2/4 L1
+–
L1
L2
L3
L7
L5
L6
L4
L2,L3,L4,L5,L6L5,L6,L7
L4
L2,L3L5,L6
L7
L5,L6
Fall 2010 42
Tree Building3/4 L1
+–
L1
L2
L3
L7
L5
L6
L4
L4
L2,L3L5,L6
L7
L6
L5
L2
L3
L5
L6
Fall 2010 43
Tree Building4/4 L1
+–
L1
L2
L3
L7
L5
L6
L4
L4L7
L6
L5
L2
L3
L5
L6
solidsolidsolid
Fall 2010 44
Dynamic Scenes
Moving camera: no problemMoving 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 problemDeleting objects: BIG problem (ref)
Fall 2010 45
[BSP & Ray Tracing]
Speed up ray tracing by:Reaching leaf nodesDetermine face through which ray exits
Find region-binding faces: collect all parental halfplanes
Compute exit pointsExtending ray into next region
… until the ray shoots into infinity
reference