Color Problem • Have a black-box function that returns a bright color in 24-bit RGB • Want a paler version of the output • What to do? Collision Resolution Collision resolution • Pre-collision positions, velocities known • Collision: black box • Post-collision positions, velocities known • Assumption: we know collision location Impulse • Instantaneous change in momentum • j = ∆P • Apply within one timestep • Effectively, infinite force Aside: Alternatives • Not the only approach to collision resolution • "soft body": force proportional to penetration distance (one-way spring force) One-body collisions • Most common case: collision of object with scenery • Calculations generalize to two-body – perform calculations in reference frame where one body is at rest, i.e., add one body's velocity to the other before starting • Simpler to set up this way Collision Normal • direction in which bodies collide • often simple: – line joining centres – normal of collision point on obstacle (often good approximation anyway) Closing Velocity • velocity with which things collide • magnitude: dot product of velocity and collision normal • If colliding: negative value • If separating: positive Post-Collision Velocity • Perfectly elastic collision: v'.nc = -v.nc • Perfectly plastic collision: v'.nc = 0 • "Coefficient of restitution": linear interpolation between these extremes –v'.nc = -c v.nc Contact • Contact management: avoid rattling effects of tiny collisions • Threshold for contact: if closing velocity smaller than threshold, set coefficient of restitution to zero – and perhaps stop simulating this object for now Impulse • Given output velocity, update velocity of body using momentum (impulse): j = -(1+c)(v.nc)nc – Unpacking: • v is relative velocity • nc is collision normal • c is coefficient of restitution Closing rotational velocity • Recall that rotation produces instantaneous linear velocity: v =ωxr • so, add this velocity to centre of mass velocity to get velocity of collision point – r = distance from body centre to collision point – if using angular momentum, ω = I-1L Impulsive torque • Compute impulse as before: have j = ∆P • Now, compute impulsive torque ∆L • Actually simple: ∆L = r x j – recall τ = r x F, same idea Wrapping up • Apply impulse, impulsive torque to both bodies (one positive, one negative) • If one body is fixed: effectively infinite mass, moment of inertia (zero inverse mass) so no resulting velocity