Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Game Physics. 2 Introduction to Game Physics Traditional game physics Traditional game physics Particle system Particle system Rigid body dynamics Rigid.

Similar presentations


Presentation on theme: "1 Game Physics. 2 Introduction to Game Physics Traditional game physics Traditional game physics Particle system Particle system Rigid body dynamics Rigid."— Presentation transcript:

1 1 Game Physics

2 2 Introduction to Game Physics Traditional game physics Traditional game physics Particle system Particle system Rigid body dynamics Rigid body dynamics Flexible body dynamics Flexible body dynamics Some state-of-art topics Some state-of-art topics Car physics Car physics Fluid dynamics Fluid dynamics Rag-doll physics Rag-doll physics Physics Physics Rigid body kinematics Rigid body kinematics Newton’s Laws Newton’s Laws Forces Forces Momentum Momentum Energy Energy

3 3 Game Physics Applications in Games (1/2) In general In general Particle system for combat effects Particle system for combat effects First-person shooting First-person shooting Rag-doll system Rag-doll system Physical character motion simulation Physical character motion simulation Rigid-body dynamics Rigid-body dynamics Fracture mechanics Fracture mechanics Sports Sports Rag-doll system Rag-doll system Physical character motion simulation Physical character motion simulation Fluid dynamics Fluid dynamics Car racing Car racing Car physics Car physics Rigid-body dynamics Rigid-body dynamics Fracture mechanics Fracture mechanics

4 4 Game Physics Applications in Games (2/2) Fighting Fighting Flexible-body dynamics Flexible-body dynamics Cloth simulation Cloth simulation Rag-doll Rag-doll Etc Etc

5 5 Introduction to Particle System Point mass Point mass Mass center Mass center Newton’s Laws Newton’s Laws Forces Forces Acceleration Acceleration Velocity Velocity Position Position Easy to implement Easy to implement Good for game FXs Good for game FXs Attach a billboard on each particle Attach a billboard on each particle A basic feature of a game engine A basic feature of a game engine Fundamentals of Game Physics Fundamentals of Game Physics

6 6 Introduction to Rigid Body Dynamics Mass of a body Mass of a body Mass center Mass center Force Force Linear momentum Linear momentum Torque Torque Angular momentum Angular momentum Inertia tensor Inertia tensor Reference Reference www-2.cs.cmu.edu/afs/cs/user/baraff/www/pbm www-2.cs.cmu.edu/afs/cs/user/baraff/www/pbm

7 7 Introduction to Flexible Body Dynamics (1/2) Particle-spring model Particle-spring model F = k x F = k x Spring force Spring force Not a stress-strain model Not a stress-strain model Lack of Elasticity, Plasticity, & Viscous-Elasticity Lack of Elasticity, Plasticity, & Viscous-Elasticity Can be unstable Can be unstable

8 8 Introduction to Flexible Body Dynamics (2/2) Finite element method 有限元素法 –Solver for ODE/PDE –Boundary conditions –Energy equation –Stress-strain model –Very complicated computing process Conservation of energy

9 9 Advanced Topics in Game Physics Fracture mechanics ( 破壞力學模擬 ) Fracture mechanics ( 破壞力學模擬 ) Fluid dynamics ( 流體力學 ) Fluid dynamics ( 流體力學 ) Car dynamics ( 車輛動力學 ) Car dynamics ( 車輛動力學 ) Rag-doll physics ( 人體物理模擬 ) Rag-doll physics ( 人體物理模擬 )

10 10 Game Physics Middleware (Physics Engine) Freeware Freeware ODE ODE Open Dynamics Engine (ODE) Open Dynamics Engine (ODE) http://www.ode.org/ http://www.ode.org/ http://www.ode.org/ Bullet Bullet Commercial ones (now almost free) Commercial ones (now almost free) nVIDIA PhysX (Ageia PhysX) nVIDIA PhysX (Ageia PhysX) http://www.nvidia.com.tw/object/physx_new_tw.html http://www.nvidia.com.tw/object/physx_new_tw.html http://www.nvidia.com.tw/object/physx_new_tw.html Powered by CUDA Powered by CUDA Harvok (Intel) Harvok (Intel) http://www.havok.com/ http://www.havok.com/

11 11 Initial value problems Initial value problems Ordinary differential equation Ordinary differential equation Numerical solutions Numerical solutions Euler’s method Euler’s method The midpoint method The midpoint method Runge-Kutta method Runge-Kutta method Differential Equation Basics

12 12 An ODE An ODE x = f (x, t) wheref is a known function x is the state of the system, x is the x’s time derivative x & x are vectors x(t 0 ) = x 0, initial condition. Start here Follow the vectors … Initial Value Problems.. Vector field Vector field Solutions Solutions Symbolic solution Symbolic solution Numerical solution Numerical solution

