From a460c753e709c5a775c3086428d8dee9736cfce5 Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 3 Mar 2004 21:37:41 +0000 Subject: [PATCH] Work around a limitation of gc_calc_course_dist(). When the start and end points are too close together, this routine can return a course of "nan" but the distance is valid. Someday someone who understands the math should rewrite the gc_calc_course_dist() routine so it is more robust, but for now it's easiest to simply check for a nan result and code around the limitation. --- simgear/scene/sky/cloud.cxx | 23 +++++++++++++++++++---- simgear/scene/sky/cloud.hxx | 3 +-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/simgear/scene/sky/cloud.cxx b/simgear/scene/sky/cloud.cxx index 5461bfd4..bcea578c 100644 --- a/simgear/scene/sky/cloud.cxx +++ b/simgear/scene/sky/cloud.cxx @@ -21,6 +21,8 @@ #include #include STL_IOSTREAM +#include + #include #include @@ -363,6 +365,17 @@ bool SGCloudLayer::reposition( sgVec3 p, sgVec3 up, double lon, double lat, calc_gc_course_dist( dest, start, &course, &dist ); // cout << "course = " << course << ", dist = " << dist << endl; + // if start and dest are too close together, + // calc_gc_course_dist() can return a course of "nan". If + // this happens, lets just use the last known good course. + // This is a hack, and it would probably be better to make + // calc_gc_course_dist() more robust. + if ( isnan(course) ) { + course = last_course; + } else { + last_course = course; + } + // calculate cloud movement due to external forces double ax = 0.0, ay = 0.0, bx = 0.0, by = 0.0; @@ -396,9 +409,10 @@ bool SGCloudLayer::reposition( sgVec3 p, sgVec3 up, double lon, double lat, if ( base[0] > -10.0 && base[0] < 10.0 ) { base[0] -= (int)base[0]; } else { - base[0] = 0.0; SG_LOG(SG_ASTRO, SG_DEBUG, - "Error: base = " << base[0] << "," << base[1]); + "Error: base = " << base[0] << "," << base[1] << + " course = " << course << " dist = " << dist ); + base[0] = 0.0; } base[1] += yoff; @@ -409,9 +423,10 @@ bool SGCloudLayer::reposition( sgVec3 p, sgVec3 up, double lon, double lat, if ( base[1] > -10.0 && base[1] < 10.0 ) { base[1] -= (int)base[1]; } else { - base[1] = 0.0; SG_LOG(SG_ASTRO, SG_ALERT, - "Error: base = " << base[0] << "," << base[1]); + "Error: base = " << base[0] << "," << base[1] << + " course = " << course << " dist = " << dist ); + base[1] = 0.0; } // cout << "base = " << base[0] << "," << base[1] << endl; diff --git a/simgear/scene/sky/cloud.hxx b/simgear/scene/sky/cloud.hxx index 4fa8c795..76a3cb88 100644 --- a/simgear/scene/sky/cloud.hxx +++ b/simgear/scene/sky/cloud.hxx @@ -194,8 +194,7 @@ private: // from winds, and to simulate the clouds being tied to ground // position, not view position // double xoff, yoff; - double last_lon, last_lat; - + double last_lon, last_lat, last_course; }; -- 2.39.5