Concepts for Programming a Rigid Body Physics Engine Part 2 Presented by Scott Hawkins.

Slides:



Advertisements
Similar presentations
AP Physics C Mechanics Review.
Advertisements

Newton’s Laws and Forces. Forces Force = a push or pull – changes speed of an object – changes direction of an object – can be touching or long distance.
Lesson 1 Gravity and Friction Lesson 2 Newton’s First Law
Lesson 1 Gravity and Friction Lesson 2 Newton’s First Law
Lesson 1 Gravity and Friction Lesson 2 Newton’s First Law
Kinetics of Particles: Energy and Momentum Methods
5. Using Newton’s Laws. Newton’s Third Law 3 Law of Action and Reaction Forces always occur in equal and opposite pairs A B A acts on B B acts on A.
PHYS 218 sec Review Chap. 4 Newton’s laws of motion.
Chapter 15: Kinetics of a Particle: Impulse and MomentumTextbook: Engineering Mechanics- STATICS and DYNAMICS- 11th Ed., R. C. Hibbeler and A. Gupta Course.
IMPACT Today’s Objectives: 1.Understand and analyze the mechanics of impact. 2.Analyze the motion of bodies undergoing a collision, in both central and.
A ladder with length L weighing 400 N rests against a vertical frictionless wall as shown below. The center of gravity of the ladder is at the center of.
MAE 242 Dynamics – Section I Dr. Kostas Sierros.
Momentum Impulse, Linear Momentum, Collisions Linear Momentum Product of mass and linear velocity Symbol is p; units are kgm/s p = mv Vector whose direction.
Rotational Dynamics Chapter 9.
3.5. C ONTACT R ESOLUTION Resolving a set of contacts.
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?
Linear Impulse & Linear Momentum
EGR 280 Mechanics 13 – Impulse and Momentum of Particles.
Chap 15 Kinetics of a particle impulse and momentum principle of linear impulse and momentum (1) Linear impulse I,N S The integral I =∫F dt is defined.
Linear, not Angular, Momentum: In this section, we deal with conservation of linear momentum (mv) of particles only. Another section of your book talks.
Chapter 8 Rotational Equilibrium and Rotational Dynamics.
Chapter 5 Newton’s Laws of Motion. 5-1 Force and Mass Force: push or pull Force is a vector – it has magnitude and direction.
PLANAR KINETICS OF A RIGID BODY:
Work Let us examine the work done by a torque applied to a system. This is a small amount of the total work done by a torque to move an object a small.
Chapter 4 Preview Objectives Force Force Diagrams
NEWTON’S FIRST LAW Definition- An object at rest will remain at rest, or if it is moving, it will continue to move with constant velocity, unless acted.
Lecture VII Rigid Body Dynamics CS274: Computer Animation and Simulation.
What is motion? Acceleration Momentum
Chapter 10 Rotation of a Rigid Object about a Fixed Axis.
ESS 303 – Biomechanics Linear Kinetics. Kinetics The study of the forces that act on or influence movement Force = Mass * Acceleration: F = M * a Force.
Chapter 9: Rotational Dynamics
Computer Animation Rick Parent Computer Animation Algorithms and Techniques Collisions & Contact.
1 Momentum and Its Conservation Or How I Learned to Love Collisions.
Concepts for Programming a Rigid Body Physics Engine Part 1 Presented by Scott Hawkins.
Linear Impulse & Linear Momentum Lecture VIII. Introduction From Newton ’ s 2 nd Law:  F = m a = m v. = d/dt (m v) The term m v is known as the linear.
Chapter 4 The Laws of Motion. Classes of Forces Contact forces involve physical contact between two objects Field forces act through empty space No physical.
Chapter 17 PLANE MOTION OF RIGID BODIES: ENERGY AND MOMENTUM METHODS
Force and Motion This week – This week – Force and Motion – Chapter 4 Force and Motion – Chapter 4.
Advanced Computer Graphics Rigid Body Simulation Spring 2002 Professor Brogan.
Joint Reaction Forces Muscle Moments Joint Power
Spring Rigid Body Simulation. Spring Contents Unconstrained Collision Contact Resting Contact.
A force is a push or pull. Net force is the combination (sum) of all acting forces.
Linear and Angular Motion. The greater the applied impulse the greater the increase in velocity. Principle 4 – Linear Motion.
AP Physics C Montwood High School R. Casao. When a wheel moves along a straight track, the center of the wheel moves forward in pure translation. A point.
CS274 Spring 01 Lecture 7 Copyright © Mark Meyer Lecture VII Rigid Body Dynamics CS274: Computer Animation and Simulation.
Impulse and Momentum AP Physics C.
© Houghton Mifflin Harcourt Publishing Company Preview Objectives Force Force Diagrams Chapter 4 Section 1 Changes in Motion.
Unit 2 Momentum and Impulse An Introduction to Momentum.
Forces and the Laws of Motion Chapter 4. Forces and the Laws of Motion 4.1 Changes in Motion –Forces are pushes or pullss can cause acceleration. are.
Rick Parent - CIS682 Rigid Body Dynamics simulate basic physics of an object subject to forces Keyframing can be tedious - especially to get ‘realism’
Chapter 4 Laws of Motion and Forces Goals: Newtons Laws, Inertia and mass, Mass vs Weight, Free Body diagrams, Fg, Fn, Fy, Fx, Ff, coefficients of friction.
IMPULSE On a secret mission… … to change equilibrium states!
Chapter 4 The Laws of Motion.
Momentum and Its Conservation Chapter 9. Properties of a System Up until now, we have looked at the forces, motion and properties of single isolated objects.
Advanced Computer Graphics Rigid Body Simulation
2D Simulation of Rigid Bodies
Lecture Rigid Body Dynamics.
Chapter 6 Section 3 Inertia & Momentum
Chapter 4 Newton’s Laws.
Chapter 5 The Laws of Motion.
ENGINEERING MECHANICS
Physics Jeopardy Rules
Impulse and Momentum AP Physics C.
Computer Animation Algorithms and Techniques
Impulse and Momentum Chapter 7.
The Laws of Motion (not including Atwood)
∆ Any object in motion has momentum, “Mass that moves”
Impulse and Momentum AP Physics C.
Impulse and Momentum AP Physics C.
Impulse and Momentum AP Physics C.
Presentation transcript:

Concepts for Programming a Rigid Body Physics Engine Part 2 Presented by Scott Hawkins

Game Physics Engine Development by Ian Millington source:

Topics Collision Resolution –Resolving Velocities –Resolving Positions Friction

Collision Resolution We have been given a list of contacts, each containing: –references to the two rigid bodies –contact point in world coordinates, q (Vector) –contact normal in world coordinates, n (Vector) –penetration depth, d (real) –coefficient of restituion, c (real) –coefficient of friction, μ (real)

Collision Resolution After we detect collisions, what needs to be updated? –positions –orientations –velocities –angular velocities

Collision Resolution Two steps –Resolve velocities (and angular velocities) –Resolve positions (and orientations)

Collision Resolution Resolving velocities –Find the closing velocity for each contact –Choose the contact with greatest closing velocity –Resolve velocities for this contact (do not remove it from the list of contacts) –Repeat this until either (1) all contacts are resolved, or (2) we run out of iterations

Finding Closing Velocity “Closing velocity” is the speed at which the two objects are moving toward each other at the point of contact. We need this information to determine which contact to resolve first.

Finding Closing Velocity How to find the closing velocity? –Find the velocity at the contact point for each object –Take the component in the direction of the contact –Sum them together

Finding Closing Velocity How do you find the velocity of a point on a spinning object? –Start with the object’s overall velocity and add the component due to rotation v point = p’ + θ’ x (p point - p) –where p point is the position of the point in world coordinates

Finding Closing Velocities For a rigid body collision, some component of the closing velocity may result from rotation vs

Finding Closing Velocity We want the velocity of each object at the contact point –We were given q, the contact point in world coordinates v contact,a = p’ a + θ’ a x (q - p a ) v contact,b = p’ b + θ’ b x (q - p b )

Finding Closing Velocity Find the component of this in the direction of the contact –We were given n, the contact normal, which is a unit vector pointing from object a to object b v c,a = v contact,a · n v c,b = v contact,b · -n –Use -n in the second equation because we want the component going from object b to object a

Finding Closing Velocity Sum the components from each object to get the total closing velocity, v c v c = v c,a + v c,b

Choosing the Greatest Closing Velocity We now have the closing velocity for each contact Choosing the greatest closing velocity will take O(n) time normally –use a max-heap?

Resolving Velocities How to update velocity and angular velocity for a pair of colliding objects? Accomplish this by applying some impulse, g (which we will find) g represents a change in momentum g = Δ(mv)

Resolving Velocities This also creates an impulsive torque, u, given by: u = (q - p) x g –Once again, q is the contact point in world coordinates

Resolving Velocities To apply g to the objects: Δp’ a = m a -1 g Δθ’ a = I a -1 u a = I a -1 [(q - p a ) x g] Δp’ b = m b -1 (-g) Δθ’ b = I b -1 u b = I b -1 [(q - p b ) x (-g)] –Be sure to use -g for object b –I -1 in these equations is in world coordinates

Resolving Velocities How to choose g ?