13 13 A numerical solution A simplification from Tayler’s series Discrete time steps starting with initial value Simple but not accurate Bigger steps, bigger errors errors O(  t 2 ) errors Can be unstable Can be unstable Not even efficient Not even efficient x(t +  t) = x(t) +  t f(x, t) Euler’s Method

14 14 Runge-Kutta method of order 4 Runge-Kutta method of order 4 O(h 5 ) O(h 5 ) k 1 = h f(x 0, t 0 ) k 2 = h f(x 0 + k 1 /2, t 0 + h/2) k 3 = h f(x 0 + k 2 /2, t 0 + h/2) k 4 = h f(x 0 + k 3, t 0 + h) x(t 0 +h) = x 0 + 1/6 k 1 + 1/3 k 2 + 1/3 k 3 + 1/6 k 4 The Runge-Kutta Method

15 15 The tendency of an object at rest to remain at rest. The tendency of an object at rest to remain at rest. The mass is a measure of the inertia of the object. The mass is a measure of the inertia of the object. The force is the general mechanism for changing the mechanical state of an object. The force is the general mechanism for changing the mechanical state of an object. A force is a vector quantity. A force is a vector quantity. An external force is one where source is outside the system of interest. An external force is one where source is outside the system of interest. The standard unit of measurement for the magnitude of a force is a newton. The standard unit of measurement for the magnitude of a force is a newton. A newton is the required force magnitude to give 1kg mass 1m/sec 2 acceleration. A newton is the required force magnitude to give 1kg mass 1m/sec 2 acceleration.Inertia

16 16 First Law First Law In the absence of external forces, an object at rest will remain at rest. In the absence of external forces, an object at rest will remain at rest. If the object is in motion and no external forces acting on it, the object remains in motion with constant velocity. If the object is in motion and no external forces acting on it, the object remains in motion with constant velocity. Only forces can change an object’s motion. Only forces can change an object’s motion. Newton’s Laws (1/3)

17 17 Second Law Second Law For an object with constant mass over time, its acceleration a is proportional to the force F and inversely proportional to the mass m of the object : a = F/m. For an object with constant mass over time, its acceleration a is proportional to the force F and inversely proportional to the mass m of the object : a = F/m. If the mass changes over time, the more general statement of the law is If the mass changes over time, the more general statement of the law is Newton’s Laws (2/3) F = (mv) = ma + v ddtdt dmdmdmdm linear momentum An object’s path of motion is determined from applied forces. An object’s path of motion is determined from applied forces.

18 18 Third Law Third Law If the force exerted on one object, there is a force with equal magnitude but opposite direction on some other that interacts with it. If the force exerted on one object, there is a force with equal magnitude but opposite direction on some other that interacts with it. Action and reaction always occur between interacting objects. Action and reaction always occur between interacting objects. Newton’s Laws (3/3)

19 19 Gravitational forces Gravitational forces Spring forces Spring forces Friction and other dissipative forces Friction and other dissipative forcesForces

20 20 Given two point masses m and M that have gravitational interaction, they attract each other with forces of equal magnitude but opposite direction, as indicated by Newton’s third law. Given two point masses m and M that have gravitational interaction, they attract each other with forces of equal magnitude but opposite direction, as indicated by Newton’s third law. Gravitational Forces (1/2) F gravity = GmM r2r2r2r2 G = 6.67 x 10 -11 newton-meter 2 per kg 2 (universal gravitational constant)

21 21 Gravitational Forces (2/2) Assume the earth’s surface is flat and the direction of gravitation force is normal to the plane, the gravitational force exerted on the object by the earth is : Assume the earth’s surface is flat and the direction of gravitation force is normal to the plane, the gravitational force exerted on the object by the earth is : F = -mgU g = 9.81 meters per sec 2 U as unit-length upward direction U as unit-length upward direction U

22 22 Spring Forces Hooke’s Law Hooke’s Law F = -c  U c > 0, spring constant  U, displacement pullF  U > 0 pushF  U < 0

23 23 Dissipative Forces A dissipative force is one for which energy of the system decreases when motion takes place. A dissipative force is one for which energy of the system decreases when motion takes place. A simple model for a dissipative force : A simple model for a dissipative force : F = -c |v| n Two common cases : Two common cases : Friction Friction Viscosity Viscosity

