rigid body dynamics jim van verth ([email protected])
TRANSCRIPT
![Page 2: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/2.jpg)
Essential Math for Games
Rigid Body Dynamics
• Simplest form of physical simulation
• Gets you a good way towards making a more realistic looking game
• Not that hard, either
![Page 3: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/3.jpg)
Essential Math for Games
Rigid Body
• Objects we simulate will not deform
• Brick vs. clay
• Fixed model: only change position and orientation
![Page 4: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/4.jpg)
Essential Math for Games
Dynamics
• Want to move objects through the game world in the most realistic manner possible
• Applying velocity not enough – need ramp up, ramp down – acceleration
• Same with orientation
![Page 5: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/5.jpg)
Essential Math for Games
Calculus Review
• Have function y(t)
• Function y'(t) describes how y changes as t changes (also written dy/dt)
• y'(t) gives slope at time t
y(t)
y'(t)
y
t
![Page 6: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/6.jpg)
Essential Math for Games
Calculus Review
• Our function is position:
• Derivative is velocity:
• Derivative of velocity is acceleration
![Page 7: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/7.jpg)
Essential Math for Games
Basic Newtonian Physics
• All objects affected by forces Gravity Ground (pushing up) Other objects pushing against it
• Force determines acceleration (F = ma)
• Acceleration changes velocity ( )
• Velocity changes position ( )
![Page 8: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/8.jpg)
Essential Math for Games
Basic Newtonian Physics
• Assume acceleration constant, then
• Similarly
![Page 9: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/9.jpg)
Essential Math for Games
Basic Newtonian Physics
• Key equations
• Note: force is derivative of momentum P
Remember for later – easier for angular
![Page 10: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/10.jpg)
Essential Math for Games
Basic Newtonian Physics
• General approach Compute all forces on object, add up Compute acceleration
• (divide total force by mass)
Compute new position based on old position, velocity, acceleration
Compute new velocity based on old velocity, acceleration
![Page 11: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/11.jpg)
Essential Math for Games
Newtonian Physics
• Works fine if acceleration is constant
• Not good if acceleration dependant on position or velocity – changes over time step
• E.g. spring force: Fspring = –kx
• E.g. drag force: Fdrag = –mv
![Page 12: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/12.jpg)
Essential Math for Games
Analytic Solution
• Can try and find an analytic solution I.e. a formula for x and v In case of simple drag:
But not always a solution Or may want to try different simulation
formulas
![Page 13: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/13.jpg)
Essential Math for Games
Numeric Solution
• Problem: Physical simulation with force dependant on position or velocity
• Start at x(0) = x0, v(0) = v0
• Only know:
• Basic solution: Euler’s method
![Page 14: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/14.jpg)
Essential Math for Games
Euler’s Method
• Idea: we have the derivative (x or v) • From calculus, know that
• Or, for sufficiently small h:
![Page 15: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/15.jpg)
Essential Math for Games
Euler’s Method
• Can re-arrange as:
• Gives us next function value in terms of current value and current derivative
![Page 16: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/16.jpg)
Essential Math for Games
Final Formulas
• Using Euler’s method with time step h
![Page 17: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/17.jpg)
Essential Math for Games
What About Orientation?
• Force (F) applies to center of mass* of object – creates translation
• Torque () applies to offset from center of mass – creates rotation
• Add up torques just like forces
![Page 18: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/18.jpg)
Essential Math for Games
Force vs. Torque (cont’d)
• To compute torque, take cross product of vector r (from CoM to point where force is applied), and force vector F
• Applies torque ccw around vector
r F
![Page 19: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/19.jpg)
Essential Math for Games
Other Angular Equivalents
• Force F vs. torque • Momentum P vs. angular momentum L
• Velocity v vs. angular velocity • Position x vs. orientation • Mass m vs. moments of inertia J
![Page 20: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/20.jpg)
Essential Math for Games
Why L?
• Difficult to compute angular velocity from angular acceleration
• Compute ang. momentum by integrating torque
• Compute ang. velocity from momentum
• Since then
![Page 21: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/21.jpg)
Essential Math for Games
Moments of Inertia
• Moments of inertia are 3 x 3 matrix, not single scalar factor (unlike m)
• Many factors because rotation depends on shape and density
• Describe how object rotates around various axes
• Not easy to compute• Change as object changes orientation
![Page 22: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/22.jpg)
Essential Math for Games
Computing J
• Can use moments of inertia for closest box or cylinder
• Can use sphere (one factor: 2mr2/5)
• Or, can just consider rotations around one axis and fake(!) the rest
• With the bottom two you end up with just one value… can simplify equations
![Page 23: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/23.jpg)
Essential Math for Games
Computing J
• Alternatively, can compute based on geometry
• Assume constant density, constant mass at each vertex
• Solid integral across shape
• See Eberly for more details Also at www.geometrictools.com
![Page 24: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/24.jpg)
Essential Math for Games
Using J in World Space
• Remember, • J computed in local space, must
transform to world space
• If using rotation matrix , use formula
• If using quaternion, convert to matrix
![Page 25: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/25.jpg)
Essential Math for Games
Computing New Orientation
• Have matrix and vector • How to integrate?
• Convert to give change in Change to linear velocity at tips of basis
vectors One for each basis gives 3x3 matrix Can use Euler's method then
![Page 26: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/26.jpg)
Essential Math for Games
Computing New Orientation
• Example:
![Page 27: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/27.jpg)
Essential Math for Games
Computing New Orientation
r gives linear velocity at r
• Could do this for each basis vector
• Better way: Use symmetric skew matrix to compute
cross products Multiply by orientation matrix
![Page 28: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/28.jpg)
Essential Math for Games
Computing New Orientation
• If have matrix , then
where
![Page 29: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/29.jpg)
Essential Math for Games
Computing New Orientation
• If have quaternion q, then
• See Baraff or Eberly for derivation
where
![Page 30: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/30.jpg)
Essential Math for Games
Computing New Orientation
• We can represent wq as matrix multiplication where
• Assumes q = (w, x, y, z)
![Page 31: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/31.jpg)
Essential Math for Games
Angular Formulas
![Page 32: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/32.jpg)
Essential Math for Games
Reducing Error
• Keep time step as small as possible
• Clamp accelerations, velocities to maximum values – avoid large forces
• If velocity, acceleration very small, set to zero (avoids little shifts in position)
• Damping acceleration based on velocity (i.e. friction) can help
![Page 33: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/33.jpg)
Essential Math for Games
Improving Performance
• If not moving, don’t simulate
• Only do as much as you have to
• If you can fake it, do so objects on ground, don’t bother with gravity only rotate around z, don’t bother with J simple drag instead of full friction model
![Page 34: Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)](https://reader036.vdocuments.site/reader036/viewer/2022062407/56649c745503460f94927c4c/html5/thumbnails/34.jpg)
Essential Math for Games
References
• Burden, Richard L. and J. Douglas Faires, Numerical Analysis, PWS Publishing Company, Boston, MA, 1993.
• Hecker, Chris, “Behind the Screen,” Game Developer, Miller Freeman, San Francisco, Dec. 1996-Jun. 1997.
• Witken, Andrew, David Baraff, Michael Kass, SIGGRAPH Course Notes, Physically Based Modelling, SIGGRAPH 2002.
• Eberly, David, Game Physics, Morgan Kaufmann, 2003.