Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Physics for Game: Part1 - Basics

1,679 views

Published on

Lecture Notes - Physics for Games

Published in: Education
  • Check the source ⇒ www.WritePaper.info ⇐ This site is really helped me out gave me relief from headaches. Good luck!
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • I can advise you this service - HelpWriting.net Bought essay here. No problem.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL eBOOK INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookeBOOK Crime, eeBOOK Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Physics for Game: Part1 - Basics

  1. 1. Part 1 - Physics Simulation Basics Physically-based Modeling Young-Min Kang Tongmyong University Basic Concepts 1. Mass, Force, and Time 2. Kinematics based Simulation 3. Dynamics and Simple Numerical Integration
  2. 2. Physically-based Modelling Mass, Force, and Time Young-Min Kang Tongmyong University
  3. 3. Mass ❖ Mass ❖ Resistance to being accelerated by force ❖ accumulated density (kg/m3) ❖ integration of density m = Z ⇢dV
  4. 4. Centre of Mass ❖ theory ❖ computation xc = R x0dm m yc = R y0dm m zc = R z0dm m xc = P ximi P mi yc = P yimi P mi zc = P zimi P mi cg = P (cgimi) m V dm at (x0,y0,z0)
  5. 5. Moment of Inertia ❖ angular mass ❖ rotation axis is important ❖ resistance to angular acceleration along the axis I = Z m r2 dm rotation axis r dm
  6. 6. Examples sphere spherical shell
  7. 7. Newton’s 2nd law of motion ❖ force = mass x acceleration ❖ total force ❖ sum of all the exerted forces ❖ acceleration is determined by the total force f = ma X fx = max X fy = may X fz = maz fnet fnet = X fi a = fnet m
  8. 8. Linear Momentum and its Derivative ❖ Linear Momentum: G ❖ mass x velocity ❖ G = mv ❖ Derivative of Linear Momentum with respect to time ❖ therefore, dG dt = dmv dt = m dv dt = ma dG dt = X f
  9. 9. Rotational Motion ❖ Torque: ❖ “force” in rotation ❖ angular momentum ❖ sum of moments of momentum of all particles ⌧ ⌧ = r ⇥ f f r ! ri vi H = X ri ⇥ mivi vi = ! ⇥ ri angular velocity H = X ri ⇥ mi(! ⇥ ri)
  10. 10. Angular Momentum = A. Mass x A. Velocity ❖ Linar Momentum: G ❖ G = mv ❖ Angular Momentum H = X ri ⇥ mi(! ⇥ ri) H = Z !r2 dm = ! Z r2 dm = !I = I! Inertia Tensor (Angular Mass) Angular Velocity
  11. 11. Derivative of Angular Momentum ❖ dG/dt = total force ❖ dH/dt = total torque dH dt = dI! dt = I d! dt = I↵ X ⌧ = I↵ ↵ = I 1 X ⌧
  12. 12. Tensor ❖ Tensor ❖ mathematical expression that has magnitude and direction ❖ its magnitude may not be unique depending on the direction ❖ typically used to represent properties of materials where these properties have different magnitudes in different directions. ❖ Isotropic vs. Anisotropic ❖ isotropic: properties are the same in all direction ❖ anisotropic: properties vary depending on direction ❖ Moment of Inertia ❖ inertia tensor (in 3D) ❖ nine components to fully describe it for any arbitrary rotation. (3x3 matrix) ❖ property of the body that varies with the axis of rotation.
  13. 13. Time ❖ Classic Physics ❖ Time is “constant” ❖ Modern Physics ❖ Time is “variable” ❖ “Speed of Light” is constant: c ❖ c = 299,792,458 m/s
  14. 14. Relativistic Time - Just for fun c = 2L/ t mirrors are travelling in a spaceship in the spaceship on earth if c is constant time should be DIFFERENT c = 2H/ te c = 2L/ ts We are not likely to use this relativistic time for this course…
  15. 15. Time Dilation ❖ Simple geometry ❖ time dilation ✓ c te 2 ◆2 = L2 + ✓ v te 2 ◆2 4L2 = c2 t2 e v2 t2 e 4L2 = (c2 v2 ) t2 e 4L2 c2 = (1 v2 c2 ) t2 e 2L c = r 1 v2 c2 te t = r 1 v2 c2 te te = 1 q 1 v2 c2 t H2 = L2 + ✓ v te 2 ◆2
  16. 16. Time and Animation ❖ Animation ❖ change over time ❖ Computer Animation ❖ computing the physical state in accordance with “time” ❖ We must measure the time ❖ Stop watch is needed ❖ Let’s make our own stop watch for animation
  17. 17. Stop Watch (header)
  18. 18. Stop Watch (implementation)
  19. 19. Visualise Your Stop Watch ❖ Implement your stop watch
  20. 20. Physically-based Modelling Kinematics Young-Min Kang Tongmyong University
  21. 21. Kinematics ❖ Kinematics vs. Dynamics ❖ kinematics ❖ force is not considered ❖ location, velocity, and acceleration are considered as ❖ functions of time ❖ x(t), v(t), a(t) ❖ dynamics ❖ force plays the most essential role ❖ compute f(t) ❖ a(t) = f(t)/m ❖ v(t+dt) += a(t)dt ❖ x(t+dt) += v(t+dt)dt f=ma
  22. 22. Statics, Kinetics, Kinematics and Dynamics ❖ Statics ❖ the study of equilibrium and its relation to forces ❖ Kinetics ❖ the study of motion and its relation to forces ❖ Kinematics ❖ the study of observed motions without regard for circumstances causing them ❖ Dynamics ❖ Statics + Kinetics classical mechanics
  23. 23. Particle and Rigid Body ❖ Particle ❖ very very tiny object with mass ❖ volume can be ignored ❖ rocket trajectory analysis ❖ the volume of the rocket can be ignored ❖ rocket can be regarded a particle ❖ Rigid body (= idealised solid body) ❖ object with mass and volume ❖ the shape does not change in any condition ❖ valid animation of rigid body = rotation and translation
  24. 24. Velocity ❖ velocity ❖ a vector ❖ speed: the magnitude of velocity ❖ velocity = (speed + direction) ❖ direction of velocity ❖ moving direction ❖ magnitude of velocity ❖ ratio of moving distance to time v = s t ratio of displacement to time interval
  25. 25. Instantaneous Velocity ❖ Reduce the time interval ❖ the more precise velocity at the moment ❖ if the time interval approaches to 0 ❖ instantaneous velocity v = lim t!0 s t = ds dt
  26. 26. displacement ❖ integration of velocity ❖ integration from t1 to t2 ❖ equivalent to the displacement ❖ If we know the velocity ❖ we can predict where the particle will be located in the future v = lim t!0 s t = ds dt vdt = ds Z vdt = Z ds Z t2 t1 vdt = Z s(t2) s(t1) ds Z t2 t1 vdt = s(t2) s(t1) = s
  27. 27. Acceleration ❖ Average acceleration ❖ ratio of velocity change to the time interval ❖ Instantaneous acceleration ❖ Integration of acceleration ❖ velocity change a = v/ t a = lim t!0 v/ t = dv/dt adt = dv Z t2 t1 adt = Z v(t2) v(t1) dv = v
  28. 28. Constant Acceleration ❖ Simple problem for Kinematics ❖ example of constant acceleration: gravity ❖ gravitational acceleration ❖ magnitude: 9.81 m/s2 ❖ direction: downwards (0,-1,0) ❖ We can easily “integrate the acceleration” to compute ❖ velocity change at every time ❖ this makes it possible to know the velocity at every time: v(t)
  29. 29. Gravitational Acceleration ❖ gravitational acceleration: g ❖ velocity change and the integration of acceleration ❖ If we know every thing at time t1 ❖ We can easily predict the velocity at time t2 ❖ if t1 =0 (t2 =t) Z v(t2) v(t1) dv = Z t2 t1 gdt v2 v1 = g(t2 t1) v2 = gt2 gt1 + v1 v2 = v1 + gt
  30. 30. Velocity as f(Displacement) ❖ Another differential equation ❖ Integration ❖ Relation between velocity and displacement v dv dt = ds dt a vdv = ads Z v2 v1 vdv = Z s2 s1 ads 1 2 v2 |v2 v1 = as|s2 s1 = gs|s2 s1 1 2 (v2 2 v1 2 ) = g(s2 s1) v2 2 = 2g(s2 s1) + v1 2
  31. 31. Location ❖ Velocity and displacement ❖ Integration ❖ Location at time t vdt = ds (v1 + gt)dt = ds Z t 0 (v1 + gt)dt = Z s2 s1 ds v1t + 1 2 gt2 = s2 s1 s2 = v1t + 1 2 gt2 + s1
  32. 32. Kinematic simulation #include "KinematicsSimulator.h" CKinematicSimulator::CKinematicSimulator() : CSimulator() {} void CKinematicSimulator::init() { initialLoc.set(0,1,0); initialVel.set(0,3,0); gravity.set(0.0, -9.8, 0.0); currentLoc = initialLoc; particle.setPosition(currentLoc[0], currentLoc[1], currentLoc[2]); particle.setRadius(0.1); } void CKinematicSimulator::doBeforeSimulation(double dt, double currentTime) { } void CKinematicSimulator::doSimulation(double dt, double currentTime) { currentLoc = initialLoc + currentTime*initialVel + (0.5 * currentTime * currentTime) * gravity ; particle.setPosition(currentLoc[0], currentLoc[1], currentLoc[2]); particle.drawWithGL(); } void CKinematicSimulator::doAfterSimulation(double dt, double currentTime) { } https://github.com/dknife/201501Lec_GamePhysics/tree/master/GPcode01_03_KinematicParticleExplosion
  33. 33. Particle explosion with Kinematics ❖ KinematicSimulator.cpp #include "KinematicsSimulator.h" CKinematicSimulator::CKinematicSimulator() : CSimulator() {} void CKinematicSimulator::init() { for(int i=0;i<NUMPARTS;i++)particle[i].randomInit(); } void CKinematicSimulator::doBeforeSimulation(double dt, double currentTime) { } void CKinematicSimulator::doSimulation(double dt, double currentTime) { for(int i=0;i<NUMPARTS;i++){ particle[i].simulate(dt, currentTime); particle[i].drawWithGL(POINT_DRAW); } } void CKinematicSimulator::doAfterSimulation(double dt, double currentTime) { }
  34. 34. Particle explosion with Kinematics ❖ Particle.cpp void CParticle::randomInit() { double speed = rand()%10000 / 10000.0 + 1.0; double theta = 2.0*3.141592 * (rand()%10000 / 10000.0); double phi = 2.0*3.141592 * (rand()%10000 / 10000.0); double vx,vy,vz; // spherical coord to cartesian coord vy = speed*cos(phi)+2.0; vx = speed*cos(theta)*sin(phi); vz = speed*sin(theta)*sin(phi); initialLoc.set(0,1,0); initialVel.set(vx, vy, vz); gravity.set(0.0, -9.8, 0.0); radius = 0.01; currentLoc = initialLoc; } void CParticle::simulate(double dt, double et) { currentLoc = initialLoc + et*initialVel + (0.5 * et * et) * gravity ; setPosition(currentLoc[0], currentLoc[1], currentLoc[2]); }
  35. 35. Result
  36. 36. Physically-based Modelling Dynamics and Numerical Integration Young-Min Kang Tongmyong University
  37. 37. Dynamics ❖ Dynamics ❖ force-based understanding of motions ❖ Important formula ❖ f = ma ❖ Rigid body ⌧ = I ˙!
  38. 38. Integration of Equations of Motion ❖ Newton’s 2nd law of motion ❖ f = ma ❖ In other words, ❖ dv = ? f = m dv dt fdt m = dv if force is constant f m (t2 t1) = v2 v1 f m t = v Z t2 t1 fdt m = Z v2 v1 dv
  39. 39. Initial Condition Problem ❖ Initial conditions ❖ x(t), v(t) ❖ location and velocity at current time t ❖ Problem ❖ predict x(t+dt) and v(t+dt) ❖ predict the location and velocity after a small time step dt ❖ Repeat with Initial conditions = x(t+dt), v(t+dt)
  40. 40. Velocity update ❖ Initial condition of velocity ❖ v1 = v(t) ❖ Velocity to be found ❖ v2 = v(t+dt) ❖ Velocity at the next frame ❖ or f m (t2 t1) = v2 v1 f m t = v v(t + t) = v(t) + f(t) m t v(t + t) = v(t) + a(t) t
  41. 41. Position Update ❖ Velocity and Position ❖ Numerical Integration ❖ If force (or acceleration) is known at time t ❖ We can “approximately” predict velocity and location at time t+dt v = ds/dt vdt = ds v(t + t) t = s
  42. 42. Realtime Simulation ❖ compute force: f ❖ compute acceleration: a = f/m ❖ predict the velocity after time step ❖ Euler integration ❖ predict the location after time step ❖ Euler integration v(t + t) = a t x(t + t) = v(t + t) t
  43. 43. Simulation Code - main.cpp void keyboardFunction(unsigned char key, int x, int y) { if (key == 27) exit(0); switch (key) { case 's': if(!myWatch.bRunning()) { Simulator->start(); myWatch.start(); } else { myWatch.stop(); Simulator->stop(); } break; case 'p': myWatch.pause(); Simulator->pause(); break; case 'r': myWatch.resume(); Simulator->resume(); default: break; } } void displayFunction(void) { … // check DT (in microsecond) from StopWatch and store it to "deltaTime" (in seconds) deltaTime = myWatch.checkAndComputeDT() / 1000000.0; currentTime = myWatch.getTotalElapsedTime() / 1000000.0; Simulator->actions(deltaTime, currentTime); glutSwapBuffers(); }
  44. 44. Simulation Code - Simulator.cpp #include "Simulator.h" #include <stdlib.h> #include <stdio.h> // Constructor CSimulator::CSimulator(): bRunning(false) { } CSimulator::~CSimulator() { } void CSimulator::actions(double dt, double currentTime) { if(bRunning) { doBeforeSimulation(dt, currentTime); doSimulation(dt, currentTime); doAfterSimulation(dt, currentTime); } visualize(); } // Control Event Handlers void CSimulator::start() { this->init(); bRunning = true; } void CSimulator::stop() { bRunning = false; this->clean(); } void CSimulator::pause() {} void CSimulator::resume() {}
  45. 45. Simulation Code - DynamicSimulator.cpp #include "DynamicSimulator.h" CDynamicSimulator::CDynamicSimulator() : CSimulator() {} void CDynamicSimulator::init() { for(int i=0;i<NUMPARTS;i++)particle[i].randomInit(); } void CDynamicSimulator::clean() {} void CDynamicSimulator::doBeforeSimulation(double dt, double currentTime) {} void CDynamicSimulator::doSimulation(double dt, double currentTime) { for(int i=0;i<NUMPARTS;i++) particle[i].simulate(dt, currentTime); } void CDynamicSimulator::doAfterSimulation(double dt, double currentTime) {} void CDynamicSimulator::visualize(void) { for(int i=0;i<NUMPARTS;i++) { particle[i].drawWithGL(POINT_DRAW); } }
  46. 46. Simulation Code - Particle.cpp void CParticle::simulate(double dt, double et) { // Update velocity: Euler Integration of acceleration vel = vel + dt*gravity; // Update position: Euler Integration of velocity loc = loc + dt*vel; // collision handling if(loc[1]<0) { loc.set(loc[0], -0.9*loc[1], loc[2]); if(vel[1]<0) vel.set(vel[0], -0.9*vel[1], vel[2]); } setPosition(loc[0], loc[1], loc[2]); }
  47. 47. Result
  48. 48. Forces ❖ Forces ❖ cause motion ❖ very important in dynamics ❖ Various force models
  49. 49. Concepts ❖ Force field : example - gravitational force ❖ Friction: a contact force that resists motion ❖ Fluid dynamic drag: resistance to objects moving in fluid ❖ Pressure: force per area ❖ Buoyancy: force pushing objects “upwards” when immersed in a fluid ❖ Springs and dampers: elastically ties objects ❖ Force applies torque to an object, and make it “rotate.”
  50. 50. Force field ❖ Force field ❖ a vector field indicating the force exerted by on object on another ❖ Very good example ❖ gravitational force field ❖ electromagnetic force field
  51. 51. Gravitational force field ❖ universal gravitational force ❖ G: gravitation constance ❖ r: distance between masses ❖ m_{1,2}: mass of each objects ❖ gravity on Earth ❖ mass of Earth: ❖ radius of Earth: ❖ gravitational acceleration |fu| = Gm1m2/r2 6.673 ⇥ 10 11 (N · m2 )/kg2 5.98 ⇥ 1024 kg 6.38 ⇥ 106 m Gmearth r2 ' ( 6.673 ⇥ 5.98 6.382 ) ⇥ 10m/s2 ' 9.8034m/s2
  52. 52. friction ❖ resistance force due to the contacting surfaces ❖ contact force ❖ normal force: N is important ❖ two friction ❖ static friction: maximum friction ❖ kinetic friction |fmax| = µsN |fk| = µkN
  53. 53. Coefficients of friction ❖ Well known surfaces
  54. 54. Fluid dynamic drag ❖ similar to friction ❖ friction is also important component of drag ❖ but, it’s not the only one ❖ viscous drag for “slow-moving” objects (laminar) ❖ f = -C v ❖ for “fast-moving” objects (turbulence) ❖ f = -C v2
  55. 55. Pressure ❖ Pressure is not force ❖ pressure = force per unit area ❖ F = PA (force = pressure x area ) ❖ P = F/A ❖ Pressure is important in simulating ❖ boats, hovercrafts,…
  56. 56. Buoyancy ❖ Different pressure in fluid ❖ Horizontal net force = 0 ❖ Vertical net force = bottom force - top force ❖ F = PA ❖ Pressures: function(density, gravity) ❖ on top surface ❖ on bottom surface Pt = ⇢ght Pb = ⇢ghb
  57. 57. Buoyancy ❖ forces ❖ difference ft = PtAt = ⇢ghts2 fb = PbAb = ⇢ghbs2 fb ft = ⇢ghbs2 ⇢ghts2 = ⇢g(hb ht)s2 = ⇢gs3 = ⇢gV (V : volume)
  58. 58. Spring force ❖ Hooke’s law ❖ force needed to extend or compress a spring by a distance x is proportional to that distance ❖ f = -k x ❖ k: spring constant ❖ rest length of spring: ❖ current length of spring: ❖ force magnitude: ❖ force direction: obj1 and obj2 are linked and located at x1 and x2. ❖ and |f| = ks(L r) x1 x2 |x1 x2| x1 x2 |x1 x2|
  59. 59. Damper ❖ Springs do not oscillate forever ❖ energy dissipation ❖ simple model ❖ damping force fd = kd(v1 v2)
  60. 60. Spring and Damper X1 X2 L L f1 = (ks(L r) + kd(v1 v2) · L L ) L L f2 = f1
  61. 61. Force and Torque ❖ Force ❖ causes linear acceleration ❖ Torque ❖ causes angular acceleration ❖ Torque: ❖ a vector ❖ magnitude ❖ how quickly the angular velocity is changed ❖ |r x f | ❖ direction ❖ rotational axis = ( r x f ) / |r x f| ⌧ ⌧ = r ⇥ f f r

×