View
221
Download
2
Category
Tags:
Preview:
Citation preview
242-515 AGD: 12. Physics 11
• Objectiveo show how physics is used in games
programming
Animation and Games
Development242-515, Semester 1, 2014-2015
12. Basic Physics
242-515 AGD: 12. Physics 22
1. Why Physics?2. Point-based Physics3. Rigid Body Physics4. Other Types of Force5. The World of the Car6. JBullet Features7. A Game Physics Textbook
Overview
242-515 AGD: 12. Physics 33
• Physics can make game worlds appear more natural / realistic
• But...• Often games are not realistic
o e.g. cars travelling at 200 mph, double jumps of Mario
• Physics engines are computationally expensiveo they may slow down the game too much
1. Why Physics?
242-515 AGD: 12. Physics 44
• Commercialo Havok (Havok.com)o Renderware (renderware.com)o NovodeX (novodex.com)
• Freeo Open Dynamic Engine (ODE) (ode.org)o PhysXo Bullet (Java version used in jME)o Box2D (2D)
Engines
242-515 AGD: 12. Physics 55
• Newtonian (this one for games)o Newton’s space and time are absolute
• Classicalo Einstein's space-time can be “changed” by matter
• Quantumo Deterministic causality questioned and multiple localities
in a single instance
Types of Physics
242-515 AGD: 12. Physics 66
• Timeo A measured duration
• Speedo The distance travelled given some time limit
• Directiono An indication of travel
• Velocityo The rate of change of position over time (has speed and direction)
• Accelerationo The rate of change of velocity
• Forceo Causes objects to accelerate (has direction as well as magnitude)
• Masso The weight of an object? (No! weight depends on gravitational pull)o The quantity of matter
Remember this stuff…..
242-515 AGD: 12. Physics 77
• Every body (object) continues in its state of rest, or uniform motion in a straight line, unless there is an external force acting on it.
• Often called "The Law of Inertia"
Newton’s First Law of Motion
242-515 AGD: 12. Physics 88
• The rate of change of momentum of a body is proportional to the force acting on it, and takes place in the direction of that force.
• Simplified – An object’s change in velocity is proportional to an applied force.
• An object's mass m, its acceleration a, and the applied force F canbe represented by the formula:
F = ma
Newton’s Second Law of Motion
242-515 AGD: 12. Physics 99
• For every action there is an equal and opposite reaction.
• If two objects bump into each other they will react by moving apart.
Newton’s 3rd Law of Motion
242-515 AGD: 12. Physics 1010
As Cartoons
242-515 AGD: 12. Physics 1111
• Two main types of Newtonian physics used in games: point-based, rigid body based
• Point-based physicso used in particle systems, bullet motion…o a point's mass is located inside the pointo a point does not rotate: it has no rotational orientation
Game Physics
242-515 AGD: 12. Physics 1212
• Solve Newtonian equations to get the position of a point at time t:
o Force applied to the point, F(t), causes acceleration
o Acceleration, a(t), causes a change in the point's velocity
o Velocity, V(t) causes a change in the point's position
2. Point-based Physics
Calculation
Examples• Calculate a new position based on a constant velocity:
xt = x0 + (vx * t)
yt = y0 + (vy * t)
zt = z0 + (vz * t)
• Velocity is a Vector, (vx, vy, vz), or (vx, vy) in 2D
• Example, point at (1, 5), velocity of (4, -3)
242-515 AGD: 12. Physics 1414
Standard Equations• v = u + a t• s = t (u + v)• v2 = u2 + 2 a s• s = u t + a t2
• u = initial velocity; v = final velocity• a = acceleration• t = time (seconds)• s = distance (meters)
Velocity
• Velocities are vectors:
Vtotal = √(Vx2 + Vy
2 + Vz2) for 3D
games
Vtotal = √(Vx2 + Vy
2) for 2D games
Acceleration
• Calculate a new velocity (vt) based on a constant acceleration:
vt = dx/dt = v0 + (a * dt)
• Each of these calculations are in one dimension
– you must perform similar calculations on y & z axes
Forces
• Forces are vectors
Ftotal = √(Fx2 + Fy
2 + Fz2) for 3D
games
Ftotal = √(Fx2 + Fy
2) for 2D games
242-515 AGD: 12. Physics 1818
• Weight of the projectile (a point), W = mgo g: constant acceleration due to gravity
(9.81m/s2)
• Projectile equations of motion:
Example: 3D Projectile Motion
initinit ttt gVV )(
2
2
1)( initinitinitinit ttttt gVpp
p() is the position function
Target Practice
F = w e ig ht = m gTarget
Projectile LaunchPosition, pinit
242-515 AGD: 12. Physics 2020
• The shape (body) has a mass that occupies volume.
• We assume that the body never changes shape
• The orientation of the body can change over time.
3. Rigid Body Physics
242-515 AGD: 12. Physics 2121
• Good news: the maths of rigid body translation is the same as for points, since we can treat the center of mass of the body as a point.
• This means we can reuse the maths:o F = m ao v = ∫a dto x = ∫v dto momentum is conserved
Rigid Body Translation
242-515 AGD: 12. Physics 2222
center of mass= point
242-515 AGD: 12. Physics 2323
• A rigid body has an orientation (rotated position in space)
• Rotation calculations are complicatedo one reason is that the order of rotation
operations is important:
o x-axis rotation then y-axis rotation ≠y-axis rotation then x-axis rotation
• Rotation is not commutative
Rotation
242-515 AGD: 12. Physics 2424
• When a body can rotate the Newtonian motion equations must be extended.o new equations are needed for rotational (angular)
mass, velocity, acceleration, force, momemtum, etc.
242-515 AGD: 12. Physics 2525
• The angular velocity ω describes the speed of rotation and the orientation of the axis about which the rotation occurs.
Angular Velocity, ω
242-515 AGD: 12. Physics 2626
242-515 AGD: 12. Physics 2727
• Δθ = change in angular displacement• Δt = time
Angular Velocity Again
242-515 AGD: 12. Physics 2828
• Δω = change in angular velocity• Δt = time
Angular Acceleration, α
242-515 AGD: 12. Physics 2929
• What happens when you push on a rotating body?• There are two things to consider: translation and
rotation.
• For translation, we can use F=ma, because the body's center of mass can be treated like a point.
• But how does the force affect the body's orientation?
Applying Force
242-515 AGD: 12. Physics 3030
• Torque is a measure of how much a force acting on an object causes that object to rotate.
• T = r x F = r F sin(θ)• Torque is the cross product (x) between the
distance vector from the pivot point (O) to the point where force vector F is applied
• θ is the angle between r and F
Torque, T
242-515 AGD: 12. Physics 3131
• The same amount of torque can be applied with less force if the distance from the pivot (fulcrum) is increased.
Uses for Torque
242-515 AGD: 12. Physics 3232
• Moment of inertia is the mass property of a rigid body that determines the torque needed for a desired angular acceleration about an axis of rotation.
• Moment of inertia depends on the shape of the body and may be different around different axes of rotation.
Moment of Inertia I
shape effect
242-515 AGD: 12. Physics 3333
axes effect
easy(torque is small)
hard(torque is large)
242-515 AGD: 12. Physics 3434
• Another definition: moment of Inertia is an object’s resistance to rotating around an axis
242-515 AGD: 12. Physics 3535
• Also called translational momentum: the product of the mass and velocity of an object
• p = m v• Linear momentum is a conserved quantity:
o if a closed system is not affected by external forces, then its total linear momentum cannot change
o useful for calculating velocity change after collisions
Linear Momentum, p
242-515 AGD: 12. Physics 3636
• Angular momentum is the rotational version of linear momentum. o e.g. a tire rolling down a hill has angular momentum
• Defined as the cross product of the moment of inertia I and the angular velocity ω.
• L = l x ω
Angular momentum, L
242-515 AGD: 12. Physics 3737
• Angular momentum is a conserved quantity: o if a closed system is not affected by external torque,
then its total angular momentum cannot changeo useful for calculating rotational change when moments
of inertia change
L = I1 x ω1L = I2 x ω2
242-515 AGD: 12. Physics 3838
Linear vs. AngularLinear Concept
Angular Version
velocity v angular velocity ω
acceleration a angular acceleration α
F = m a torque T = r x F' = I α
mass m moment of inertia I
momentump = m v
angular momentum L = I x ω
242-515 AGD: 12. Physics 3939
• The maths for rigid bodies is simpler if we use a local coordinate system for each bodyo e.g. place the origin at the centre of mass of the body
• But, we also need to transform any global forces into each body's local coordinate system
• We also have to transform any local motion back into global coordinates.
Changing Coordinate Systems
242-515 AGD: 12. Physics 4040
• (Virtual) Springs• Damping• Friction• Aerodynamic Drag• …
4. Other Types of Force
242-515 AGD: 12. Physics 4141
• Even if you don't see very many actual springs in a game, there are likely to be many invisible virtual springs at work.
• Virtual springs are useful for implementing constraints between objects:o preventing objects overlappingo cloth renderingo character animation
(Virtual) Springs
Linear Springs
dllkF restspring )(
Damping
ddVVcF epepdamping ))(( 12
Damping describes physical conditions such as viscosity, roughness, etc.
Static FrictionNot Sliding On the
BrinkSliding
242-515 AGD: 12. Physics 4545
• Once static friction is overcome and the object is moving, friction continues to push against the relative motion of the two surfaces.o called kinetic friction
Kinetic Friction
242-515 AGD: 12. Physics 4646
• Cars exist in an environment that exerts forces.
5. The World of the Car
Resistance
• A car driving down a road experiences two (main) types of resistance.o Aerodynamic drag, rolling resistance
rollingairtotal RRR
• Once resistance has been calculated, it is possible to calculate the amount of power a car needs to move.
242-515 AGD: 12. Physics 4848
dpair CSVR 2)2/1(
Aerodynamic DragMass density of air
Speed of car
Projected frontal area of car normal to direction of V
Drag coefficient:0.29 – 0.4: sports cars;0.6 – 0.9: trucks
Rolling resistance• Tires rolling on a road experience rolling
resistance. This is not friction and has a lot to do with wheel deformation. Simplifying, we can say:
rrolling CR Coefficient of rolling resistance:Cars ≈ 0.015;trucks ≈ 0.006 – 0.01
Weight of car (assuming four identical wheels)
242-515 AGD: 12. Physics 5050
• Power is the measure of the amount of work done by a force, or torque, over time.
• Mechanical work done by a force is equal to the force * distance an object moves under the action of that force.
• Power is usually expressed in units of horsepowero 1 horsepower = 550 ft-lbs/s
Power
Horsepower• Horsepower needed to overcome total
resistance at a given speed (we are working in feet and lbs):
550/)( VRP total
horsepowerTotal resistance corresponding to a car’s speed (V)
Engine output The previous equation relates the power
delivered to the wheels to reach speed V. The actual power required will be higher due to
mechanical loss. Power is delivered to a wheel in the form of
torque.
rTF ww /
Force delivered by a wheel to the road to push the car along
Torque on thewheel
Radius of the wheel
242-515 AGD: 12. Physics 5353
• Stopping distance depends on the braking system and how hard the driver breaks. o the harder the brakes are applied the shorter the
stopping distance
• If a car skids then the stopping distance depends on the frictional force between the tyres and the road.
• If travelling uphill the stopping distance will be shorter.o gravity plays a role
• If travelling downhill the stopping distance will be greater.
Stopping
242-515 AGD: 12. Physics 5454
)]sincos(2/[2 gvd s
Calculating Skidding Distance
Acceleration due to gravity Coefficient of
friction between wheels and the road.
Usually around 0.4
Initial speed of the car
Angle of the road
242-515 AGD: 12. Physics 5555
• In a real driving game a lot more parameters play a role.o e.g. suspension, variable engine power, road
surface
• Usually it is easier to use a physics engine, but this still requires an understanding of the forces that you want to model.
More Calculations Required?
242-515 AGD: 12. Physics 5656
6. JBullet Features• Rigid Bodies
o Simple shapes, complex geometries
• Joints and Spring Constraints• Dynamics Modeling
o Integrating forces and torques
• Collision Detectiono Physical interactions between objects
• Ray Tracingo Range finders and optical flow
• Cloth, Soft (deformable) Bodies
56
what we've beentalking about inthis part
the next part
242-515 AGD: 12. Physics 5757
• Physics for Game DevelopersDavid M Bourg, Bryan BywalecO'Reilly, April 2013, 2nd ed.
7. A Game Physics Textbook
Recommended