collision response jim van verth ([email protected])

45
Collision Response Jim Van Verth ([email protected])

Upload: norma-lakeman

Post on 28-Mar-2015

233 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Collision Response Jim Van Verth (jim@essentialmath.com)

Collision Response

Jim Van Verth ([email protected])

Page 2: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Collision Response

• Physical response to collision

• Two main cases Colliding (opposing velocities)

• Bouncing

Resting (orthogonal velocities)• Rolling, sliding

Page 3: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Contact Point

• Need location of point of collision and normal to surface at actual time of collision

• We might not have this

• Objects could be interpenetrating

Page 4: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Determine Collision Time

• Do binary search Back off simulation half of previous time

step• Still penetrating? Back off ¼ time step• No collision? Move forward ¼ time step

Continue until time step too small or exact collision found

• Slow, may not find exact point

Page 5: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Determining Collision Time

• Or just fake it

• Determine penetration distance

• Push objects away until they just touch

• Can use mass, velocities to adjust how much each moves (if’n you feel fancy)

• Problem: can cause a new collision this way

Page 6: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Determining Collision Time

• Alternative: push apart a little, use collision response to do the rest

• Assumes collision response can handle penetration

• Apply force (penalty force) to push them apart

Page 7: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Determining Collision Time

• Or use predictive method to determine time of impact (TOI)

• Integrate up to TOI

• Do collision response

• Find next TOI, integrate, respond, repeat until done

Page 8: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Determining Collision Time

• Ex: spheres

• Spheres sweep out capsules, intersect?

Page 9: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Determining Collision Time

• Or: relative velocity• Compare sphere vs. capsule

• Sphere centers Pa, Pb; radii ra, rb

• Relative velocity v = va- vb

Sa

Sb

Page 10: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Determining Collision Time

• Idea: determine point(s) on velocity line distance ra+rb from Pb

• Or: ||Pb – (Pa+vt)|| = ra+rb

• Or: (w – vt)•(w – vt) – (ra+rb)2 = 0; w = Pb – Pa

• Quadratic: solve for t

Sa

Sb

Page 11: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Determining Collision Time

• Expand (w – vt)•(w – vt) – (ra+rb)2 = 0

• Get (v•v)t2 – 2(v•w)t + w•w – (ra+rb)2 = 0

• Use quadratic equation, get

Page 12: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Determining Collision Time

• Could be 1 solution Just touching, radical = 0

• Could be no solutions Never touch, radical is imaginary

• Pick solution with smallest t 0, 1

Page 13: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Have Collision, Will Travel

• Have normal n (from object A to object B), collision point P, velocities va, vb

• Three cases: Separating

• Relative velocity along normal < 0

Colliding• Relative velocity along normal > 0

Resting• Relative velocity along normal = 0

Page 14: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Linear Collision Response

• Have normal n, collision point p, velocities v1, v2

• How to respond?• Idea: collision is discontinuity in velocity• Generate impulse along collision normal

– modify velocities• How much depends on incoming

velocity, masses of objects

Page 15: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Linear Collision Response

• Do simple case – two spheres a & b incoming velocities va,vb

collision normal n want to compute impulse magnitude f

n

va

vb

Page 16: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Linear Collision Response

• Compute relative velocity vab

n

va

vb

vab

Page 17: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Linear Collision Response

• Compute velocity along normal Use dot product to project onto normal

n

vab

vn

Page 18: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Linear Collision Response

• Outgoing velocity dependant on coefficient of restitution

= 1: pure elastic collision (superballs) = 0: pure non-elastic collision (clay)

or

Page 19: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Linear Collision Response

• Also need to conserve momentum

or

and

or

Page 20: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Linear Collision Response

• Combining last two slides (with a wave of my hand) gives

Page 21: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Linear Collision Response

• Compute final velocities

n

va-

vb- vb

+

va+

Page 22: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Angular Collision Response

• Like linear, but include angular velocity

• Compute velocity at collision point

vb

va

ra rba

b

Page 23: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Angular Collision Response

• Need to conserve angular momentum

and

or

and

or

Page 24: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Angular Collision Response

• Final impulse equation (more waving of hands)

