game physics

29
1 Game Physics Game Physics

Upload: angela-gillespie

Post on 02-Jan-2016

27 views

Category:

Documents


1 download

DESCRIPTION

Game Physics. Introduction to Game Physics. Traditional Game Physics Particle system Rigid body dynamics Flexible body dynamics Some State-of-art Topics Car physics Fluid dynamics Rag-doll physics Physics Rigid body kinematics Newton’s Laws Forces Momenta Energy. - PowerPoint PPT Presentation

TRANSCRIPT

1

Game PhysicsGame Physics

2

Introduction to Game PhysicsIntroduction to Game Physics Traditional Game PhysicsTraditional Game Physics

– Particle systemParticle system– Rigid body dynamicsRigid body dynamics– Flexible body dynamicsFlexible body dynamics

Some State-of-art TopicsSome State-of-art Topics– Car physicsCar physics– Fluid dynamicsFluid dynamics– Rag-doll physicsRag-doll physics

PhysicsPhysics– Rigid body kinematicsRigid body kinematics– Newton’s LawsNewton’s Laws– ForcesForces– MomentaMomenta– EnergyEnergy

3

Basic Concepts from Physics (1/2)Basic Concepts from Physics (1/2)

Newton’s LawsNewton’s Laws– 11stst Law Law

» ““靜者恆靜,動者恆成等速度運動”靜者恆靜,動者恆成等速度運動”– 22ndnd Law Law

» F = ma = mF = ma = mv/v/tt

– 33rdrd Law Law» 作用力與反作用力作用力與反作用力

ForcesForces– Gravity / Spring forces / Friction / ViscosityGravity / Spring forces / Friction / Viscosity– TorqueTorque

= r X F= r X F

– EquilibriumEquilibrium

4

Basic Concepts from Physics (2/2)Basic Concepts from Physics (2/2)

MomentaMomenta– Linear momentumLinear momentum– Angular momentumAngular momentum– Moment of inertiaMoment of inertia

5

Particles are objects withParticles are objects with– MassMass– PositionPosition– VelocityVelocity– Respond to forcesRespond to forces

BBut no spatial extent (no size!)ut no spatial extent (no size!)– Point massPoint mass

BBased on Newton Lawsased on Newton Laws– ff = m = maa– xx = = f f / m/ m– vv = = ff / m, / m, xx = = vv

Particle DynamicsParticle Dynamics

... .

6

typedef struct { float m; /* mass */ float *x; /* position */ float *v; /* velocity */ float *f; /* force accumulator */} *Particle;

typedef struct { Particle *p /* array of pointers to particles */ int n; /* number of particles */ float t; /* simulation clock */} *ParticleSystem;

xvf

m

states

xvf

m

xvf

m

xvf

m

xvf

m

xvf

m

…Particle n time

Basic Particle SystemBasic Particle System

7

/* gather states from the particles */void ParticleGetState(ParticleSystem p, float *dst){ int i; for (i = 0; i < p->n; i++) { *(dst++) = p->p[I]->x[0]; *(dst++) = p->p[I]->x[1]; *(dst++) = p->p[I]->x[2]; *(dst++) = p->p[I]->v[0]; *(dst++) = p->p[I]->v[1]; *(dst++) = p->p[I]->v[2]; }}

8

/* scatter states into the particles */void ParticleSetState(ParticleSystem p, float *src){ int i; for (i = 0; i < p->n; i++) { p->p[i]->x[0] = *(src++); p->p[i]->x[1] = *(src++); p->p[i]->x[2] = *(src++); p->p[i]->v[0] = *(src++); p->p[i]->v[1] = *(src++); p->p[i]->v[2] = *(src++); }}

9

