Game Development Reference
In-Depth Information
DEGREES(alpha), DEGREES(beta), DEGREES(phi), Vc);
fprintf(fdebug, "%f, %f, %f, %f, %f, %f, %f\n", time, DEGREES(alpha),
alpha_dot, alpha_dotdot, DEGREES(beta), beta_dot, beta_dotdot);
return 0;
Local variables a , at , b , and bt are used to temporarily store the previous time step's
results for α and β and their first derivatives. i is a counter variable. fp is a file pointer
that we'll use to write results out to a text file. phi is used to store the sum of θ + β. And
Vc2 is the square of the club head velocity calculated according to Jorgensen's equation.
The variables ak1 through ak4 , and bk1 through bk4 , are used to store intermediate
results of the Runge-Kutta integration scheme. fdebug is a file pointer to a file we used
for writing debugging information.
After the output and debug files are opened, the function enters a loop to perform the
integration over 200 time steps. You can change the number of time steps as you see fit
for your application. Keep in mind that the swing event, from start to striking the ball,
takes place over a very short period of time—only fractions of a second long.
Upon entering the loop, you'll see some code that checks how much time has elapsed;
if that time is greater than 0.1s, the wrist torque, Qbeta , is set to 0. This is a crude model
of how the wrist torque that's initially applied is released, allowing the club to swing past
the arm. Depending on the swing you're modeling, this torque could actually reverse
direction, forcing the club past the arm even more. Dr. Jorgensen's book explains all this
in detail, even giving experimental results.
Next, results of the previous time step are saved in the variables a , b , at , and bt . The
first time step simply stores the initial values. Now, the integration starts for the first
step, k1 (see Chapter 7 ). Each of these steps involves computing ¨ and ¨ using the
functions ComputeAlphaDotDot and ComputeBetaDotDot . The k1 results are then cal‐
culated and used to compute intermediate results for the first time derivatives of α and
β. All four intermediate steps are carried out in a similar manner.
Finally, the current time step's results for alpha_dot and beta_dot , along with alpha
and beta , are computed. Also, the square of the club head velocity, Vc2 , is computed
using Jorgensen's equation shown earlier; and the club head velocity, Vc , results from
the square root of Vc2 .
Search Nedrilad ::

Custom Search