1 / 34

Jim Van Verth (jim@essentialmath)

Rigid Body Dynamics. Jim Van Verth (jim@essentialmath.com). Rigid Body Dynamics. Simplest form of physical simulation Gets you a good way towards making a more realistic looking game Not that hard, either. Rigid Body. Objects we simulate will not deform Brick vs. clay

mtrowbridge
Download Presentation

Jim Van Verth (jim@essentialmath)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Rigid Body Dynamics Jim Van Verth (jim@essentialmath.com)

  2. Rigid Body Dynamics • Simplest form of physical simulation • Gets you a good way towards making a more realistic looking game • Not that hard, either Essential Math for Games

  3. Rigid Body • Objects we simulate will not deform • Brick vs. clay • Fixed model: only change position and orientation Essential Math for Games

  4. 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 Essential Math for Games

  5. 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 y(t) y'(t) t Essential Math for Games

  6. Calculus Review • Our function is position: • Derivative is velocity: • Derivative of velocity is acceleration Essential Math for Games

  7. 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 ( ) Essential Math for Games

  8. Basic Newtonian Physics • Assume acceleration constant, then • Similarly Essential Math for Games

  9. Basic Newtonian Physics • Key equations • Note: force is derivative of momentum P • Remember for later – easier for angular Essential Math for Games

  10. 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 Essential Math for Games

  11. 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 = –mv Essential Math for Games

  12. 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 Essential Math for Games

  13. 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 Essential Math for Games

  14. Euler’s Method • Idea: we have the derivative (x or v) • From calculus, know that • Or, for sufficiently small h: Essential Math for Games

  15. Euler’s Method • Can re-arrange as: • Gives us next function value in terms of current value and current derivative Essential Math for Games

  16. Final Formulas • Using Euler’s method with time step h Essential Math for Games

  17. 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 Essential Math for Games

  18. 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 Essential Math for Games

  19. 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 Essential Math for Games

  20. Why L? • Difficult to compute angular velocity from angular acceleration • Compute ang. momentum by integrating torque • Compute ang. velocity from momentum • Since then Essential Math for Games

  21. 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 Essential Math for Games

  22. 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 Essential Math for Games

  23. 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 Essential Math for Games

  24. 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 Essential Math for Games

  25. 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 Essential Math for Games

  26. Computing New Orientation • Example: Essential Math for Games

  27. 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 Essential Math for Games

  28. Computing New Orientation • If have matrix, then where Essential Math for Games

  29. Computing New Orientation • If have quaternion q, then • See Baraff or Eberly for derivation where Essential Math for Games

  30. Computing New Orientation • We can represent wq as matrix multiplication where • Assumes q = (w, x, y, z) Essential Math for Games

  31. Angular Formulas Essential Math for Games

  32. 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 Essential Math for Games

  33. 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 Essential Math for Games

  34. 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. Essential Math for Games

More Related