Game Development Reference
In-Depth Information
double ComputeBetaDotDot(void)
{
double C, D, G;
C = -(I + R * S * cos(beta));
D = I;
G = Qbeta - alpha_dot * alpha_dot * R * S * sin(beta) −
S * (g * sin(theta + beta) - a * cos(theta + beta));
return (G - C * alpha_dotdot) / D;
}
The solution to Equations 1 and 2 follows the Runge-Kutta scheme we showed you in
Chapter 7 . Four intermediate steps are taken for each time step. The time step size is
controlled by dt , which we've set to 0.0025s. If you simply used Euler's method, you'd
have to reduce this step size quite a bit to obtain a stable solution. We implemented the
solution in the main function of our console example. The code is as follows:
int _tmain(int argc, _TCHAR* argv[])
{
double a, at;
double b, bt;
int i;
FILE* fp;
double phi;
double Vc2;
double ak1, ak2, ak3, ak4;
double bk1, bk2, bk3, bk4;
FILE* fdebug;
fp = fopen("results.txt", "w");
fdebug = fopen("debug.txt", "w");
for(i = 0; i<200; i++)
{
time += dt;
if(time>=0.1)
{
Qbeta = 0;
}
// save results of previous time step
a = alpha;
b = beta;
at = alpha_dot;
bt = beta_dot;
// integrate alpha'' and beta''
Search Nedrilad ::




Custom Search