Game Development Reference
In-Depth Information
Y Components
For the y components, you need to follow the same procedure shown earlier for the x
components, but with the appropriate y-direction forces. Here's what it looks like:
-F dy - F gy = m (dv y /dt)
-C d v y - m g = m (dv y /dt)
(0 to t) dt = -m ∫ (vy1 to vy2) 1/(C d v y + m g) dv y
v y2 = (1/C d ) e (-C d /m)t (C d v y1 + m g) - (m g)/C d
Now that you have an equation for velocity, you can proceed to get an equation for
displacement as before:
v y2 dt = ds y
[(1/C d ) e (-C d /m)t (C d v y1 + m g) - (m g)/C d ] dt = ds y
(0 to t) [(1/C d ) e (-C d /m)t (C d v y1 + m g) - (m g)/C d ] dt = ∫ (sy1 to
sy2) ds y
s y2 = s y1 + [-(v y1 + (m g)/C d ) (m/C d ) e (-C d /m)t - t (m g)/C d ] +
[(m/C d )(v y1 + (m g)/C d )]
OK, that's two down and only one more to go.
Z Components
With the z component, you get a break. You'll notice that the equations of motion for
the x and z components look almost the same with the exception of the x and z subscripts
and the sine versus cosine terms. Taking advantage of this fact, you can simply copy the
x component equations and replace the x subscript with a z and the cosine terms with
sines and be done with it:
v z2 = (1/C d ) [e (-C d /m)t (c w v w sin γ + C d v z1 ) - (c w v w sin γ)]
s z2 = [(m/C d ) e (-C d /m)t (-(C w v w sin γ) / C d - v z1 ) - ((C w v w sin
γ)/C d ) t] -
[(m/C d ) (-(C w v w sin γ)/C d - v z1 )] + s z1
Cannon Revised
Now that you have some new equations for the projectile's displacement in each coor‐
dinate direction, you can go to the cannon example source code and replace the old
displacement calculation formulas with the new ones. Make the changes in the DoSimu
lation function as follows: