13_3dgp_gamephyics

Upload: vin-mamuric-meneses

Post on 08-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 13_3DGP_GamePhyics

    1/32

    1

    Game PhysicsGame Physics

  • 8/7/2019 13_3DGP_GamePhyics

    2/32

    Tr aditional game physicsTr aditional game physics

    Pa r ticle systemPa r ticle system Rigid body dynamicsRigid body dynamics Flexible body dynamicsFlexible body dynamics

    Some stateSome state- -ofof--a r t topicsa r t topics

    Ca r physicsCar physics Fluid dynamicsFluid dynamics RagRag--doll physicsdoll physicsPhysicsPhysics

    Rigid body kinematicsRigid body kinematics Newtons LawsNewtons Laws Fo rcesForces MomentaMomenta Ene rgyEne rgy

    2

    Introduction to Game PhysicsIntroduction to Game Physics

  • 8/7/2019 13_3DGP_GamePhyics

    3/32

    Newtons LawsNewtons Laws

    11stst

    LawLaw

    22ndnd LawLaw F = ma = mF = ma = m HHv/v/ HHtt

    33rdrd

    LawLaw

    ForcesForces G rav ity / Spr ing fo rces / Fr iction / ViscosityGrav ity / Spr ing fo rces / Fr iction / Viscosity

    Torq ueTorq ue XX = r X F= r X F

    Equilib r iumEquilib r ium

    3

    B asic Concepts from Physics (1/2)B asic Concepts from Physics (1/2)

  • 8/7/2019 13_3DGP_GamePhyics

    4/32

    MomentaMomenta

    Linea r momentumLinea r momentum Angula r momentumAngula r momentum Moment of ine r tiaMoment of ine r tia

    4

    B asic Concepts from Physics (2/2)B asic Concepts from Physics (2/2)

  • 8/7/2019 13_3DGP_GamePhyics

    5/32

    5

    Pa r ticles a re objects withPa r ticles a re objects with

    MassMass PositionPosition VelocityVelocity

    Respond to fo rcesRespond to fo rcesBBut no spatial extent (no size!)ut no spatial extent (no size!)

    Point massPoint mass

    BBased on Newton Lawsased on Newton Laws f f = m= m aa x x == f f / m/ m v v == f f / m,/ m, x x == vv

    Particle DynamicsParticle Dynamics

    ..

    . .

  • 8/7/2019 13_3DGP_GamePhyics

    6/32

    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;

    x

    v

    f m

    states

    x

    v

    f

    m

    x

    v

    f

    m

    x

    v

    f

    m

    x

    v

    f

    m

    x

    v

    f

    m

    P article n time

    B asic Particle SystemB asic Particle System

  • 8/7/2019 13_3DGP_GamePhyics

    7/32

    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/7/2019 13_3DGP_GamePhyics

    8/32

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

    }}

  • 8/7/2019 13_3DGP_GamePhyics

    9/32

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

    }

  • 8/7/2019 13_3DGP_GamePhyics

    10/32

    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;

    }

  • 8/7/2019 13_3DGP_GamePhyics

    11/32

    Mass of a BodyMass of a Body

    Mass cente rMass cente rForceForce Linea r momentumLinea r momentum P(t) = M v (t)P(t) = M v (t)

    Velocity (Velocity ( v v ))Torq ueTorq ue Angula r momentumAngula r momentum L(t) = IL(t) = I [ [ (t)(t) Local rotation (Local rotation ( [ [ ))

    Ine r tia Tenso rIne r tia Tenso rRefe renceRefe rence wwwwww--2 . cs . cmu . edu / afs / cs / use r / ba raff / www / pbm2. cs . cmu . edu / afs / cs / use r / ba raff / www / pbm 11

    R igid B ody DynamicsR igid B ody Dynamics

  • 8/7/2019 13_3DGP_GamePhyics

    12/32

    Spr ingSpr ing--mass modelmass model

    F = k x F = k x Not a st ressNot a st ress--st rain modelst rain model Lack of Elasticity, Plasticity, & ViscousLack of Elasticity, Plasticity, & Viscous- -ElasticityElasticity Can be unstableCan be unstable

    12

    F lexible B ody Dynamics (1/2)F lexible B ody Dynamics (1/2)

  • 8/7/2019 13_3DGP_GamePhyics

    13/32

    13

    F lexible B ody Dynamics (2/2)F lexible B ody Dynamics (2/2)

    Finite element methodFinite element method

    (( )) Sol v e r fo r ODE/ PDESolv e r fo r ODE/ PDE Bounda ry conditionsBounda ry conditions Ene rgy e quationEne rgy e quation

    St ressSt ress--st rain modelst rain model Ve ry complicated computing p rocessVery complicated computing p rocess

    Conse rv ation of ene rgyConse rv ation of ene rgy

  • 8/7/2019 13_3DGP_GamePhyics

    14/32

    14

    A dvanced Topics in Game PhysicsA dvanced Topics in Game Physics

    Fractu re Mechanics (Fractu re Mechanics ( ))

    Fluid Dynamics (Fluid Dynamics ( ))Car Dynamics (Car Dynamics ( ))RagRag--doll Physics (doll Physics ( ))

  • 8/7/2019 13_3DGP_GamePhyics

    15/32

    15

    Game FXGame FX

  • 8/7/2019 13_3DGP_GamePhyics

    16/32

    Imp rov e the Visual & Sound Game EffectsImp rov e the Visual & Sound Game Effects

    IncludesIncludes Combat FXCombat FX En v ironment FXEnv ironment FX Cha racte r FXCha racte r FX Scene FXScene FX Sound FXSound FX

    FX Edito r NeededFX Edito r Needed Gene ral 3D animation tools can not do itGene ral 3D animation tools can not do it

    KeyKey--f rame system is not wo rkingframe system is not wo rking FX animation is alwaysFX animation is always

    Procedu rallyProcedu rallyRelated to the p re v ious f rameRelated to the p re v ious f rame

    Small Wo rk But La rge EffectSmall Wo rk But La rge Effect16

    Introduction to Game FXIntroduction to Game FX

  • 8/7/2019 13_3DGP_GamePhyics

    17/32

    17

    FX Editing ToolFX Editing Tool

  • 8/7/2019 13_3DGP_GamePhyics

    18/32

    18

    Game Particle EffectsGame Particle Effects

    Conque r Online

  • 8/7/2019 13_3DGP_GamePhyics

    19/32

    Dur ing the CombatDur ing the Combat

    Weapon motion blu rWeapon motion blu r Weapon effectWeapon effect Skill effectSkill effect

    Afte r the CombatAfte r the Combat Damage effectDamage effect

    FX Edito rFX Edito r

    19

    Combat FXCombat FX

  • 8/7/2019 13_3DGP_GamePhyics

    20/32

  • 8/7/2019 13_3DGP_GamePhyics

    21/32

    Compute r Animation :Compute r Animation :

    Image solutionImage solution Blending rende red image se quenceBlending rende red image se quence

    Rende r too many f ramesRende r too many f rames Div ide the f ramesDiv ide the f rames Av e rageAv e rage Done!Done!

    21

    M otion B lurM otion B lur Image SolutionImage Solution

  • 8/7/2019 13_3DGP_GamePhyics

    22/32

    In Games, Use Tr anspa rent Objects to Simulate theIn Games, Use Tr anspa rent Objects to Simulate the

    Motion Blu rMotion Blu rFalse Motion Blu rFalse Motion Blu r Tr acking the motion path of the objectTr acking the motion path of the object Connecting them as a t r iangula r meshConnecting them as a t r iangula r mesh

    Use timeUse time- -dependent semidependent semi- -t ranspa rency to simulate thet ranspa rency to simulate theblu rblu r

    The path can be smoothed using CatmullThe path can be smoothed using Catmull- -Rom splineRom spline Local stability of the cu rv eLocal stability of the cu rv e

    22

    M otion B lurM otion B lur Geometry SolutionGeometry Solution

  • 8/7/2019 13_3DGP_GamePhyics

    23/32

    Almost All Game FXs Use this Tr ickAlmost All Game FXs Use this Tr ick

    Geomet ry Object on which the Textu re AnimationGeomet ry Object on which the Textu re AnimationPlayingPlaying Billboa rdBillboa rd 3D Plate3D Plate Cylinde rCylinde r Sphe reSphe re Re v olv ing a c ross section cu rv eRev olv ing a c ross section cu rv e

    Textu re Se quence with Colo rTextu re Se quence with Colo r--keykey

    SemiSemi--t ranspa rent Textu rest ranspa rent Textu res Alpha blendingAlpha blending Sou rce colo r added to backg roundSource colo r added to backg round

    Demo!!!!Demo!!!!23

    FX Uses Texture A nimationFX Uses Texture A nimation

  • 8/7/2019 13_3DGP_GamePhyics

    24/32

    The FXsThe FXs Fi re / exposu re / smoke / dustFire / exposu re / smoke / dust

    Initial Value + Time dependencyInitial Value + Time dependencyCombined with Billboa rd FXCombined with Billboa rd FX Billboa rd to play the textu re animationBillboa rd to play the textu re animation

    Pa r ticle system to calculate the motion pathPa r ticle system to calculate the motion pathGra v ity is the majo r fo rce usedGra v ity is the majo r fo rce usedEmitte r patte rnEmitte r patte rn Single emitte rSingle emitte r

    Area emitte rArea emitte r Emitte r on v e r ticesEmitte r on v e r tices

    Demo !!!Demo !!!24

    Particle System for FX s in CombatParticle System for FX s in Combat

  • 8/7/2019 13_3DGP_GamePhyics

    25/32

    Weathe rWeathe r

    Use pa r ticle systemUse pa r ticle system RainRain SnowSnow WindWind

    FogFog Tr aditional fogTr aditional fog

    F rom nea r to fa rFrom nea r to fa r Ha rdwa re standa rd featu reHardwa re standa rd featu re

    Volume fogVolume fog Laye red fogLaye red fog Use v e r tex shade rUse v e r tex shade r

    Day & NightDay & Night

    25

    Environment FXEnvironment FX

  • 8/7/2019 13_3DGP_GamePhyics

    26/32

    FatalityFatality

    Case by case and need c reati v e solutionsCase by case and need c reati v e solutionsRende r ing Effects on SkinsRende r ing Effects on Skins En v ironment mappingEnv ironment mapping Bump mapBump map

    No rmal mapNormal map Multiple textu re mapMultiple textu re map

    Flexible bodyFlexible body Flexible body dynamicsFlexible body dynamics

    FurFur RealReal--time fu r rende r ingtime fu r rende r ing

    26

    Character FXCharacter FX

  • 8/7/2019 13_3DGP_GamePhyics

    27/32

    Use a v e ry la rge box o r domeUse a v e ry la rge box o r dome--like model to su rr oundlike model to su rr oundthe whole game scenethe whole game scene

    Use textu res on the box o r dome as the backd ropUse textu res on the box o r dome as the backd ropUse multiple textu res and textu re coo rdinatesUse multiple textu res and textu re coo rdinatesanimation to simulate the mo v ing of the cloudsanimation to simulate the mo v ing of the clouds

    27

    Scene FX Scene FX Sky B oxSky B ox

  • 8/7/2019 13_3DGP_GamePhyics

    28/32

    Runtime calculate the position and o r ientation ofRuntime calculate the position and o r ientation of

    the came ra with the sunthe came ra with the sunPut textu res to simulate the lens fla rePut textu res to simulate the lens fla re

    28

    Scene FX Scene FX Lens F lareLens F lare

  • 8/7/2019 13_3DGP_GamePhyics

    29/32

    Atmosphe r ic light scatte r ingAtmosphe r ic light scatte r ing

    Caused by dust, molecules, o r wate r v apo rCaused by dust, molecules, o r wate r v apo r These can cause light to be:These can cause light to be:

    Scatte red into the line of sightScatte red into the line of sight (in(in--scatte r ing)scatte r ing) Scatte red out of the line of sightScatte red out of the line of sight (out(out--scatte r ing)scatte r ing) Abso rbed altogethe r Absorbed altogethe r (abso rption)(abso rption)

    29

    Scene FX Scene FX Light ScatteringLight Scattering

    Skylight and sun lightSkylight and sun lightCan be Implemented by v e r texCan be Implemented by v e r tex shade rshade r

  • 8/7/2019 13_3DGP_GamePhyics

    30/32

    30

    Scene FX Scene FX Light Scattering ExamplesLight Scattering Examples

    With scatte r ingWithout scatte r ing

  • 8/7/2019 13_3DGP_GamePhyics

    31/32

    OGRE Particle SystemOGRE Particle System

    31

    OGRE Par ticle System Att r ibuteshttp: // www . ogre3d . org/ docs / manual / manual_32 . html

    OGRE Par ticle Edito rhttp: // www . game-cat . com / ogre / pe / Pa r ticleEdito r_Beta . zip

    OGRE Par ticle Edito r Tuto r ialhttp: // www . game-cat . com / ogre / pe / docs / PETuto r ial . htm

  • 8/7/2019 13_3DGP_GamePhyics

    32/32

    Particle System DefinitionParticle System Definition

    Attributes (Partial)Attributes (Partial)

    32

    Attribute Name Value Format Description

    quota Maximum number of particles at one time in thesystem (default 10 ).

    material Name of material used by all particles in thesystem (default none).

    particle_width Width of particles in world coordinates (default100 ).

    particle_height Height of particles in world coordinates (default100 ).

    cull_each | Cull particles individually (default false).

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

    billboard_type | | |

    Billboard-renderer-specific attribute (defaultpoint).