Page 25: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Angular Collision Response

• Compute new angular momentum

remember, sim uses angular momentum

• Then angular velocity from momentum

Page 26: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Multiple Colliding Contacts

• 3-body problem (kinda)

• Do one at a time, will end up with penetration

• What to do?

Page 27: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Multiple Colliding Contacts

• One solution: Do independently Handle penetration as part of collision

resolution

• Another solution: Generate constraint forces Use relaxation techniques

Page 28: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Multiple Colliding Contacts

• Crunchy math solution• Build systems of equations where

• , normal component of rel. vel. before & after

• ai,j describes how body j affects impulse on body i

• Get matrix equation:

Page 29: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Multiple Colliding Contacts

• Results coupled – want “as close as possible” If (separating) want close to If (colliding) want close to

• Represent difference by new vector b If then If then

Page 30: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Multiple Colliding Contacts

• Now want to minimize length of vector

• Impulses are non-positive so want• Also want • Quadratic programming problem• Can convert to Linear Complementary

Problem (LCP) – use Lemke’s Algorithm

Page 31: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Resting Contacts

• Mirtich & Canny use micro-impulses, simulate molecular micro-collisions

• Works with current impulse system

Page 32: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Resting Contacts

• Impulses work, but can be kind of jittery• Forces generate velocity into object• Counteract in next frame – but still move a bit

• One solution: once close to rest, turn off simg

Page 33: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Resting Contact

• Velocity along normal is 0, so look at forces along normal

• If will push together, counteract with new constraint force C = gn, g < 0

• Want acceleration along normal• If will eventually push apart, want g = 0

• So want: ≤ 0, g ≤ 0, g = 0

Page 34: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Resting Contact

• Can build expression for :

Page 35: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Resting Contact

• Expand out, end up with expression like

• Ag repr. acceleration due to response • b repr. acceleration due to other forces

• Remember, want ≤ 0, g ≤ 0, g = 0

• If b > 0, then g = -b/A, = 0

• If b ≤ 0, then g = 0, = b

Page 36: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Resting Contact

• Simple example: assume object on ground, only linear forces

• If b > 0, then Counteracts force along normal

• If b ≤ 0, then C = 0

Page 37: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Resting Contact

• Things get a lot more complicated if both move, and angular terms

• See Eberly for the full details

Page 38: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Multiple Resting Contacts

• Can have stacks of stuff

• What to do then?

Page 39: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Multiple Resting Contacts

• Build systems of equations where

• Get matrix equation

where , ,• A is the same as with colliding contacts!

• Another LCP problem – use Lemke’s

Page 40: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Resting Contacts

• Resting contact is a hard problem

• Very susceptible to floating point error, jittering

• Don’t do more than application needs

• Don’t get discouraged

Page 41: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Contact Friction

• Generate force opposed to velocity

• For contact: tangential relative velocity

• Magnitude is relative to normal force

• If using impulses, can ignore normal force, use constant

Page 42: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Putting It Together

1. Compute forces, torques on objects

2. Determine collisions

3. Adjust velocities, forces, torques based on collision

4. Predict future collision

5. Step ahead to future collision (if any) or fixed step (if not)

Page 43: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

Recap

• Try to keep objects non-penetrating

• Colliding objects get impulses

• Resting objects either micro-impulses or constraint forces

• Multiple contacts hard, but manageable

Page 44: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

References

• Hecker, Chris, “Behind the Screen,” Game Developer, Miller Freeman, San Francisco, Dec. 1996-Jun. 1997.

• Lander, Jeff, “Graphic Content,” Game Developer, Miller Freeman, San Francisco, Jan., Mar., Sep. 1999.

• Witkin, Andrew, David Baraff, Michael Kass, SIGGRAPH Course Notes, Physically Based Modelling, SIGGRAPH 2002.

Page 45: Collision Response Jim Van Verth (jim@essentialmath.com)

Essential Math for Games

References

• Mirtich, Brian and John Canny, “Impulse-Based Simulation of Rigid Bodies”, Proceedings of 1995 Symposium on Interactive 3D Graphics, April 1995. (available online)

• Eberly, David H., Game Physics, Morgan Kaufmann, 2004.