+ if (fgGetBool("/sim/presets/running")) {
+ Propulsion->InitRunning(-1);
+ for (unsigned int i = 0; i < Propulsion->GetNumEngines(); i++) {
+ FGPiston* eng = (FGPiston*)Propulsion->GetEngine(i);
+ globals->get_controls()->set_magnetos(i, eng->GetMagnetos());
+ globals->get_controls()->set_mixture(i, FCS->GetMixtureCmd(i));
+ }
+ }
+
+ if ( needTrim ) {
+ FGLocation cart(fgic->GetLongitudeRadIC(), fgic->GetLatitudeRadIC(),
+ get_Sea_level_radius() + fgic->GetAltitudeASLFtIC());
+ double cart_pos[3], contact[3], d[3], vel[3], agl;
+ update_ground_cache(cart, cart_pos, 0.01);
+
+ get_agl_ft(fdmex->GetSimTime(), cart_pos, SG_METER_TO_FEET*2, contact,
+ d, vel, d, &agl);
+ double terrain_alt = sqrt(contact[0]*contact[0] + contact[1]*contact[1]
+ + contact[2]*contact[2]) - get_Sea_level_radius();
+
+ SG_LOG(SG_FLIGHT, SG_INFO, "Ready to trim, terrain elevation is: "
+ << terrain_alt * SG_METER_TO_FEET );
+
+ if (fgGetBool("/sim/presets/onground")) {
+ FGColumnVector3 gndVelNED = cart.GetTec2l()
+ * FGColumnVector3(vel[0], vel[1], vel[2]);
+ fgic->SetVNorthFpsIC(gndVelNED(1));
+ fgic->SetVEastFpsIC(gndVelNED(2));
+ fgic->SetVDownFpsIC(gndVelNED(3));
+ }
+ fgic->SetTerrainElevationFtIC( terrain_alt );
+ do_trim();
+ needTrim = false;
+ }
+