CS361

24
CS361 Week 14 - Monday

description

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. - PowerPoint PPT Presentation

Transcript of CS361

Page 1: CS361

CS361Week 14 - Monday

Page 2: CS361

Last time

What did we talk about last time? Bounding volume/bounding volume

intersections

Page 3: CS361

Questions?

Page 4: CS361

Assignment 5

Page 5: CS361

Project 4

Page 6: CS361

Student Lecture:Collision Detection

Page 7: CS361

Collision Detection

Page 8: CS361

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?

Page 9: CS361

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

Page 10: CS361

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

Page 11: CS361

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)

Page 12: CS361

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

Page 13: CS361

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

Page 14: CS361

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

Page 15: CS361

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)

Page 16: CS361

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)

Page 17: CS361

Putting it together

Here is an outline of a frame in a typical two-phase CD system

Page 18: CS361

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

Page 19: CS361

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

Page 20: CS361

Sphere on sphere collision Dealing with spheres is the simplest because their

point of intersection is easy to calculate First, compute collision vector (line between sphere

centers) Divide sphere velocities into two parts:

Perpendicular to collision Parallel to collision

Only the perpendicular velocity changes

Page 21: CS361

Updating the velocities Once you have the velocities that change,

you can do the math in a single dimension In a perfectly elastic collision, both

momentum and energy are conserved Let m1 and m2 be the masses of the objects u1 and u2 are their velocities before impact v1 and v2 are their velocities after impact

Page 22: CS361

Upcoming

Page 23: CS361

Next time…

Non-photorealistic rendering

Page 24: CS361

Reminders

Finish Assignment 5 Due on Friday

Keep working on Project 4 Due next Friday

Read Chapter 11