220 likes | 367 Views
Week 14 - Monday. CS361. Last time. What did we talk about last time? Bounding volume/bounding volume intersections. Questions?. Assignment 5. Project 4. Student Lecture: Collision Detection. Collision Detection. Collision detection.
E N D
Week 14 - Monday CS361
Last time • What did we talk about last time? • Bounding volume/bounding volume intersections
Collision detection • There are three important pieces to collision handling: • Collision detection • Did these objects collide? • Collision determination • When and where did these objects collide exactly? • Collision response • What happens as a result of the collision?
Collision detection expectations • Achieve interactive rates with complex models when those models are near and far from each other • Handle polygon soups (no guarantees about convexity or adjacency) • Assume that models can undergo rigid body transformations • Use efficient bounding volumes
Collision detection with rays • Rather than try to test complex models for collision with an environment, we can use representative rays instead • Perhaps one ray for each wheel of a car • A positive ray distance means space between the objects • A negative ray distance means collision • A zero ray distance means the objects are merely touching • It's essentially a ray tracing problem
BSP trees • Binary space partitioning trees (BSP trees) are a common way of dividing space hierarchically • For axis-aligned BSPs, one axis is chosen and a perpendicular plane is generated to divide the box • This process is repeatedly recursively until some criteria (like 3 or fewer objects per division) is reached • BSPs can also be split by choosing polygons to divide the world (usually done so as to make a perfectly balanced tree) • BSPs are good for static scenes (moving objects can cause huge portions of the tree to be recreated)
Dynamic CD with BSP trees • We look at a movement of a time step going from point p0 to p1 • We then just need to see if the line connecting those points intersects any objects (easy to do in a BSP) • We have to temporarily alter each plane's location based on the size of the bounding volume (e.g. move the plane closer by a value of r to test against a sphere with radius r) • Note: characters in games are often represented with cylinders
Hierarchical CD • We can build hierarchies using one of the three following approaches: • Bottom-up: Find nearby BVs and combine them, doing so recursively • Incremental tree-insertion:Start with an empty tree and add BVs according to what is going to add the least total volume to the tree • Top-down (most common): Find a BV for the entire model, then divide the BV into k or fewer parts, recursively • Finding a good split point is key
Multiple objects CD • Hierarchies are generally made for static scenes • Then we test against them for collisions with dynamic objects • What about when there are multiple moving objects that might interact with each other? • We work in two phases • Broad phase collision detection • Exact collision detection among candidates
Sweep-and-prune • Assume everything has an AABB or a bounding sphere • Assume temporal coherence (stuff doesn't move that much over a small amount of time) • On one dimension, we can sort the endpoints of the AABBs • We can quickly throw out objects that cannot possibly intersect • Bubble sort or insertion sort to the rescue! • We could sort everything in O(n log n) every time • Because of temporal coherence, not many end points change order and adaptive sorts work in around O(n)
Grids • Another possibility is keeping large grid cells that keep track of which objects or BVs are inside them • Objects that do not share grid cells do not need to be checked for collision • Finding the right grid cell size can be difficult • Spatial hashing can be used as well (mapping to a hash table based on location)
Putting it together • Here is an outline of a frame in a typical two-phase CD system
Time critical CD • For games and other time critical problems, it may be necessary to restrict the amount of time available for CD to a fixed value (or whatever is left of the allotted time after rendering) • When we don't know if we are going to have time to visit the entire tree hierarchy, we may want to visit the tree breadth-first
Collision response • Collision response means whatever action is done to prevent abnormal object interpenetration • Usually a bounce or something like that • It is important to find the exact time of the collision (might be in the middle of a frame) to get the correct bounce • Let velocity v = vn + vp where vn is the velocity parallel to the normal of the surface • For a perfectly elastic bounce, the new velocity is • v' = vp – vn • In real collisions, some energy is lost, described by the coefficient of restitution k, making • v' = vp – kvn
Next time… • Non-photorealistic rendering
Reminders • Finish Assignment 5 • Due on Friday • Keep working on Project 4 • Due next Friday • Read Chapter 11