Resolving Velocities We want the objects to bounce off of each other according to the coefficient of restitution, c v c,after = -cv c At the contact point, and in the direction of the contact normal, we want a velocity change of Δv Δv = -cv c - v c = -(1 + c)v c

Resolving Velocities How can we choose g to generate this result? –We already know the direction of g It must point in the direction of the contact normal, since it is like a normal force acting over an infinitely short time interval –Find the magnitude g by expressing g as g = gn and plugging it into the previous equations

Resolving Velocities If we applied the impulse gn, we would get: Δp’ a = m a -1 gn Δθ’ a = I a -1 [(q - p a ) x gn] Δp’ b = -m b -1 gn Δθ’ b = -I b -1 [(q - p b ) x gn]

Resolving Velocities This causes a change in velocity at the contact point: Δv contact,a = Δp’ a + Δθ’ a x (q - p a ) = m a -1 gn + (I a -1 [(q - p a ) x gn]) x (q - p a ) = g[m a -1 n + (I a -1 [(q - p a ) x n]) x (q - p a )] Δv contact,b = Δp’ b + Δθ’ b x (q - p b ) = -m b -1 gn + (-I b -1 [(q - p b ) x gn]) x (q - p b ) = -g[m b -1 n + (I b -1 [(q - p b ) x n]) x (q - p b )]

Resolving Velocities This contributes to a change in closing velocity: Δv c,a = Δv contact,a · n = g[m a -1 n + (I a -1 [(q - p a ) x n]) x (q - p a )] · n = g(m a -1 + [(I a -1 [(q - p a ) x n]) x (q - p a )] · n) Δv c,b = Δv contact,b · -n = -g[m b -1 n + (I b -1 [(q - p b ) x n]) x (q - p b )] · -n = g(m b -1 + [(I b -1 [(q - p b ) x n]) x (q - p b )] · n)

Resolving Velocities Add these to get the total change in closing velocity: Δv c = Δv c,a + Δv c,b = g(m a -1 + [(I a -1 [(q - p a ) x n]) x (q - p a )] · n) + g(m b -1 + [(I b -1 [(q - p b ) x n]) x (q - p b )] · n) = -(1 + c)v c

Resolving Velocities Now we can isolate g g = -(1 + c)v c / (m a -1 + [(I a -1 [(q - p a ) x n]) x (q - p a )] · n + m b -1 + [(I b -1 [(q - p b ) x n]) x (q - p b )] · n) g = gn Apply g to the objects as we discussed earlier

Resolving Velocities After resolving the velocities for one contact, update its closing velocity to be v c,after = -cv c –Update the closing velocities for every contact involving one of the two bodies that were changed This contact was resolved These need to update v c

Resolving Velocities Continue resolving whichever contact has the greatest closing velocity until either –(1) all contacts are resolved (all closing velocities are less than or equal to zero) or –(2) we run out of iterations

Collision Resolution Resolving positions –Choose the contact with greatest interpenetration depth –Resolve positions for this contact (do not remove it from the list of contacts) –Repeat this until either (1) all contacts are resolved, or (2) we run out of iterations

Choosing the Greatest Interpenetration Depth The interpenetration depth d at each contact is given to us by the collision detector Use another max-heap?

Resolving Positions How to update position and orientation for a pair of colliding objects? –We apply changes in position and orientation to each object to make d = 0 –The changes we need to find are Δp a, Δθ a, Δp b, and Δθ b

Resolving Positions Once we have Δp a, Δθ a, Δp b, and Δθ b, we can perform the update p a,after = p a + Δp a θ a,after = θ a + ½(Δθ a )(θ a ) –where Δθ a = 0 + Δθ a,x i + Δθ a,y j + Δθ a,z k and Δθ a,x, Δθ a,y, Δθ a,z are components of Δθ a p b,after = p b + Δp b θ b,after = θ b + ½(Δθ b )(θ b ) –where Δθ b = 0 + Δθ b,x i + Δθ b,y j + Δθ b,z k and Δθ b,x, Δθ b,y, Δθ b,z are components of Δθ b

Resolving Positions How do we decide what those changes should be?

Resolving Positions Millington uses an approximation –Treat distance moved around a circle as if it were in a straight line

Resolving Positions Interpenetration depth d resolved through a combination of linear and rotational movement from both objects d = linear movement of a + angular movement of a + linear movement of b + angular movement of b

Resolving Positions Each movement contributes some fraction of the total distance linear movement of a = w 1 d angular movement of a = w 2 d linear movement of b = w 3 d angular movement of b = w 4 d –where w 1, w 2, w 3, and w 4 are weights between 0 and 1 such that w 1 + w 2 + w 3 + w 4 = 1

