Download presentation

Presentation is loading. Please wait.

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

2
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

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

4
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

5
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) y t

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

7
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 ( )

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

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

10
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

11
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: F spring = – kx E.g. drag force: F drag = – m v

12
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

13
Essential Math for Games Numeric Solution Problem: Physical simulation with force dependant on position or velocity Start at x(0) = x 0, v(0) = v 0 Only know: Basic solution: Euler’s method

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

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

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

17
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

18
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

19
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

20
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

21
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

22
Essential Math for Games Computing J Can use moments of inertia for closest box or cylinder Can use sphere (one factor: 2mr 2 /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

23
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

24
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

25
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

26
Essential Math for Games Computing New Orientation Example:

27
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

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

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

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

31
Essential Math for Games Angular Formulas

32
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

33
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

34
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.

Similar presentations

OK

Game Physics – Part I Dan Fleck Coming up: Rigid Body Dynamics.

Game Physics – Part I Dan Fleck Coming up: Rigid Body Dynamics.

© 2019 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google