24 24 Friction (1/2) A frictional force between two objects in contact opposes the sliding of one (moving) object over the surface of adjacent object (nonmoving). A frictional force between two objects in contact opposes the sliding of one (moving) object over the surface of adjacent object (nonmoving). The friction force is tangent to the contact surface and opposite in direction to the velocity of the moving object. The friction force is tangent to the contact surface and opposite in direction to the velocity of the moving object. The magnitude of the frictional force is assumed to be proportional to the magnitude of the normal force between surfaces. The magnitude of the frictional force is assumed to be proportional to the magnitude of the normal force between surfaces. F = - c k v / |v|, if v is not zero = 0, if v is zero = 0, if v is zero c k is referred to as the coefficient of kinetic friction The kinetic friction force is modeled as The kinetic friction force is modeled as c k = F friction / F normal

25 25 Friction (2/2) Static friction Static friction c s, coefficient of static friction c s, coefficient of static friction 1111  2 >  1 static case kinetic case c s = max(F friction )/ F normal

26 26Viscosity A typical occurrence of this type of force is when an object is dragged through a thick fluid. A typical occurrence of this type of force is when an object is dragged through a thick fluid. The force is modeled to have the direction opposite to that of the moving object. The force is modeled to have the direction opposite to that of the moving object. F = -F dissipative v/|v| = -(c|v|) v/|v| = -cv c > 0

27 27Torque Moment of force Moment of force F is the applied force. F is the applied force. r is the position of the applied force relative to the mass center. r is the position of the applied force relative to the mass center. The torque is the quantity : The torque is the quantity :  = r x F o r F The torque will generate a local rotation with respect to the mass center. The torque will generate a local rotation with respect to the mass center. Two forces of equal magnitude, opposite direction, but different lines of action are said to be a couple. Two forces of equal magnitude, opposite direction, but different lines of action are said to be a couple.

28 28Equilibrium Forces on an object are said to be concurrent if the lines of action all pass through a common point. Forces on an object are said to be concurrent if the lines of action all pass through a common point. Balanced forces mean the sum of the forces is zero. Balanced forces mean the sum of the forces is zero. concurrent not balanced concurrentbalanced not concurrent not balanced not concurrent balancedFF 2F

29 29Momentum Linear momentum Linear momentum Angular momentum Angular momentum

30 30 Linear Momentum The linear momentum is the product : The linear momentum is the product : p = m v m is the mass v is the velocity For a system of p particles of masses m i and velocity v i for i is in the range of (1, p), the linear momentum is For a system of p particles of masses m i and velocity v i for i is in the range of (1, p), the linear momentum is p = Σ m i v i p i = 1 If the object is a continuum of mass that occupies a region R, the linear momentum is If the object is a continuum of mass that occupies a region R, the linear momentum is p = ∫ v dm = ∫  v dR R R dm =  dR Infinite small measurement of mass

31 31 Angular Momentum Angular momentum can be treated as a measure of inertia to continue rotating about an axis. Angular momentum can be treated as a measure of inertia to continue rotating about an axis. L = r x p = r x m v Angular momentum for a set of particles, Angular momentum for a set of particles, L = Σ r i x m i v i p i = 1 If the object is a continuum of mass that occupies a region R, the angular momentum is If the object is a continuum of mass that occupies a region R, the angular momentum is L = ∫ r x v dm = ∫  r x v dR R R dm =  dR Infinite small measurement of mass

32 32 Moment of Inertia The measure of the rotational inertia of a body about an axis is the moment of inertia. The measure of the rotational inertia of a body about an axis is the moment of inertia. For a single particle, moment of inertia is For a single particle, moment of inertia is I = m r 2 m is the mass r is the distance to an axis But for a rigid body object, the inertia will be integrated as a function of mass and the geometry shape. But for a rigid body object, the inertia will be integrated as a function of mass and the geometry shape. We will discuss it in the section of “Rigid-body Dynamics” We will discuss it in the section of “Rigid-body Dynamics” Moment of inertia in one dimension Moment of inertia in one dimension Moment of inertia in two dimension Moment of inertia in two dimension Moment of inertia in three dimension Moment of inertia in three dimension Mass and Inertia tensor of a solid polyhedron Mass and Inertia tensor of a solid polyhedron

33 33 Particles are objects with Mass Position Velocity Respond to forces But no spatial extent (no size!) Point mass Based on Newton Laws f = ma x = f / m v = f / m, v = x Particle Dynamics....

34 34 Euler’s Method for Particle System v(t +  t) = v(t) +  t f’(v, t) x(t +  t) = x(t) +  t f(x, t) Discrete time steps starting with initial value Discrete time steps starting with initial value t = t 0, t 1, t 2, … t = t 0, t 1, t 2, … Fixed frame rate but adaptive sampling rate Fixed frame rate but adaptive sampling rate Simple but not accurate Simple but not accurate Bigger steps, bigger errors Bigger steps, bigger errors O(  t 2 ) errors O(  t 2 ) errors Can be unstable Can be unstable Not even efficient Not even efficient If the time step is very tiny If the time step is very tiny Calculate the velocity first Calculate the velocity first Then the position Then the position

