Top Banner
Game Physics Chris Miles
29

Game Physics

Dec 31, 2015

Download

Documents

Kelly Barnett

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 to make them behave more realistically. Overview. Newton’s laws Data types Particle implementation Rigid body implementation. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Game Physics

Game Physics

Chris Miles

Page 2: Game Physics

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

Page 3: Game Physics

Overview

Newton’s laws Data types Particle implementation Rigid body implementation

Page 4: Game Physics
Page 5: Game Physics

Newton’s Laws of Motion

1. Inertia

2. F = ma

3. Equal and opposite

Page 6: Game Physics

How They Apply

Velocity remains constant unless acted on by a force.

Objects accelerate via f = ma

Interactions between objects should affect both similarly

Page 7: Game Physics

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.

Page 8: Game Physics

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

Page 9: Game Physics

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

Page 10: Game Physics

Data Types

Scalar Vector Matrix Quaternion Euler Angles Rotation Matrix Tensor

Page 11: Game Physics

Scalars

Scalars are a single number

They represent simple characteristics, such as mass

Page 12: Game Physics

Vectors

[2,5] [1,5,17] [-.14,5,-7]

Vectors usually represent a location, both in world and local space

Page 13: Game Physics

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)

Page 14: Game Physics

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

Page 15: Game Physics

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

Page 16: Game Physics

Rotation matrixes

Another alternative to quaternions Too large, requires 9 variables vs. 4 Numerically unstable – unnormalizes over

time Slower

Page 17: Game Physics

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

Page 18: Game Physics

Particle Class Definition

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

Page 19: Game Physics

Function Integrate( dtime )

//dtime = how much time has passed in this time step

position += velocity * dtime

velocity += force / mass

force = 0

Page 20: Game Physics

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

Page 21: Game Physics

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/MTT/examples/Simulation_rep/node89.html is a good overview

Page 22: Game Physics

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

Page 23: Game Physics

Rigid Body

Position and Orientation

Linear and Angular movements are independent and analagous

Page 24: Game Physics

Rigid Body Class Definition

Class RigidBody– vector position– vector velocity– vector resultantForce– scalar mass

– quaternion orientation– vector rotationalVelocity– vector resultantTorque– tensor momentOfInertia

– Function Integrate( dtime )

Page 25: Game Physics

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

Page 26: Game Physics

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 Σmr2

Page 27: Game Physics

Ideal Integrate function

position += velocity * dtimevelocity += force / mass * dtimeforce = 0

orientation += rotationalVelocity * dtimerotationalVelocity += torque / momentOfInertia *

dtimetorque = 0

Page 28: Game Physics

Complications

Quaternion operators are odd so to add rotationalVelocity

from– orientation += rotationalVelocity * dtime

to– o += (rv * o) / 2.0f * dtime;

Page 29: Game Physics

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