using bsp for cd ref: bsp in deberg et al ’ s book (url)url

45
Using BSP for CD Ref: BSP in deBerg et al’s book (url)

Upload: amberlynn-stokes

Post on 03-Jan-2016

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Using BSP for CD

Ref:BSP in deBerg et al’s book (url)

Page 2: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 2

Introduction

BSP: binary space partitionCD: collision detectionEspecially useful for indoor scenes

Page 3: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 3

Kd-Tree and BSP tree

kd-tree is a special kind of bsp tree

+–

Page 4: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 4

BSP Tree Construction

Page 5: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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

Page 6: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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.

Page 7: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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.

Page 8: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 8

S3S3S2S2

S2

S2S3

S3

S1

S1

SIZE=3

Different ordering generates different trees

Different ordering generates different trees

Page 9: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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

Page 10: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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

Page 11: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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

Page 12: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 12

Painter’s Algorithm (BSP Version)

S(v) need not be drawn!

Page 13: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 13

Example Scene

Page 14: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 14

A

B

E

C

F

D

G

Page 15: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 15

A

E

C1

F

D

G

C2B2

B1

D

A B1 C1 B2 C2 EFG

+–

Page 16: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 16

A

E

C1

F

D

G

C2B2

B1

D

C1F

A B1 C2 B2 EG

Page 17: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 17

A

E

C1

F

D

G

C2B2

B1

D

C1F

B1 C2 E

G B2 A

Tree completed!Tree completed!

Page 18: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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]

Page 19: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 19

A

E

C1

F

D

G

C2

B2

B1

D

C1F

B1 C2 E

G B2 Aeye

V

hv-

hv+

Page 20: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 20

A

E

C1

F

D

G

C2

B2

B1

D

C1F

B1 C2 E

G B2 Aeye

V

C1

hv-

hv+

Page 21: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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+

Page 22: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 22

A

E

C1

F

D

G

C2

B2

B1

D

C1F

B1 C2 E

G B2 Aeye

V

B1 C1A

Page 23: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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+

Page 24: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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

+

Page 25: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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

+

Page 26: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 26

A

E

C1

F

D

G

C2

B2

B1

D

C1F

B1 C2 E

G B2 Aeye

V

B1 C1ADB2

Page 27: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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

+

Page 28: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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

Page 29: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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

+

Page 30: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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

Page 31: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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

Page 32: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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

Page 33: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 33

Collision Resolution

Better to solve a collision by deflecting the motion rather than stopping at the impact pointStepping and climbing

Page 34: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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

Page 35: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 35

Point-Scene Test

Page 36: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 36

Example

L1 L2

L3

L1

L2

L3

0<0

d0 d-r

r

Page 37: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 37

Example

L1 L2

L3

L1

L2

L3

0<0

d-r

r

d-r

Page 38: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 38

Example

L1 L2

L3

L1

L2

L3

0<0

d-r

d-r

d-r

solid

free

free

free

Page 39: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 39

Example

L1 L2

L3

L4

L5

L6

L1

L2

L5

L4

L3

L6

+–

solid

solid

free

free

free

free

free

Page 40: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 40

Ex: Tree Building1/4 L1

+–

L1

L2

L3

L7

L5

L6

L4

L2,L3,L4,L5,L6L5,L6,L7

Page 41: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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

Page 42: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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

Page 43: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

Fall 2010 43

Tree Building4/4 L1

+–

L1

L2

L3

L7

L5

L6

L4

L4L7

L6

L5

L2

L3

L5

L6

solidsolidsolid

Page 44: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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)

Page 45: Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url

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