/* calculate derivative, place in dst */void ParticleDerivative(ParticleSystem p, float *dst){ int i;

ClearForce(p); ComputeForce(p);

for (i = 0; i < p->n; i++) { *(dst++) = p->p[i]->v[0]; *(dst++) = p->p[i]->v[1]; *(dst++) = p->p[i]->v[2]; *(dst++) = p->p[i]->f[0]/p->p[i]->m; *(dst++) = p->p[i]->f[1]/p->p[i]->m; *(dst++) = p->p[i]->f[2]/p->p[i]->m; }}

10

/* Euler Solver */void EulerStep(ParticleSystem p, float DeltaT){ ParticleDeriv(p, temp1); ScaleVector(temp1, DeltaT); ParticleGetState(p, temp2); AddVector(temp1, temp2, temp2); ParticleSetState(p, temp2); p->t += DeltaT;}

11

Rigid Body DynamicsRigid Body Dynamics

Mass of a BodyMass of a Body– Mass centerMass center

ForceForce– Linear momentumLinear momentum– P(t) = M v(t)P(t) = M v(t)– Velocity (Velocity (vv))

TorqueTorque– Angular momentumAngular momentum– L(t) = I L(t) = I (t)(t)– Local rotation (Local rotation ())

Inertia TensorInertia Tensor ReferenceReference

– www-2.cs.cmu.edu/afs/cs/user/baraff/www/pbmwww-2.cs.cmu.edu/afs/cs/user/baraff/www/pbm

12

Flexible Body Dynamics (1/2)Flexible Body Dynamics (1/2)

Particle-Spring ModelParticle-Spring Model– F = k xF = k x – Not a stress-strain modelNot a stress-strain model– Lack of Elasticity, Plasticity, & Viscous-ElasticityLack of Elasticity, Plasticity, & Viscous-Elasticity– Can be unstableCan be unstable

13

Flexible Body Dynamics (2/2)Flexible Body Dynamics (2/2)

Finite Element MethodFinite Element Method– Solver for ODE/PDESolver for ODE/PDE– Boundary conditionsBoundary conditions– Energy equationEnergy equation– Stress-strain modelStress-strain model– Very complicated computing processVery complicated computing process

Conservation of EnergyConservation of Energy

14

Advanced Topics in Game PhysicsAdvanced Topics in Game Physics

Fracture Mechanics (Fracture Mechanics ( 破壞力學模擬破壞力學模擬 )) Fluid Dynamics (Fluid Dynamics ( 流體力學流體力學 )) Car Dynamics (Car Dynamics ( 車輛動力學車輛動力學 )) Rag-doll Physics (Rag-doll Physics ( 人體物理模擬人體物理模擬 ))

15

Game FXGame FX

16

Introduction to Game FXIntroduction to Game FX Improve the Visual & Sound Game EffectsImprove the Visual & Sound Game Effects IncludesIncludes

– Combat FXCombat FX– Environment FXEnvironment FX– Character FXCharacter FX– Scene FXScene FX– Sound FXSound FX

FX Editor NeededFX Editor Needed– General 3D animation can not do itGeneral 3D animation can not do it

» Key-frame system is nor workingKey-frame system is nor working» FX animation is alwaysFX animation is always

ProcedurallyProcedurally Related to the previous frameRelated to the previous frame

Small Work But Large EffectSmall Work But Large Effect

17

FX Editing ToolFX Editing Tool

18

Combat FXCombat FX

During the CombatDuring the Combat– Weapon motion blurWeapon motion blur– Weapon effectWeapon effect– Skill effectSkill effect

After the CombatAfter the Combat– Damage effectDamage effect

FX EditorFX Editor

19

Combat FX ExampleCombat FX Example

20

Motion Blur – Image SolutionMotion Blur – Image Solution

Computer Animation :Computer Animation :– Image solutionImage solution– Blending rendered image sequenceBlending rendered image sequence

» Render too many framesRender too many frames» Divide the framesDivide the frames» AverageAverage» Done!Done!

21

Motion Blur – Geometry SolutionMotion Blur – Geometry Solution

In Games, Use Transparent Objects to In Games, Use Transparent Objects to Simulate the Motion BlurSimulate the Motion Blur

