Presentation is loading. Please wait.

Presentation is loading. Please wait.

Game Physics Chris Miles. The Goal To learn how to create game objects with realistic physics models To learn how to simulate aspects of reality in order.

Similar presentations


Presentation on theme: "Game Physics Chris Miles. The Goal To learn how to create game objects with realistic physics models To learn how to simulate aspects of reality in order."— Presentation transcript:

1 Game Physics Chris Miles

2 The Goal To learn how to create game objects with realistic physics models To learn how to simulate aspects of reality in order to make them behave more realistically

3 Overview Newton’s laws Data types Particle implementation Rigid body implementation

4

5 Newton’s Laws of Motion 1. Inertia 2. F = ma 3. Equal and opposite

6 How They Apply Velocity remains constant unless acted on by a force. Objects accelerate via f = ma Interactions between objects should affect both similarly

7 How They Don’t Apply 1. Velocities that reduce over time give better numerical stability 2. Objects are often moved instantaneously 3. Many interactions are one-sided, there is no reason to simulate the other side.

8 An Object – Rigid Body An object that moves but does not change shape “Mass properties” define how these objects are affected by forces 1. Mass 2. Moment of inertia 3. Center of gravity

9 Simulation We want to write a simulation describing the motion of the object look at the universe after 1 second, 2 seconds, so on and so on. integrate the equations of motion between those steps

10 Data Types Scalar Vector Matrix Quaternion Euler Angles Rotation Matrix Tensor

11 Scalars Scalars are a single number They represent simple characteristics, such as mass

12 Vectors [2,5][1,5,17][-.14,5,-7] Vectors usually represent a location, both in world and local space

13 Quaternion Quaternion’s contain an orientation Explaining how they work is long and fruitless Know that they hold an orientation in some undecipherable way Can quickly rotate vectors, cumulate easily, and interpolate smoothly Used by virtually every modern game engine (Laura Croft gets points for pioneering)

14 Particles First we will look at particles, which are a reduced form of Rigid Bodies Particles differ in that they do not have orientation, they just have positions

15 Euler angles What quaternions were developed to replace Vector containing rotations around x,y,z Suffers from gimbal lock - makes it impossible to go from some orientations to others in a single step Interpolates poorly - very ugly animations / camera movement Understandable

16 Rotation matrixes Another alternative to quaternions Too large, requires 9 variables vs. 4 Numerically unstable – unnormalizes over time Slower

17 Tensor Don’t worry about them, math term Generalization of scalars/vectors/matrix’s Scalars are rank 0 tensor, vectors 1, matrix’s 2 Concerned with rank 2 tensors, for moment of inertia Can also accurately simulate drag

18 Particle Class Definition Class Particle – vector position – vector velocity – vector resultantForce – scalar mass – Function Integrate( dtime ) – Called every time step to update position

19 Function Integrate( dtime ) //dtime = how much time has passed in this time step position += velocity * dtime velocity += force / mass force = 0

20 Improvements Violate law #1, have velocities slowly decrease – greatly increases numerical stability Original: – velocity += force / mass * dtime New: – velocity += (force/mass – velocity*cf)* dtime cf should be a coefficient of on the order of.999 or so

21 Implicit Integration We are doing explicit (forward) euler integration so far in our modeling. If stability is an issue you can use implicit integration http://www.mech.gla.ac.uk/~peterg/software/MT T/examples/Simulation_rep/node89.html is a good overview http://www.mech.gla.ac.uk/~peterg/software/MT T/examples/Simulation_rep/node89.html

22 Runge-Kutta Precise integration technique Sample several times for each time step. t = 0, t =.25, t =.5, t =.75 to find value at t = 1 Provides very accurate results http://mathworld.wolfram.com/Runge-KuttaMethod.html

23 Rigid Body Position and Orientation Linear and Angular movements are independent and analagous

24 Rigid Body Class Definition Class RigidBody – vector position – vector velocity – vector resultantForce – scalar mass – quaternion orientation – vector rotationalVelocity – vector resultantTorque – tensormomentOfInertia – Function Integrate( dtime )

25 Moments of Inertia The moment of inertia is the rotational equivalent to mass, it describes how hard an object is to rotate Depends on the axis of rotation so it is a tensor, mapping from a direction to a magnitude 3x3 matrix Just using a simple scalar in this example7

26 Calculating Moments of Inertia Producing the values that go inside the moment of inertia is non trivial. Assign point masses to the object, representing where things are distributed Then Σmr 2

27 Ideal Integrate function position += velocity * dtime velocity += force / mass * dtime force = 0 orientation += rotationalVelocity * dtime rotationalVelocity += torque / momentOfInertia * dtime torque = 0

28 Complications Quaternion operators are odd so to add rotationalVelocity from – orientation += rotationalVelocity * dtime to – o += (rv * o) / 2.0f * dtime;

29 Point Forces To calculate the torque caused by point forces Use the vector cross product force X position = torque Where position is the vector from the center of gravity to the point


Download ppt "Game Physics Chris Miles. The Goal To learn how to create game objects with realistic physics models To learn how to simulate aspects of reality in order."

Similar presentations


Ads by Google