Dana Vrajitoru
B583/C490 Game Programming and Design
Physics in 3D Games
Kinematics
- Newton's laws of motion
- Trajectory, speed, and acceleration
- Constant versus non constant acceleration
- Gravitational motion and ballistics
- Angular speed and acceleration
- Satellites, orbits
- Slope and movement decomposition
Newton's 3 Laws of Motion
- I. Every object in a state of uniform motion tends to remain in
that state of motion unless an external force is applied to it.
- II. The relationship between an object's mass m, its acceleration
a, and the applied force F is F = ma. Acceleration and force are
vectors; in this law the direction of the force vector is the same as
the direction of the acceleration vector.
- III. For every action there is an equal and opposite reaction.
Trajectory, Speed,
- Problem. Describe the movement of a point-wise object through space.
- Trajectory - a curve in space s(x(t), y(t), z(t)) where the
parameter t is the time.
- Speed (velocity) - the distance covered in a unit of time v =
distance/time (m/s)
- Momentary speed - limit of the speed when the lapse of time goes
to 0.
- v(t) = s'(t)
... and Acceleration
- Acceleration - the variation of the speed in a unit of time.
- a(t) = v'(t) = s''(t)
- Our goal: compute the trajectory of an object based on the following data:
- origin of the movement
- initial speed as a vector
- some description of the acceleration (gravitation, input from the
user for car race or flight simulation, etc.)
- other physical constraints (the form of the road, degrees of
freedom for articulated objects, etc.)
Types of Motion Calculation
- Newtonian motion where Dt is the lapse of time between the two
points on the trajectory:
- s(t + Dt) = s(t) + v(t) Dt + 0.5 a(t) (Dt)2
v(t + Dt) = v(t) + a(t) Dt
- Lagrangian motion:
- Lagrangian: L = T - U, where T is the kinetic energy and U is the
potential energy.
- T = 0.5 m v2.
- U = m * g * height
- Equation of motion:
Constant Acceleration
- We can simply plot the position and speed as known functions of time.
- Considering that the time starts from 0, that the object's initial
position is s0, and that its initial speed is
v0, then we have
- s(t) = s0 + v0 t + a t2/2
- v(t) = v0 + a t
Non Constant Acceleration
- We can describe the acceleration as a function.
- This gives us a system of partial differential equations - PDEs
with given initial values for t = 0 (initial value problem - IVP).
- Usually it is solved by approximating s and v on small intervals
of time.
- s'(t) = v(t), s(0) = s0
- v'(t) = a(v, s, t, ...), v(0) = v0
- If a is just a function of t, then we can compute
- v(t) = Integral0t a(u) du,
s(t) = Integral0t v(u) du
Example - Drag Force
- The drag force (and acceleration) is proportional to the square of
the speed.
- a = -kv2 = dv/dt
- -k dt = dv/v2
- By integrating between 0 and t on the left, and between
v0 = v(0) and v1 = v(t) on the right, we obtain
- -k t = -1/v1 + 1/v0
- v(t) = v0/(1 +v 0 k t)
- s(t) = s0 + v0 t /(1 + v0 k t) -
kv2t2/2
Newton's Law of Gravitation
- Every object in the universe attracts every other object with a
force directed along the line of centers of the two objects that is
proportional to the product of their masses and inversely proportional
to square of the distance between them.
- If the two objects have masses m1 and m2 and
are at a distance of r, then the attraction force between them is
F = G m1 m2 / r2
- where G = 6.67 x 10-11 N m2 /kg2
is the universal gravitational constant
Earth's Gravitation
- To define the gravitational acceleration at the surface of the
Earth, we need
- M = 5.98 x 1024 kg, the mass of the Earth, and
R = 6.38 x 106 m, the radius of the Earth
- we can define the gravitational acceleration g on the surface of
the Earth as (approximate sea level)
g = G M / R = 9.8 m / s2
- Then for every object of mass m, the gravitational force is F = g
m.
Ballistic Trajectories
- Problem. The object is projected from the ground at a given angle
a and with given initial speed v0.
- We decompose v00 in
v0x = |v0| sin a
v0y = |v0| cos a
- If we consider again that the time starts from 0, we must compute
the position and the speed at time t.
- We will consider the initial position to be 0.
- The horizontal acceleration is equal to 0, so the horizontal speed
is constant.
- The vertical acceleration is equal to -g.
- x(t) = vx t,
vx(t) = v0x
y(t) = v0y t - 0.5 g t2,
vy(t) = v0y - g t
- The trajectory is parabolic.
Total Distance and Time
- How long will it take for the object to fall down again? Where
will it land? How high will it go?
- If we impose vy(t1) = 0, we have
- v0y = g t1, t1 = v0y/g
- The total time will be twice that much T = 2 v0y/g
- The horizontal distance covered in this time is
- X = v0x 2 v0y/g
- The vertical distance covered in t1 is
- H = v0y v0y/g - 0.5
v0y2/g = 0.5 v0y2/g
Angular Speed
- When an object moves on a circular trajectory, the angular speed
is the rate at which the angle changes.
- w = d a / dt
- The rate at which the angular velocity changes is the angular
acceleration.
- W = d w / dt
- If r is the radius of the circle and v is the speed that is
tangent to the circle, then we can compute
- w = v/r, W = a/r.
Satellite
- When an object arrives in the neighborhood of a second massive
object with a speed perpendicular to the line between their centers,
the first object may become a satellite.
- When an object rotates, the centrifugal force is pushing it
towards the exterior of the circle.
- The gravitation must equal this force for the object to be a
satellite. It will play the role of the centripetal force.
- Fc = m w2 r = m v2 /r
- m v2 / r = G m M / r 2
- v = sqrt(G M / r)
Gravitational Orbits
- The orbits of the planets generally are ellipses.
- The orbits of some of the planets (e.g., Venus) are ellipses of
such small eccentricity that they are essentially circles, and we can
put artificial satellites into orbit around the Earth with circular
orbits if we choose.
- Some comets have parabolic orbits; this means that they pass the
Sun once and then leave the Solar System, never to return. Other
comets have elliptical orbits and thus orbit the Sun with specific
periods.
- The gravitational interaction between two passing stars generally
results in hyperbolic trajectories for the two stars.
Slope
- Consider an object moving down a path with a given slope.
- Decompose the gravitational acceleration into a component that is
tangent to the surface, and another that is normal to the surface.
- The tangent component will influence the speed in the tangent
direction.
- The normal component may slow it down because of the friction
(otherwise it has no effect on the movement).
- gt = g sin a
- gp = g cos a
Friction Force
- A force occurring when two solid objects are in contact, applied
against their relative movement.
- The frictional resistance is proportional to the force which
presses the surfaces together as well as the roughness of the
surfaces. If we denote by N this force (like the gravitation), then
the frictional resistance force may then be written:
- Ff = mu N
- where mu is a constant depending on the two surfaces.
Friction and Slope
- For a terrain that is not flat, the normal force to the surface
based on gravitation is
- Gn = m gp = m g cos alpha
- where m is the mass of the object.
- The friction force will then be
- FF = mu Gn = m mu g cos(alpha)
- The resulting acceleration
- af = g mu cos(alpha) a
- This will have a sign that is opposite to the direction of movement.
Change of Slope
- Passing from a surface of a given slope to a surface of different
slope.
- If v is the speed at the passage point, we decompose it in a speed
that is tangent to the new surface (vt), and a speed that
is normal to the new surface (vp).
- The normal component is lost for the movement and it is
transformed in impact momentum.
- The computations on the new surface start with the tangent speed.
Application - Slide
- By a smooth change in the slope, transform the almost vertical
speed in an almost horizontal speed at the end of the trajectory. This
way we avoid damaging the object by collision with the ground (slide,
roller coaster).
Terrain-Dependant Slope
Solving the equation: the projection of the direction vector on the
terrain plane must be orthogonal to the plane normal. The scalar
product of the 2 vectors must be 0.