““False” Motion BlurFalse” Motion Blur– Tracking the motion path of the objectTracking the motion path of the object– Connecting them as a triangular meshConnecting them as a triangular mesh– Use time-dependent semi-transparency to simulate Use time-dependent semi-transparency to simulate

the “blur”the “blur”– The path can be smoothed using Catmull-Rom The path can be smoothed using Catmull-Rom

splinespline» Local stability of the curveLocal stability of the curve

22

FX Uses Texture AnimationFX Uses Texture Animation Almost All Game FXs Use this TrickAlmost All Game FXs Use this Trick Geometry Object on which the Texture Geometry Object on which the Texture

Animation PlayingAnimation Playing– BillboardBillboard– 3D Plate3D Plate– CylinderCylinder– SphereSphere– Revolving a cross section curveRevolving a cross section curve

Texture Sequence with Color-keyTexture Sequence with Color-key Semi-transparent TexturesSemi-transparent Textures

– Alpha blendingAlpha blending» Source color added to backgroundSource color added to background

Demo!!!!Demo!!!!

23

Particle System for FXs in CombatParticle System for FXs in Combat The FXsThe FXs

– Fire / exposure / smoke / dustFire / exposure / smoke / dust Initial Value + Time dependencyInitial Value + Time dependency Combined with Billboard FXCombined with Billboard FX

– Billboard to play the texture animationBillboard to play the texture animation– Particle system to calculate the motion pathParticle system to calculate the motion path

Gravity is the major force usedGravity is the major force used Emitter patternEmitter pattern

– Single emitterSingle emitter– Area emitterArea emitter– Emitter on verticesEmitter on vertices

Demo !!!Demo !!!

24

Environment FXEnvironment FX

WeatherWeather– Use particle systemUse particle system

» RainRain» SnowSnow» WindWind

FogFog– Traditional fogTraditional fog

» From near to farFrom near to far» Hardware standard featureHardware standard feature

– Volume fogVolume fog» Layered fogLayered fog» Use vertex shaderUse vertex shader

Day & NightDay & Night

25

Character FXCharacter FX

FatalityFatality– Case by case and need creative solutionsCase by case and need creative solutions

Rendering Effects on SkinsRendering Effects on Skins– Environment mappingEnvironment mapping– Bump mapBump map– Normal mapNormal map– Multiple texture mapMultiple texture map

Flexible bodyFlexible body– Flexible body dynamicsFlexible body dynamics

FurFur– Real-time fur renderingReal-time fur rendering

……

26

Scene FX – Sky BoxScene FX – Sky Box

Use a very large box or dome-like model to Use a very large box or dome-like model to surround the whole game scenesurround the whole game scene

Use textures on the box or dome as the Use textures on the box or dome as the backdropbackdrop

Use multiple textures and texture coordinates Use multiple textures and texture coordinates animation to simulate the moving of the cloudsanimation to simulate the moving of the clouds

27

Scene FX – Len’s FlareScene FX – Len’s Flare

Runtime calculate the position and orientation Runtime calculate the position and orientation of the camera with the sunof the camera with the sun

Put textures to simulate the len’s flare Put textures to simulate the len’s flare

28

Scene FX – Light ScatteringScene FX – Light Scattering

Atmospheric Light ScatteringAtmospheric Light Scattering Caused by dust, molecules, or water vaporCaused by dust, molecules, or water vapor

– These can cause light to be:These can cause light to be:» Scattered into the line of sight Scattered into the line of sight (in-scattering)(in-scattering)

» Scattered out of the line of sight Scattered out of the line of sight (out-scattering)(out-scattering)

» Absorbed altogether Absorbed altogether (absorption)(absorption)

Skylight and sun lightSkylight and sun light Can be Implemented by Vertex Shader Can be Implemented by Vertex Shader

29

Scene FX – Light Scattering ExamplesScene FX – Light Scattering Examples

With scatteringWithout scattering