1
0
Fork 0

Introduce a radar/in-range boolean property, end check this to see whether the CPU intensive radar calculations need to be done. If not, skip them.

This commit is contained in:
ehofman 2004-06-10 19:14:19 +00:00
parent 6c8f7fab01
commit 4fe886f008
3 changed files with 61 additions and 41 deletions

View file

@ -237,10 +237,25 @@ void FGAIAircraft::Run(double dt) {
//###########################//
// do calculations for radar //
//###########################//
double radar_range_ft2 = fgGetDouble("/instrumentation/radar/range");
radar_range_ft2 *= SG_NM_TO_METER * SG_METER_TO_FEET;
radar_range_ft2 *= radar_range_ft2;
// copy values from the AIManager
double user_latitude = manager->get_user_latitude();
double user_longitude = manager->get_user_longitude();
double lat_range = fabs(pos.lat() - user_latitude) * ft_per_deg_lat;
double lon_range = fabs(pos.lon() - user_longitude) * ft_per_deg_lon;
double range_ft2 = lat_range*lat_range + lon_range*lon_range;
//
// Test whether the target is within radar range.
//
in_range = (range_ft2 <= radar_range_ft2);
if ( in_range )
{
props->setBoolValue("radar/in-range", true);
// copy values from the AIManager
double user_altitude = manager->get_user_altitude();
double user_heading = manager->get_user_heading();
double user_pitch = manager->get_user_pitch();
@ -248,9 +263,7 @@ void FGAIAircraft::Run(double dt) {
double user_speed = manager->get_user_speed();
// calculate range to target in feet and nautical miles
double lat_range = fabs(pos.lat() - user_latitude) * ft_per_deg_lat;
double lon_range = fabs(pos.lon() - user_longitude) * ft_per_deg_lon;
double range_ft = sqrt( lat_range*lat_range + lon_range*lon_range );
double range_ft = sqrt( range_ft2 );
range = range_ft / 6076.11549;
// calculate bearing to target
@ -302,12 +315,15 @@ void FGAIAircraft::Run(double dt) {
rotation = hdg - user_heading;
if (rotation < 0.0) rotation += 360.0;
} else
props->setBoolValue("radar/in-range", false);
//************************************//
// Tanker code //
//************************************//
if ( isTanker) {
if ( (range_ft < 250.0) &&
if ( (range_ft2 < 250.0 * 250.0) &&
(y_shift > 0.0) &&
(elevation > 0.0) ) {
refuel_node->setBoolValue(true);

View file

@ -48,6 +48,7 @@ FGAIBase::FGAIBase() {
tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs = pitch = 0.0;
bearing = elevation = range = rdot = 0.0;
x_shift = y_shift = rotation = 0.0;
in_range = false;
invisible = true;
no_roll = true;
model_path = "";
@ -139,6 +140,7 @@ void FGAIBase::bind() {
props->tie("orientation/roll-deg", SGRawValuePointer<double>(&roll));
props->tie("orientation/true-heading-deg", SGRawValuePointer<double>(&hdg));
props->tie("radar/in-range", SGRawValuePointer<bool>(&in_range));
props->tie("radar/bearing-deg", SGRawValuePointer<double>(&bearing));
props->tie("radar/elevation-deg", SGRawValuePointer<double>(&elevation));
props->tie("radar/range-nm", SGRawValuePointer<double>(&range));
@ -167,6 +169,7 @@ void FGAIBase::unbind() {
props->untie("orientation/roll-deg");
props->untie("orientation/true-heading-deg");
props->untie("radar/in-range");
props->untie("radar/bearing-deg");
props->untie("radar/elevation-deg");
props->untie("radar/range-nm");

View file

@ -86,6 +86,7 @@ protected:
double tgt_vs;
// these describe radar information for the user
bool in_range; // true if in range of the radar, otherwise false
double bearing; // true bearing from user to this model
double elevation; // elevation in degrees from user to this model
double range; // range from user to this model, nm