tsbk03 technics for advanced gomputer games:...

90
TSBK03 Technics for Advanced Gomputer Games: Physics Ht2010 Sergiy Valyukh, IFM Ver10.1

Upload: danghanh

Post on 19-Feb-2018

238 views

Category:

Documents


0 download

TRANSCRIPT

TSBK03

Technics

for Advanced

Gomputer

Games: Physics Ht2010

Sergiy Valyukh, IFM

Ver10.1

TSBK03: Physics, Ht2010 2

Outline

i. Introduction

(physics

and its

role

in game industry)

1. Kinematics, Newton’s

mechanics

2. Work, Energy

and Power

3. Projectiles

4. Collisions

5. Sports Simulations

6. Cars and Motorcycles

Presenter
Presentation Notes
En inledning samt 6 fysikavsnitt. Fö1: i,1 Fö2: 2,3 Fö3: 4,5,6

TSBK03: Physics, Ht2010 3

i. Introduction

(physics

and its

role

in game industry)

i.1About the course

i.2 Physics

as a natural science

i.3 Modelling

of the physical

word

in a game

TSBK03: Physics, Ht2010 4

i.1 about

the course

physics

for game programers

Purposes

To inroduce

into

basics

of physics, in order to model

the ”real world”

in computer games

Sources

Webpage

of the course

(Ingemar R)http://www.computer-graphics.se/TSBK03.htmlRagnemalm, PFNP-SHCWMTS

[IR]

G. Palmer, Physics for Game Programmers, Apress, 2005

Witkin, Baraff, Kass, lectures

from Pixar

”SIGGRAPH 2001 Course notes”

[Pix], http://www.pixar.com/

Ian Millingston, Game Physics

Engine Development, Elsevier, 2007

C. Hecker, Behind

the Screen, http://www.d6.com/users/checker

D. Eberly, Game physics, Elsevier, 2004

D. Bourg, Physics

for Game Developers, O’Reilly, 2002

Presenter
Presentation Notes
3 fö: En svår uppgift. Material från tre Mekkurser (samt vågfys och em/optik).�Kanske 15hp på 6h.�Ni har också olika bakgrund C,D,IT,(Y,Doktorander) Orient, begrepp: Mest mekanik Övergripande: KJ - fysik, försöker ge en bakgrund till den fysik som tas upp i WBK samt IR. Ni experter – Större vana att programmera, implementera fysikdelarna�Hoppas vi kan nå varandra

TSBK03: Physics, Ht2010 5

i.2 Physics

as a natural science

ClassicalClassical PhysicsPhysics

Molecular physics ElectromagnetismMechanics

TSBK03: Physics, Ht2010 6

i.3 Modelling

of the physical

word

3D objects and 3D scenesMovementRigid objectsRotationFrictionAir and water resistanceGravityCollisions

and explosions Springy

thingsWaves

If it is looks right on the screen, that’s good enough!

Criterion

for a physical

model

in a game:

90% of games applied physical simulations use:

Presenter
Presentation Notes
Mekanik: Föremåls rörelser och de krafter som påverkar rörelsen EM: Om de krafter som uppstår pga laddningar i vila och rörelse. Optik. Termodynamik: Om fysikaliska system med väldigt många partiklar Relativitetsteori: snabba, hög energi Kvantfysik: små dimensioner Ringar: Berör dessa områden

TSBK03: Physics, Ht2010 7

i.3 Modelling

of the physical

word

Physics Will Keep Your Games from Looking Fake

Adding Physics-Based Realism Is Easier Than You Might Think

Adding Physics Won’t Affect Game Performance

Knowing Some Physics Will Make You a Better Game Programmer

TSBK03: Physics, Ht2010 8

Basic Concepts

Systems of Units

TSBK03: Physics, Ht2010 9

Basic Concepts

Coordinate Systems and Frames of Reference

TSBK03: Physics, Ht2010 10

Basic Concepts

Coordinate Systems and Frames of Reference

TSBK03: Physics, Ht2010 11

Basic Concepts

Scalars and Vectors

kzjyixR

kVjViVV zyx

