Collision Detection & Acceleration Structures

advertisement
Collision Detection
and Acceleration
Rama Hoetzlein, 2008
Lecture Notes
Cornell University
What is Collision Detection?...
What if we have lots of objects?
What are some solutions?
1. Spatial partitioning
Spatial partitioning
Cells
1
A
B
2
E
F
3
..
n
C
D
-Each grid cell can
contain multiple objects
- How do we map
position to cell number?
2. Octree partitioning
- Insertion and retrieval are O( log n )
- What are some limitations?
3. Bounding Volumes
Bounding Volumes – 3D
• Bounding Volume (BV) – a volume that encloses a set of objects
• The idea is to use a much similar geometric shape for quick tests
(frustum culling for example)
• Easy to compute, as tight as possible
AABB
Sphere
•AABB, Sphere – easy to compute, but poor fit
OBB
Conservative Bounds
• tight → avoid
false positives
• fast to intersect
axis-aligned
bounding box
(AABB)
non-aligned
oriented bounding
box (OBB)
bounding
sphere
arbitrary convex region
(bounding half-spaces)
AABB Ray Intersection
-Many acceleration structures can
be used for both collision detection
& raytracing
t2x
tfar
y=Y2
t2y
tnear
t1x
y=Y1
t1y
x=X1
x=X2
• For all 3 axes,
calculate the intersection
distances t1 and t2
• tnear = max (t1x, t1y, t1z)
tfar = min (t2x, t2y, t2z)
• If tnear> tfar,
box is missed
• If tfar< tnclip,
box is behind
• If box survived tests,
report intersection at tnear
Bounding Volume Hierarchies
- Use hierarchicy of scene to create
a tree of bounding volumes.
- Volumes can overlap
Parent volume
Child volume
4. Binary Space Partition (BSP-Tree)
• Main purpose – depth sorting
• Consisting of a dividing plane, and a BSP tree on each
side of the dividing plane (note the recursive definition)
• The back to front traversal order can be decided right
away according to where the eye is
Binary Space Partition... cont’d.
• Two possible implementations:
Axis-Aligned BSP
Divide space along world axis.
Polygon-Aligned BSP
Divide space along scene planes.
Intersecting?
BSP Trees - Axis-Aligned (k-d tree)
• Starting with an AABB
• Recursively subdivide into small boxes
• One possible strategy: cycle through the axes
(also called k-d trees)
0
D
B
1b
2
1a
E
1a
A
A
0
C
1b
B
Q: Objects intersect the
boundaries?
C
2
D
E
BSP Trees - Polygon-Aligned
- Recursively divide space along polygons in the scene
- Each leaf is a convex, enclosed space
- Fast traversal, but slow to create.. So, create only once.
BSP Trees - Polygon-Aligned
- Combined with raycasting
- First real-time 3D first person
No slanted walls = 2D BSP
5. Axis-Aligned Sorting
What is the total run time?
.. Spatial paritioning demo..
Narrow phase
Example from Computer Games...
What is broad phase here?
What is narrow phase?
Narrow Phase: Alpha-channel Masks (for images)
Benefits?
Narrow Phase: Vector sprites (2D)
Narrow Phase: Polyhedral mesh intersection (3D)
- Hard problem
- What is the result?
- Near constant time methods exist.
Simplify. Don’t need full intersections.
Narrow Phase: Cell occupancy
Special case: Objects exactly fill a grid cell..
Applications?
Applications of Mesh Intersections:
1. Raytracing
- Ray-mesh intersection
2. Machine industry - CSG, Computational Solid Geometry
Tool part subtracts from solid part
3. Boolean Shapes
- Modeling by add / subtract / intersect
4. Games
- Real-time rigid body collisions
5. Medical
- When does instrument (scalpel, etc.)
intersect with body anatomy.
Download