Resolving Positions Impulse –To resolve velocities, the “impulse” we want is a force integrated over a short time units are kg·m/s –To resolve positions, we need an “impulse” that is force integrated twice over a short time units are kg·m

Resolving Positions Inertia –normally, an object’s tendency to resist a change in motion –in this case, we say “inertia” is an object’s response to one kg·m of “impulse”

Resolving Positions Choose w 1, w 2, w 3, and w 4 based on inertia w 1 = linear inertia of a / total inertia w 2 = angular inertia of a / total inertia w 3 = linear inertia of b / total inertia w 4 = angular inertia of b / total inertia total inertia = linear inertia of a + angular inertia of a + linear inertia of b + angular inertia of b

Resolving Positions Linear Inertia –How much linear movement occurs in response to a unit impulse? –(different kind of impulse than before) linear inertia of a = m -1 a linear inertia of b = m -1 b

Resolving Positions Angular Inertia –How much angular movement occurs in response to a unit impulse? (in the direction of the contact) angular inertia of a = [(I -1 a [(q - p a ) x n]) x (q - p a )] · n angular inertia of b = [(I -1 b [(q - p b ) x n]) x (q - p b )] · n

Resolving Positions We can now find the weights w 1, w 2, w 3, and w 4 w 1 = m -1 a / total inertia w 2 = [(I -1 a [(q - p a ) x n]) x (q - p a )] · n / total inertia w 3 = m -1 b / total inertia w 4 = [(I -1 b [(q - p b ) x n]) x (q - p b )] · n / total inertia total inertia = m -1 a + [(I -1 a [(q - p a ) x n]) x (q - p a )] · n + m -1 b + [(I -1 b [(q - p b ) x n]) x (q - p b )] · n

Resolving Positions Using these weights, we can find how much of each type of movement should occur linear movement of a = w 1 d angular movement of a = w 2 d linear movement of b = w 3 d angular movement of b = w 4 d

Resolving Positions How can we generate this much movement?

Resolving Positions Linear movement Δp a = -n * linear movement of a Δp b = n * linear movement of b

Resolving Positions Angular Movement How much rotation? –We are given an amount of movement –Find ratio of impulse per movement –Find ratio of rotation per impulse –rotation = (movement) * (impulse / movement) * (rotation / impulse)

Resolving Positions How to find ratio of impulse per movement? –The angular inertia we used before was a ratio of movement per impulse (impulse/movement) a = (angular inertia of a) -1 (impulse/movement) b = (angular inertia of b) -1

Resolving Positions How to find ratio of rotation per impulse? (rotation/impulse) a = I -1 a ((q - p a ) x n) (rotation/impulse) b = I -1 b ((q - p b ) x (-n)) –Use -n for object b, since it must receive an impulse in the opposite direction

Resolving Positions Putting it all together Δθ a = rotation a = (movement) a * (impulse / movement) a * (rotation / impulse) a = w 2 d * (angular inertia of a) -1 * I -1 a ((q - p a ) x n) = (angular inertia of a / total inertia) * d * (angular inertia of a) -1 * I -1 a ((q - p a ) x n)

Resolving Positions Putting it all together Δθ b = rotation b = (movement) b * (impulse / movement) b * (rotation / impulse) b = w 4 d * (angular inertia of b) -1 * I -1 b ((q - p b ) x (-n)) = (angular inertia of b / total inertia) * d * (angular inertia of b) -1 * I -1 b ((q - p b ) x (-n))

Resolving Positions Apply Δp a, Δθ a, Δp b, and Δθ b to the objects as we discussed earlier

Resolving Positions After resolving the positions for one contact, update the penetration depth for related contacts This contact was resolved These need to update d

Resolving Positions To update the penetration depth d for a related contact Δd = (Δp + (Δθ x (q - p))) · n

Resolving Positions Continue resolving whichever contact has the greatest penetration depth until either –(1) all contacts are resolved (all penetration depths are less than or equal to zero) or –(2) we run out of iterations

Friction We want a frictional impulse g f ||g f || <= μ||g|| g f is in the direction that will eliminate perpendicular components of the objects’s relative motion

Friction To find the direction of g f –Find the components of the objects’ velocities perpendicular to the contact v perp,a = v contact,a - v contact,a (v contact,a · n)/||v contact,a || v perp,b = v contact,b - v contact,b (v contact,b · -n)/|| v contact,b || v perp,total = v perp,a - v perp,b g f = -||g f ||v perp,total

Friction To find the magnitude of g f –Find the greatest possible value for ||g f || that satisfies the inequalities ||g f || <= μ||g|| ||Δv perp,total || <= ||v perp,total ||