35 35 Particle States Position Position Velocity Velocity Mass Mass Life Life Etc Etc Bounce rate Bounce rate Opacity Opacity Color Color In game application, we always put a billboard object with texture animation on a particle to simulate the geometry shape of the particle. In game application, we always put a billboard object with texture animation on a particle to simulate the geometry shape of the particle.

36 36 typedef struct { float m; /* mass */ float m; /* mass */ float *x; /* position */ float *x; /* position */ float *v; /* velocity */ float *v; /* velocity */ float *f; /* force accumulator */ float *f; /* force accumulator */ } *Particle; typedef struct { Particle *p /* array of pointers to particles */ Particle *p /* array of pointers to particles */ int n; /* number of particles */ int n; /* number of particles */ float t; /* simulation clock */ float t; /* simulation clock */ } *ParticleSystem; xvfm states xvfmxvfmxvfmxvfm xvfm … Particle n time Basic Particle System (1/5)

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

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

39 39 /* calculate derivative, place in dst */ void ParticleDerivative(ParticleSystem p, float *dst) { int i; int i; ClearForce(p); ClearForce(p); ComputeForce(p); ComputeForce(p); for (i = 0; i n; i++) { for (i = 0; i n; i++) { *(dst++) = p->p[i]->v[0]; *(dst++) = p->p[i]->v[0]; *(dst++) = p->p[i]->v[1]; *(dst++) = p->p[i]->v[1]; *(dst++) = p->p[i]->v[2]; *(dst++) = p->p[i]->v[2]; *(dst++) = p->p[i]->f[0]/p->p[i]->m; *(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[1]/p->p[i]->m; *(dst++) = p->p[i]->f[2]/p->p[i]->m; *(dst++) = p->p[i]->f[2]/p->p[i]->m; } } } } Basic Particle System (4/5)

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

41 41 The Rigid Body Non-deformable body Non-deformable body Within the body, the distance between two points are constant. Within the body, the distance between two points are constant. Rigid body motion Rigid body motion Kinematics Kinematics Dynamics Dynamics Degree of freedom Degree of freedom 3 rotations 3 rotations 3 translations 3 translations Mass of a body Mass of a body Mass center Mass center Force Force Linear momentum Linear momentum Torque Torque Angular momentum Angular momentum Inertia tensor Inertia tensor

42 42 Inertia Tensor (1/2)

43 43 Inertia Tensor (2/2) We always use bounding box to simplify the calculation of the inertia tensor. We always use bounding box to simplify the calculation of the inertia tensor. Rectangle block Rectangle block Cylinder Cylinder Sphere Sphere Pros Pros Simple Simple Cons Cons Inaccurate Inaccurate

44 44 Calculate Inertia Tensor for a Rectangle Block

45 45 Body Space & World Space p(t) = R(t)p 0 + x(t)

46 46 Linear Velocity We call x(t) and R(t) the position and orientation of the body at time t. We call x(t) and R(t) the position and orientation of the body at time t. * R(t) is the rotation matrix.

47 47 Angular Velocity (1/2)  (t) is the angular velocity of the body.  (t) is the angular velocity of the body.  (t) is not R(t)  (t) is not R(t)  (t) is a vector. But R(t) is a matrix  (t) is a vector. But R(t) is a matrix.

48 48 Angular Velocity (2/2)

49 49 Rigid Body Equation of Motion

50 50 Flexible Body Dynamics (1/2) Deformable body Deformable body Cloth Cloth Flag Flag Sand Sand Hair Hair Solvers Solvers Particle-spring model Particle-spring model Particles simulate the mass and the inertia. Particles simulate the mass and the inertia. Springs simulate the material. Springs simulate the material. Particle has translation only. Particle has translation only.

51 51 Flexible Body Dynamics (2/2) Spring Spring Hook’s Law Hook’s Law Rigid-body-spring Model Rigid-body-spring Model Use rigid body objects or balls to replace the particles. Use rigid body objects or balls to replace the particles. Rigid body has translation and rotation. Rigid body has translation and rotation. Translation springs Translation springs Rotation springs Rotation springs Finite element method Finite element method Stress Stress Strain Strain


Download ppt "1 Game Physics. 2 Introduction to Game Physics Traditional game physics Traditional game physics Particle system Particle system Rigid body dynamics Rigid."

Similar presentations


Ads by Google