kzzjyyixxRR

)()()( 21212121 Sum of vectors:

Magnitude of a vector: 222 zyxR

Vector scalar product: 21212121 zzyyxxRR

Vector cross product: kyxyxjxzxzizyzyRR

)()()( 12211221122121

TSBK03: Physics, Ht2010 12

Basic Concepts

Matrices

Derivatives

Differential Equations

TSBK03: Physics, Ht2010 13

Basic Kinematics

X

Y

XY

t

)( otr )(tr

)()()( trdt

tvdta

acceleration

2sm

)()()( trdt

trdtv

Instantaneous velocity

sm

o

oaverage tt

trtrv

)()(

Average velocity

sm

)()()( otrtrtr Displacement m

2

1

t

t

drsDistance m

t

t

t

too

t

to

o oo

dttattvtrdttvtrtr )()()()()()(

TSBK03: Physics, Ht2010 14

Basic Newtonian

Mechanics

Newton’s three laws of motion

Some special types of forces—gravitational, friction, centripetal, and spring

The concept of a force vector

Force balances and force diagrams

Work

Energy

Power

Rotational Motion

Many-Particle Interactions

TSBK03: Physics, Ht2010 15

Every body preserves in its state of rest, or of uniform in a right line, unless it is compelled to change that state by forces impressed thereon.

Newton’s

First Law of Motion: Inertia

Basic Newtonian

Mechanics

TSBK03: Physics, Ht2010 16

amF

The alteration of motion is ever proportional to the motive force impressed

Basic Newtonian

Mechanics

Newton’s Second Law of Motion: Force, Mass, and Acceleration

TSBK03: Physics, Ht2010 17

To every action there is always opposed an equal reactionTo every action there is always opposed an equal reaction

Basic Newtonian

Mechanics

Newton’s Third Law of Motion: Equal and Opposite Forces

TSBK03: Physics, Ht2010 18

Types of Forces

Centripetal Force

rmvF

2

Basic Newtonian

Mechanics

TSBK03: Physics, Ht2010 19

123

12

21 RR

MMGF

gM

2

2

21110674.6

kgNmG

kgN

mkg

kgNmg 81.9

10375,6109736.510674.6 26

24

2

211

Basic Newtonian

Mechanics

Types of Forces

Gravitational Force

TSBK03: Physics, Ht2010 20

Quantity Differential Equation Solution

Acceleration None ga

Velocity gdtvd

tgvv 0

Locationg

dtrd

2

2

tgvvdtrd

0

20 2

1 tgtvrr o

Basic Newtonian

Mechanics

Types of Forces

Gravitational Force

Equations

of motion

TSBK03: Physics, Ht2010 21

Quantity Differential Equation Solution

Acceleration None ,gaz

X Y

Z g

0,0 yx aa

Velocity gadtdv

zz ,0 gtvv zz

00 , yyxx vvvv

gadt

zdz 2

2

Location

gtvvdtdz

zz 0

,21 2

0 gttvzz zo

,0tvxx xo

tvyy yo 0

Basic Newtonian

Mechanics

Types of Forces

Gravitational Force

Equations

of motion for projections

TSBK03: Physics, Ht2010 22

NF FF

Basic Newtonian

Mechanics

Types of Forces

Friction

TSBK03: Physics, Ht2010 23

Friction

Friction Coefficients for Some Common Surface Interactions

Basic Newtonian

Mechanics

TSBK03: Physics, Ht2010 24

Springs

xkF

Hooke’s Law

Equation of motion: kxxm

02 xx mk

2

)sin()( otAtx Solution:

Basic Newtonian

Mechanics

TSBK03: Physics, Ht2010 25

Force balance

Basic Newtonian

Mechanics

TSBK03: Physics, Ht2010 26

Work

]JNm,,smkg[ 2

2

rFW

2

1

r

r

rdFW

TSBK03: Physics, Ht2010 27

Energy

Kinetic

Energy

2

2mvEk

Kinetic energy is the energy of an object due to its motion

mp2

2

TSBK03: Physics, Ht2010 28

Energy

Potential Energy

2

2xkEp

mghEp

Potential energy is the energy of an object due to its location

TSBK03: Physics, Ht2010 29

Energy

Other

Forms of Energy

Thermal energy

Chemical energy

Nuclear energy

Electromagnetic energy

TSBK03: Physics, Ht2010 30

Power

Power is defined as the amount of work performed per unit time.

tWN

]watt,sJ[

TSBK03: Physics, Ht2010 31

Rotational Motion

Definitions

v

Angular position: )(t

Angular velocity: )()( tt 1s

Frequency: 2

f 1s

Tangential velocity:

sm

)()()( trttv

2sm

Tangential acceleration: )()()( trtdtdta

)()()()()( trtttrt

Angular acceleration: 2s)()()( ttt

TSBK03: Physics, Ht2010 32

Rotational Motion

Torque

NmTorque: FrM

TSBK03: Physics, Ht2010 33

Rotational Motion

Moment of inertia

I

[kgm2]

]mkg[ 22V

dmrI]mkg[ 22i

iirmI

Kinetic

energy

2

2IT

zzyzxz

yzyyxy

xzxyxx

IIIIIIIII

J

Inertia

tensor

JL

JM

JL ˆ

JM ˆ

N

kkkkxx zymI

1

22 )(

N

kkkkyy zxmI

1

22 )(

N

kkkkzz yxmI

1

22 )(

N

kkkkyxxy yxmII

1

N

kkkkzxxz zxmII

1

N

kkkkzyyz zymII

1

Presenter
Presentation Notes
I motsvarar massa men tar även hänsyn till utbredningen r - sträckan från rotationsaxeln Tröghetsmatris

TSBK03: Physics, Ht2010 34

Many-Particle Interactions

For an N particles system, in equilibrium

1

2f21

f13

3

f12

f31

f23

f32

F3

F1

resultant force 0

0i

iF

resultant moment (torque) 0

0i

ii Fr

i

iii

i vmpP

iii

iii vmrprL

TSBK03: Physics, Ht2010 35

Conservation laws

constmi

i

constEi

i

constPi

i

0i

iL

TSBK03: Physics, Ht2010 36

Projectiles

Topics

The gravity-only

model

Aerodynamic drag

Laminar and turbulent flow

Wind effects

Spin effects

Details on specific types of projectiles including bullets, cannonballs, and arrows

TSBK03: Physics, Ht2010 37

Projectiles

The gravity-only

model

gdtvd

gdt

rd

2

2

or

Equation of motion:

Solution:

tgvv 0

20 2

1 tgtvrr o

,0 gtvv yy

,21 2

0 gttvyy yo

0xx vv

,0tvxx xo

or

TSBK03: Physics, Ht2010 38

Projectiles

The gravity-only

model

Golf Game

…Java_Code\Chapter05_Projectile\GolfGame.java (from www.apress.com/book/downloadfile/2078)

TSBK03: Physics, Ht2010 39

Projectiles

The gravity-only

model

Summary

o

The only

force

on the projectile

is due

to gravity, which

acts

in the vertical.

o

The motion in the three

coordinate

directions

is independent.

o

The projectile

trajectory

is independent of mass

and projectile

geometry.

o

The velocity

in the x-

and y-directions

is constant

over the entire

trajectory

and is equal

to the initial velocities

in the x-

and y-direction.

o

The shape

of the projectile

trajectory

is a parabola.

TSBK03: Physics, Ht2010 40

Projectiles

Aerodynamic drag

Basic Concepts

FrictionDpressureDDrag FFF ,,

Total dragPressure drag

Friction drag (or skin drag)

TSBK03: Physics, Ht2010 41

Projectiles

Aerodynamic drag

Drag Coefficient

Drag force

Drag coefficient Effective areaDensity of the fluid

Velocity

TSBK03: Physics, Ht2010 42

Projectiles

Aerodynamic drag

Drag Coefficiento

Laminar

and Turbulent Flow

(Re)DD CC

vL

Re

The drag coefficient of a sphere as a function of Reynolds number

TSBK03: Physics, Ht2010 43

Projectiles

Aerodynamic drag

Drag Coefficiento

Laminar

and Turbulent Flow

(Re)DD CC

vL

Re

Laminar and Turbulent Drag Coefficients

TSBK03: Physics, Ht2010 44

Projectiles

Aerodynamic drag

Drag Coefficiento

Altitude

Effects

on Density

Values of Air Density As a Function of Altitude

TSBK03: Physics, Ht2010 45

Projectiles

Aerodynamic drag

Equations

of motion

vvFgmF D

rr

m

Fgr

D

TSBK03: Physics, Ht2010 46

Projectiles

Aerodynamic drag

Golf Game Version 2

…Java_Code\Chapter05_Projectile\GolfGame2.java (from www.apress.com/book/downloadfile/2078)

TSBK03: Physics, Ht2010 47

Projectiles

Aerodynamic drag

Summaryo

Drag force

acts

in the opposite

direction

to the velocity. The magnitude

of the drag force

is proportional to the square

of the velocity.

o

The three

components

of motion are coupled

when

drag is taken into

account.

o

The drag force

is a function

of the projectile

geometry.

o

The acceleration due to drag is inversely proportional to the mass of the projectile.

o

The drag on an object is proportional to the density of the fluid in which it is traveling.

TSBK03: Physics, Ht2010 48

Projectiles

Wind Effect

Equations

of motion

vvFgmF D

rr

m

Fgr

D

Apparent velocity is the vector sum of the projectilevelocity and wind velocity.

TSBK03: Physics, Ht2010 49

Projectiles

Wind Effect

Golf Game Version 3

…Java_Code\Chapter05_Projectile\GolfGame3.java (from www.apress.com/book/downloadfile/2078)

The effects of headwind or tailwind on a golf ball trajectory

TSBK03: Physics, Ht2010 50

Projectiles

Wind Effect

Summary

o

The presence

of wind

changes

the apparent

velocity

seen

by the projectile

in flight. A headwind

will

increase

the apparent

velocity. A tailwind

will

decrease

it.

o

The wind velocity affects the drag force in all three coordinate

directions even if the wind velocities themselves are only in the x-

and z-planes.

TSBK03: Physics, Ht2010 51

Projectiles

Projectiles

Spin Effect

Bernoulli’s equation: constghvp 2

21

pressurethe fluid density

velocityaltitude

constvp 2

21

(h=const)

A spinning object generates lift

TSBK03: Physics, Ht2010 52

Projectiles

Spin Effect

Magnus force

Equation

of motion

vv

AvCF LM

2

2

The Magnus force lift coefficient

vrCL

For a sphere:

vrCL2

For a cylinder:

vvvC

vvFgmF LD

2

2

r

r

m

rC

rr

m

Fgr L

D

2

2

TSBK03: Physics, Ht2010 53

Projectiles

Spin Effect

Golf Game Version 4

…Java_Code\Chapter05_Projectile\GolfGame4.java (from www.apress.com/book/downloadfile/2078)

The effect of spin on golf ball flight

TSBK03: Physics, Ht2010 54

Projectiles

Spin Effect

Golf Game Version 4

…Java_Code\Chapter05_Projectile\GolfGame4.java (from www.apress.com/book/downloadfile/2078)

A tilt in the spin axis causes the ball to curve

TSBK03: Physics, Ht2010 55

Projectiles

Spin Effect

Summary:

o

An object

given backspin will

generate

a lifting

force. An object

given topspin will

generate

a force

that will

push

the object

downwards.

o

The acceleration that results

from Magnus force

is inversely

proportional to mass. A heavier

object

will

experience

less acceleration than

a similar, lighter

object.

o

The magnitude

of Magnus force

depends

on the geometry. All other

things

being

equal, larger

objects

will

generate

a larger

Magnus force

than

will

smaller

objects.

TSBK03: Physics, Ht2010 56

Projectiles

Details on Specific Types of Projectiles

Bullets

Shadowgraph of .308 Winchester FMJ bullet traveling at approximately 850 m/s

(from www.nennstiel-ruprecht.de)Bullets usually have a yaw angle during flight

TSBK03: Physics, Ht2010 57

Projectiles

Details on Specific Types of Projectiles

Bullets

TSBK03: Physics, Ht2010 58

Collisions

Specific topics

Linear

momentum

and impulse

Conservation

of linear

momentum

Two-body

linear

collisions

Elastic

and inelastic

collisions

Collision

detection

Collision

response

Collisions

with Friction

TSBK03: Physics, Ht2010 59

Collisions

Linear

momentum

and impulse

vmP

dtPdF

The linear momentum

Newton’s 2nd law

i

i constP

Conservation of Linear Momentum

TSBK03: Physics, Ht2010 60

Collisions

Elastic

Collisions

A perfectly elastic collision is defined as one in whichthere is no loss of kinetic energy in the collision.

Before After

i

ii vm2

2

i

ii vm2

2

TSBK03: Physics, Ht2010 61

Collisions

Inelastic

Collisions

Before the collision

After the collision

An inelastic collision is one in which part of the kinetic energy is changed to some other form of energy in the collision

i

ii vm2

2

i

ii vm2

2

TSBK03: Physics, Ht2010 62

Collisions

Elastic

and Inelastic

Collisions

coefficient of restitution

21

21

vv

vve

10 e

…Java_Code\Chapter06_Collision\SphereCollision.java (from www.apress.com/book/downloadfile/2078)

TSBK03: Physics, Ht2010 63

Collisions

Collision

detection

Gilbert-Johnson-Keerthi

(GJK) algorithm

Minkowski

Addition

The Minkowski sum of a box and a sphere.

TSBK03: Physics, Ht2010 64

Collisions

Collision

detection

Gilbert-Johnson-Keerthi

(GJK) algorithm

Minkowski

”difference”

(Configuration

space

obstacle

(CSO) )

TSBK03: Physics, Ht2010 65

Collisions

Collision

detection

Gilbert-Johnson-Keerthi

(GJK) algorithm

The negated shape -B and the Minkowski sum A⊕(-B).

The two shapes for our GJK example.

TSBK03: Physics, Ht2010 66

Collisions

Collision

detection

Gilbert-Johnson-Keerthi

(GJK) algorithm

The first step of the GJK algorithm, on separate objects (left) and combined (right)

TSBK03: Physics, Ht2010 67

Collisions

Collision

detection

Gilbert-Johnson-Keerthi

(GJK) algorithm

The first step of the GJK algorithm, on separate objects (left) and combined (right)

TSBK03: Physics, Ht2010 68

Collisions

Collision

response

Ar

n

Brp

AX

BX

A

B

)(tXpr AA

)(tXpr BB

AAApA rvv BBBpB rvv

pBpArel vvv

njPimp

AAA mnjvv /

BBB mnjvv / nrIjnjrI AAAAAAA

11 ˆˆ

nrIjnjrI BBBBBBB

11 ˆˆ relrel vv

nrvrvnvvv BBBAAApBpArel )()( nrvrvnvvv BBBAAApBpArel

)()(

nrnrImnrnrImnjv BBBBAAAArel )ˆ/ˆ/( 11

nrnrIrnrIjmjmjv BBBAAABArel )ˆˆ(//)1( 11

nrnrIrnrImmvj

BBBAAABA

rel

)ˆˆ(/1/1)1(

11

(1)

(2)

(3)

(4)

(5)

(6)

(7)

(9)(8)

(10)

TSBK03: Physics, Ht2010 69

Collisions

Collisions

with Friction

When two objects collide obliquely, they will slide against each other for a brief period of time.

The frictional impulse acts in the direction normal to the line of action and causes rotations of the objects

n

1n

The frictional impulse )(ˆab PPnF

1

11̂ˆr

IF

2

22ˆˆ

rIF

TSBK03: Physics, Ht2010 70

Collisions

Summary

The change in velocity that results from a collision can be characterized by a linear or angular impulse.

The post-collision velocities of two objects after a collision can be determined from the principle of conservation of momentum and the coefficient of restitution for the collision.

For frictionless collisions, only the velocity in the direction of the line of action of a collision is affected by the collision. The other velocity components normal to the line of action are unchanged.

For collisions that involve friction, the resulting frictional impulse reduces the magnitude of the velocity in the direction normal to the line of

action and causes the objects to spin.

TSBK03: Physics, Ht2010 71

Sports Simulations

Topics to be considered

Golf

Soccer

Basketball

Other games

TSBK03: Physics, Ht2010 72

Sports Simulations

Golf

Golf Ball Specifications

A model for simulation includes the mass of the club head, the mass of the ball, the velocity of the club head at impact, and the angle of the impact.

Schematic of a club head—golf ball collision

nnvmm

mev CBallC

CBall

lub

lub

lub)1(

nnvv Ccp

lub

nnvvv CCcn

lublub

TSBK03: Physics, Ht2010 73

Sports Simulations

Golf

Friction Effects

Friction between the ball and club face causes the ball to spin

The friction force does two things: 1) it reduces the relative velocity between the club and ball, and 2) it generates a torque on the ball that causes it to spin.

