ptr[2] = vec[2];
}
-// base_fdm_state is the internal state that is updated in integer
-// multiples of "dt". This leads to "jitter" with respect to the real
-// world time, so we introduce cur_fdm_state which is extrapolated by
-// the difference between sim time and real world time
-
FGInterface *cur_fdm_state = 0;
-FGInterface base_fdm_state;
// Constructor
FGInterface::FGInterface()
- : remainder(0)
{
_setup();
}
FGInterface::FGInterface( double dt )
- : remainder(0)
{
_setup();
}
// unbind(); // FIXME: should be called explicitly
}
-
int
FGInterface::_calc_multiloop (double dt)
{
+ // Since some time the simulation time increments we get here are
+ // already a multiple of the basic update freqency.
+ // So, there is no need to do our own multiloop rounding with all bad
+ // roundoff problems when we already have nearly accurate values.
+ // Only the speedup thing must be still handled here
int hz = fgGetInt("/sim/model-hz");
+ int multiloop = SGMiscd::roundToInt(dt*hz);
int speedup = fgGetInt("/sim/speed-up");
-
- dt += remainder;
- remainder = 0;
- double ml = dt * hz;
- // Avoid roundoff problems by adding the roundoff itself.
- // ... ok, two times the roundoff to have enough room.
- int multiloop = int(floor(ml * (1.0 + 2.0*DBL_EPSILON)));
- remainder = (ml - multiloop) / hz;
-
- // If we artificially inflate ml above by a tiny amount to get the
- // closest integer, then subtract the integer from the original
- // slightly smaller value, we can get a negative remainder.
- // Logically this should never happen, and we definitely don't want
- // to carry a negative remainder over to the next iteration, so
- // never let the remainder go below zero.
- //
- // Note: this fixes a problem where we run 1, 3, 1, 3, 1, 3... loops
- // of the FDM when in fact we want to run 2, 2, 2, 2, 2...
- if ( remainder < 0 ) { remainder = 0; }
-
- return (multiloop * speedup);
+ return multiloop * speedup;
}
runway_altitude=0;
climb_rate=0;
altitude_agl=0;
+ track=0;
}
void
set_inited( true );
-// stamp();
-// set_remainder( 0 );
+ ground_cache.set_cache_time_offset(globals->get_sim_time_sec());
// Set initial position
SG_LOG( SG_FLIGHT, SG_INFO, "...initializing position..." );
{
bound = true;
- // Time management (read-only)
-// fgTie("/fdm/time/delta_t", this,
-// &FGInterface::get_delta_t); // read-only
-// fgTie("/fdm/time/elapsed", this,
-// &FGInterface::get_elapsed); // read-only
-// fgTie("/fdm/time/remainder", this,
-// &FGInterface::get_remainder); // read-only
-// fgTie("/fdm/time/multi_loop", this,
-// &FGInterface::get_multi_loop); // read-only
-
// Aircraft position
fgTie("/position/latitude-deg", this,
&FGInterface::get_Latitude_deg,
&FGInterface::get_Psi_deg,
&FGInterface::set_Psi_deg);
fgSetArchivable("/orientation/heading-deg");
+ fgTie("/orientation/track-deg", this,
+ &FGInterface::get_Track);
// Body-axis "euler rates" (rotation speed, but in a funny
// representation).
{
bound = false;
- // fgUntie("/fdm/time/delta_t");
- // fgUntie("/fdm/time/elapsed");
- // fgUntie("/fdm/time/remainder");
- // fgUntie("/fdm/time/multi_loop");
fgUntie("/position/latitude-deg");
fgUntie("/position/longitude-deg");
fgUntie("/position/altitude-ft");
fgUntie("/orientation/roll-deg");
fgUntie("/orientation/pitch-deg");
fgUntie("/orientation/heading-deg");
+ fgUntie("/orientation/track-deg");
fgUntie("/orientation/roll-rate-degps");
fgUntie("/orientation/pitch-rate-degps");
fgUntie("/orientation/yaw-rate-degps");
void FGInterface::_updatePositionM(const SGVec3d& cartPos)
{
+ TrackComputer tracker( track, geodetic_position_v );
cartesian_position_v = cartPos;
geodetic_position_v = SGGeod::fromCart(cartesian_position_v);
geocentric_position_v = SGGeoc::fromCart(cartesian_position_v);
void FGInterface::_updatePosition(const SGGeod& geod)
{
+ TrackComputer tracker( track, geodetic_position_v );
geodetic_position_v = geod;
cartesian_position_v = SGVec3d::fromGeod(geodetic_position_v);
geocentric_position_v = SGGeoc::fromCart(cartesian_position_v);
void FGInterface::_updatePosition(const SGGeoc& geoc)
{
+ TrackComputer tracker( track, geodetic_position_v );
geocentric_position_v = geoc;
cartesian_position_v = SGVec3d::fromGeoc(geocentric_position_v);
geodetic_position_v = SGGeod::fromCart(cartesian_position_v);
}
bool
-FGInterface::prepare_ground_cache_m(double ref_time, const double pt[3],
- double rad)
+FGInterface::prepare_ground_cache_m(double startSimTime, double endSimTime,
+ const double pt[3], double rad)
{
- return ground_cache.prepare_ground_cache(ref_time, SGVec3d(pt), rad);
+ return ground_cache.prepare_ground_cache(startSimTime, endSimTime,
+ SGVec3d(pt), rad);
}
-bool FGInterface::prepare_ground_cache_ft(double ref_time, const double pt[3],
- double rad)
+bool
+FGInterface::prepare_ground_cache_ft(double startSimTime, double endSimTime,
+ const double pt[3], double rad)
{
// Convert units and do the real work.
SGVec3d pt_ft = SG_FEET_TO_METER*SGVec3d(pt);
- return ground_cache.prepare_ground_cache(ref_time, pt_ft, rad*SG_FEET_TO_METER);
+ return ground_cache.prepare_ground_cache(startSimTime, endSimTime,
+ pt_ft, rad*SG_FEET_TO_METER);
}
bool
SGVec3d pt_m = SGVec3d(pt) - max_altoff*ground_cache.get_down();
SGVec3d _contact, _normal, _linearVel, _angularVel;
material = 0;
- if (!ground_cache.get_agl(t, pt_m, _contact, _normal, _linearVel,
- _angularVel, id, material))
- return false;
+ bool ret = ground_cache.get_agl(t, pt_m, _contact, _normal, _linearVel,
+ _angularVel, id, material);
// correct the linear velocity, since the line intersector delivers
// values for the start point and the get_agl function should
// traditionally deliver for the contact point
assign(normal, _normal);
assign(linearVel, _linearVel);
assign(angularVel, _angularVel);
- return true;
+ return ret;
}
bool
pt_m *= SG_FEET_TO_METER;
SGVec3d _contact, _normal, _linearVel, _angularVel;
material = 0;
- if (!ground_cache.get_agl(t, pt_m, _contact, _normal, _linearVel,
- _angularVel, id, material))
- return false;
+ bool ret = ground_cache.get_agl(t, pt_m, _contact, _normal, _linearVel,
+ _angularVel, id, material);
// correct the linear velocity, since the line intersector delivers
// values for the start point and the get_agl function should
// traditionally deliver for the contact point
assign( normal, _normal );
assign( linearVel, SG_METER_TO_FEET*_linearVel );
assign( angularVel, _angularVel );
- return true;
+ return ret;
}
bool
// FIXME: how to handle t - ref_time differences ???
SGVec3d cpos;
- double ref_time, radius;
+ double ref_time = 0, radius;
// Prepare the ground cache for that position.
if (!is_valid_m(&ref_time, cpos.data(), &radius)) {
- bool ok = prepare_ground_cache_m(ref_time, pos.data(), 10);
+ double startTime = ref_time;
+ double endTime = startTime + 1;
+ bool ok = prepare_ground_cache_m(startTime, endTime, pos.data(), 10);
/// This is most likely the case when the given altitude is
/// too low, try with a new altitude of 10000m, that should be
/// sufficient to find a ground level below everywhere on our planet
if (!ok) {
- pos = SGVec3d::fromGeod(SGGeod::fromRadM(geod.getLongitudeRad(), geod.getLatitudeRad(), 10000));
+ pos = SGVec3d::fromGeod(SGGeod::fromGeodM(geod, 10000));
/// If there is still no ground, return sea level radius
- if (!prepare_ground_cache_m(ref_time, pos.data(), 10))
+ if (!prepare_ground_cache_m(startTime, endTime, pos.data(), 10))
return 0;
}
} else if (radius*radius <= distSqr(pos, cpos)) {
+ double startTime = ref_time;
+ double endTime = startTime + 1;
+
/// We reuse the old radius value, but only if it is at least 10 Meters ..
if (!(10 < radius)) // Well this strange compare is nan safe
radius = 10;
- bool ok = prepare_ground_cache_m(ref_time, pos.data(), radius);
+ bool ok = prepare_ground_cache_m(startTime, endTime, pos.data(), radius);
/// This is most likely the case when the given altitude is
/// too low, try with a new altitude of 10000m, that should be
/// sufficient to find a ground level below everywhere on our planet
if (!ok) {
- pos = SGVec3d::fromGeod(SGGeod::fromRadM(geod.getLongitudeRad(), geod.getLatitudeRad(), 10000));
+ pos = SGVec3d::fromGeod(SGGeod::fromGeodM(geod, 10000));
/// If there is still no ground, return sea level radius
- if (!prepare_ground_cache_m(ref_time, pos.data(), radius))
+ if (!prepare_ground_cache_m(startTime, endTime, pos.data(), radius))
return 0;
}
}