Game Physics - PowerPoint PPT Presentation

About This Presentation
Title:

Game Physics

Description:

Game Physics Part I Dan Fleck Coming up: Rigid Body Dynamics – PowerPoint PPT presentation

Number of Views:80
Avg rating:3.0/5.0
Slides: 26
Provided by: DanF168
Learn more at: https://cs.gmu.edu
Category:

less

Transcript and Presenter's Notes

Title: Game Physics


1
Game Physics Part I
  • Dan Fleck

2
Rigid Body Dynamics
  • Kinematics is the study of movement over time
  • Dynamics is the study of force and masses
    interacting to cause movement over time (aka
    kinematic changes).
  • Example
  • How far a ball travels in 10 seconds at 50mph is
    kinematics
  • How far the same ball travels when hit by a bat
    and under the force of gravity is dynamics
  • Additionally for simplification were going to
    model rigid bodies ones that do not deform (not
    squishy)
  • We can model articulated rigid bodies multiple
    limbs connected with a joint

3
Bring on calculus
  • Calculus was invented by Newton (and Leibniz) to
    handle these problems
  • Newtons Laws
  • 1. An object at rest stays at rest and an object
    in uniform motion stays in the same motions
    unless acted upon by outside forces (conservation
    of inertia)
  • 2. Force Mass Acceleration
  • 3. For every action there is an equal and
    opposite reaction

4
Fma
  • rPosition, vVelocity, aacceleration
  • Velocity is equal to the change in position over
    time.
  • Acceleration is equal to the change in velocity
    over time.

5
Intuitive Understanding
  • If every second my position changes by 5m, what
    is my velocity?
  • Acceleration is the change in velocity over time.
    If I am traveling at 5m/s at time t1, and 6m/s
    at t2, my acceleration is 1m/ss

6
Integration
  • Integration takes you backwards
  • Integrating acceleration over time gives you
    velocity
  • Intuition
  • If you are acceleration at 5m/ss, then every
    second you increase velocity by 5. Integrating
    sums up these changes, so your velocity is
  • What is C?
  • At time t0, what is velocity? C so C is initial
    velocity
  • So, if you are accelerating at 5m/ss, starting
    at 7m/s what is your velocity at time t3 seconds?

7
Integration
  • Similarly, integrating velocity over time gives
    you position
  • Example If youre accelerating at a constant
    5m/ss, then
  • So, given you have traveled for 5 seconds
    starting from point 0, where are you?
  • Plug in the values
  • So, given initial position, initial velocity, and
    acceleration you can find the new position,
    velocity.
  • We will do this every frame, using values from
    the previous frames.

8
Forces
  • But wait how do we find the acceleration to
    begin with?
  • Linear momentum is denoted as p which is
  • To change momentum, we need a force.Newton says
  • So, given a force on a point mass, we can find
    the acceleration and then we can find position,
    velocity whew, were done but..

9
Finding Momentum
  • On a rigid body, we have mass spread over an area
  • We compute momentum by treating each point on the
    object discretely and summing them up
  • Lets try to simplify this by introducing the
    center of mass (CM). Define CM as (where M is the
    total mass of the body)

10
Center of Mass
  • Using this equation, multiply bothsides by M and
    take the derivative
  • Aha.. .now we have total momentum on the right,
    but what is on the left?
  • Because M is a constant it comes out of the
    derivative and then we have change in position
    over time of the center of mass or velocity of
    CM!

11
Acceleration of CM
  • Total linear momentum can be found just using the
    velocity of the CM (no summation needed!)
  • So, finally the acceleration of the entire body
    can be calculated by assuming the forces are all
    acting on the CM and computing the acceleration
    of CM

12
Partial Summary
  • We now know, that given an objects acceleration
    we can compute its velocity and position by
    integrating
  • And to determine acceleration, we can sum forces
    acting on the center of mass (CM) and divide by
    total mass
  • Current challenge Integrating symbolically the
    find v(t) and t(t) is very hard! Remember
    differential equations?

13
Differential Equations
  • These equations occur when the dependent variable
    and its derivative both appear in the equation.
    Intuitively this occurs frequently because it
    means the rate of change of a value depends on
    the value.
  • Example air friction.. the faster you are going,
    the more force it applies to slow you down
  • f -v ma (solve for a) but a is the
    derivative of v, so
  • Solving this analytically is best left to you and
    your differential equations professor

14
Numerical Integration of Ordinary Differential
Equations (ODEs)
  • Analytically solving these is hard, but solving
    them numerically is much simpler. Many methods
    exist, but well use Eulers method.
  • Integration is simply summing the area under the
    curve, and the derivative is the slope of the
    curve at any point. Euler says

Integrating from t3 to 5 is summing the y values
for that section.
t3
t5
15
Eulers Approximation
Numerically integrating velocity and position we
get these equations
Euler numerical integration is an approximation
(src Wikipedia)
16
Final Summary of Equations
  • Sum up the forces acting on the body at the
    center of mass to get current acceleration
  • To get new velocity and position, use your
    current acceleration, velocity, position and
    numerical integration over some small time step
    (h)

17
Now we can code!
  • ForceRegistry stores which forces are being
    applied to which objects
  • ForceGenerator virtual (abstract) class that all
    Forces implement
  • Mainloop
  • for each entry in Registry
  • add force to accumulator in object
  • for each object
  • compute acceleration using resulting
    total force
  • compute new velocity using acceleration
  • compute new position using velocity
  • reset force accumulator to zero

18
ForceRegistry
  • v

19
ForceGenerator
20
ImpulseForceGenerator
Warning This code is actually changing the
acceleration, it should just update the forces
and the acceleration should be computed at the
end of all forces
21
DragForce generator
  • In order to slow an object down, a drag force can
    be applied that works in the opposite direction
    of velocity.
  • typically a simplified drag equation used in
    games is
  • k1 and k2 are constants specifying the drag
    force, and the direction is in the opposite
    direction of velocity.

22
DragForce Generator
Add force to current forces upon the player
23
Mainloop Updating Physics Quantities
Inside mainloop
After the forces have been updated, you must then
apply the forces to create acceleration and
update velocity and position.
24
Whats next?
  • Other forces
  • Spring forces push and pull
  • Bungee forces pull only
  • Anchored springs/bungees
  • Rotational forces
  • forces instead of moving the force can also
    induce rotations on the object
  • Collisions
  • Conversion from 2D to 3D

25
References
  • These slides are mainly based on Chris Heckers
    articles in Game Developers Magazine (1997).
  • The specific PDFs (part 1-4) are available
    athttp//chrishecker.com/Rigid_Body_Dynamics
  • Additional references from
  • http//en.wikipedia.org/wiki/Euler_method
  • Graham Morgans slides (unpublished)
Write a Comment
User Comments (0)
About PowerShow.com