rIvvm nn

)(

rvn

21mrI

vv nn

2

52 mrI

nn vv75

rvn

75

22 sin

72cos)1( e

mmmvv

BC

CCxBx

75cossin e

mmmvv

BC

CCxBz

TSBK03: Physics, Ht2010 74

Sports Simulations

Golf

Modeling the Golf Ball in Flight

Force diagram for a golf ball in flight

vrCL

vrCL36.00025.005.0

Experimental and computed lift coefficients for a standard golf ball

Experimental data

vv

AvCF LM

2

2

TSBK03: Physics, Ht2010 75

Sports Simulations

Golf

…Java_Code\Chapter07_Sports\GolfGame.java (from www.apress.com/book/downloadfile/2078)

A blow-up shot results from too much spin on the ball

TSBK03: Physics, Ht2010 76

Sports Simulations

Soccer

Modeling the Soccer Ball in Flight

Laminar and Turbulent Drag

AvCF DD 2

2

Drag coefficient of a nonspinning soccer ball

vL

ReThe Reynolds number:

The viscosity of air:4.110

10456.15.1

6

TT

TSBK03: Physics, Ht2010 77

Sports Simulations

Soccer

Modeling the Soccer Ball in Flight

Magnus Force v

vvCF LM

2

2

Experimental and computed soccer ball lift coefficients

Experimental data

25.0

35.0

vrCL

TSBK03: Physics, Ht2010 78

Sports Simulations

Soccer

Free-Kick Game

…Java_Code\Chapter07_Sports\FreeKick.java (from www.apress.com/book/downloadfile/2078)

The Free-Kick Game screen shot

TSBK03: Physics, Ht2010 79

Sports Simulations

Basketball

Equipment Specifications

The Radius, Diameter, and Mass of Regulation Men’s Basketballs

A schematic of the location of the basket, lane, and free-throw line

Court Dimensions

TSBK03: Physics, Ht2010 80

Sports Simulations

Basketball

Equipment Specifications

Basket and backboard schematics

Basket and Backboard Dimensions

TSBK03: Physics, Ht2010 81

Sports Simulations

Basketball

Evaluating the Forces on a Basketball in Flight

Force and Acceleration Components Acting on a Basketball

For a shot to be good, it must travel through the hoop

TSBK03: Physics, Ht2010 82

Sports Simulations

Basketball

A Free-Throw Game

A screen shot of the Free-Throw Game

…Java_Code\Chapter07_Sports\FreeThrow.java (from www.apress.com/book/downloadfile/2078)

TSBK03: Physics, Ht2010 83

Sports Simulations

Specific of simulation of other games

Baseball

Football

Hockey

Tennis

TSBK03: Physics, Ht2010 84

Sports Simulations

Summary

When a ball (or person for that matter) is in the air, it can be

treated as projectile and will be subject to the forces due to gravity, aerodynamic drag, wind, and spin.

The Magnus force due to spin is very important for the sports of

golf, soccer, and baseball. The magnitude of the force due to spin can be obtained by determining the lift coefficient for the object in question.

At times the effects of wind and spin can be ignored, for example, when simulating the flight of a basketball.

There are also instances, for example soccer and baseball, when it is probably better for game programming purposes not to try to model the initial collision, but rather to begin the simulation by specifying the post-collision velocity, spin rate, and spin axis of the ball.

TSBK03: Physics, Ht2010 85

Cars and Motorcycles

Topics to be considered

The basic force diagram of a car

Power and Torque

TSBK03: Physics, Ht2010 86

Cars and Motorcycles

Basic Force Diagram

0 Dfw

g FFrTF

TSBK03: Physics, Ht2010 87

Cars and Motorcycles

Torque

A typical torque curve

The engine torque is a function of the rate at which the engine is turning over

TSBK03: Physics, Ht2010 88

Cars and Motorcycles

Power and Torque

eee TP

The power curve for the 2004 Boxster S

TSBK03: Physics, Ht2010 89

Cars and Motorcycles

Gears and Wheel Torque

A cross-section of a transmission (Photo courtesy of Daimler-Chrysler).

Gears are used to change angular velocity and torque.

TSBK03: Physics, Ht2010 90

Cars and Motorcycles

Gears and Wheel Torque

Porsche Boxster S Gear Ratios Theoretical Maximum Velocity for Each Gear for the Boxster S