Game Physics

32
1 Game Physics Game Physics

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 of Game Physics

Page 1: Game Physics

1

Game PhysicsGame Physics

Page 2: 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 2

Introduction to Game PhysicsIntroduction to Game Physics

Page 3: Game Physics

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

3

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

Page 4: Game Physics

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

4

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

Page 5: Game Physics

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

... .

Page 6: Game Physics

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

Page 7: Game Physics

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]; }}

Page 8: Game Physics

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++); }}

Page 9: Game Physics

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; }}

Page 10: Game Physics

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;}

Page 11: Game Physics

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 11

Rigid Body DynamicsRigid Body Dynamics

Page 12: Game Physics

Spring-mass modelSpring-mass 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

12

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

Page 13: Game Physics

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

Page 14: Game Physics

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 ( 人體物理模擬人體物理模擬 ))

Page 15: Game Physics

15

Game FXGame FX

Page 16: Game Physics

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 tools can not do itGeneral 3D animation tools can not do it

» Key-frame system is not workingKey-frame system is not 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 Effect16

Introduction to Game FXIntroduction to Game FX

Page 17: Game Physics

17

FX Editing ToolFX Editing Tool

Page 18: Game Physics

18

Game Particle Effects Game Particle Effects

Conquer Online

Page 19: Game Physics

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 FXCombat FX

Page 20: Game Physics

2020

Combat FX Example Combat FX Example

Page 21: Game Physics

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 – Image SolutionMotion Blur – Image Solution

Page 22: Game Physics

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

Motion Blur – Geometry SolutionMotion Blur – Geometry Solution

Page 23: Game Physics

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

FX Uses Texture AnimationFX Uses Texture Animation

Page 24: Game Physics

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

Particle System for FXs in CombatParticle System for FXs in Combat

Page 25: Game Physics

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

Environment FXEnvironment FX

Page 26: Game Physics

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

Character FXCharacter FX

Page 27: Game Physics

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 – Sky BoxScene FX – Sky Box

Page 28: Game Physics

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 – Len’s FlareScene FX – Len’s Flare

Page 29: Game Physics

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)

29

Scene FX – Light ScatteringScene FX – Light Scattering

Skylight and sun lightSkylight and sun light Can be Implemented by vertex shader Can be Implemented by vertex shader

Page 30: Game Physics

30

Scene FX – Light Scattering ExamplesScene FX – Light Scattering Examples

With scatteringWithout scattering

Page 31: Game Physics

OGRE Particle SystemOGRE Particle System

31

OGRE Particle System Attributeshttp://www.ogre3d.org/docs/manual/manual_32.html

OGRE Particle Editorhttp://www.game-cat.com/ogre/pe/ParticleEditor_Beta.zip

OGRE Particle Editor Tutorialhttp://www.game-cat.com/ogre/pe/docs/PETutorial.htm

Page 32: Game Physics

Particle System Definition Particle System Definition Attributes (Partial)Attributes (Partial)

32

Attribute Name Value Format Description

quota <max_particles> Maximum number of particles at one time in the system (default 10).

material <name> Name of material used by all particles in the system (default none).

particle_width <width> Width of particles in world coordinates (default 100).

particle_height <height> Height of particles in world coordinates (default 100).

cull_each <true> | <false> Cull particles individually (default false).

sorted <true> | <false> Sort particles by depth from camera (default false).

billboard_type <point> | <oriented_common> | <oriented_self> |…

Billboard-renderer-specific attribute (default point).