Game Development Reference
In-Depth Information
C * g * (t*t)/m);
V2.j = V1.j + (t/m)*C*V2.i - g*t;
// Calc. S2:
s2.i = s1.i + V1.i * t + (1.0f/2.0f) * (C/m * V2.j) * (t*t);
s2.j = s1.j + V1.j * t + (1.0f/2.0f) * ( ((C*V2.i) - m*g)/m ) * (t*t);
// Check for collision with ground (x-z plane)
if(s2.j <= 0)
return 2;
// Cut off the simulation if it's taking too long
// This is so the program does not get stuck in the while loop
if(time>60)
return 3;
return 0;
}
The heart of this simulation is the lines that calculate V2 and s2 , the instantaneous
velocity and position of the projectile, respectively. The equations of motion here come
from the 2D kinetic equations of motion including gravity, as discussed in Chapter 4 ,
combined with the following formula (shown earlier) for estimating the Magnus lift on
a spinning sphere:
F L = (2 π 2 ρ v r 4 ω) / (2 r)
You can see the effect of spin on the projectile's trajectory by providing the sample
program with different values for spin in revolutions per minute. The program converts
this to radians per second and stores this value in the variable omega . A positive spin
value indicates bottom spin such that the bottom of the sphere is spinning away from
you, while a negative spin indicates topspin, where the top of the ball spins away from
you. Bottom spin generates a positive lift force that will tend to extend the range of the
projectile, while topspin generates negative lift that will force the projectile toward the
ground, shortening its range. (Note that this example assumes that the spin axis is hor‐
izontal and perpendicular to the plane of the screen.) Figure 6-13 illustrates this be‐
havior.
Search Nedrilad ::




Custom Search