Hi!
I have changed Tiago's patch somewhat, it now iterates over all the
ground layers.
Debug output looks like this for KSFO:
Found tower ground layer at 124.323ft, material <unnamed>
Found tower ground layer at 114.536ft, material <unnamed>
Found tower ground layer at 82.3405ft, material <unnamed>
Found tower ground layer at 42.9577ft, material <unnamed>
Found tower ground layer at 5.36808ft, material pc_tiedown
Setting tower viewpoint altitude 112.368
I was hoping to find a layer like "Grass" or "Ground" somewhere, but
no. So for now, the code picks the lowest layer, which might not work
if the tower is sunk into the ground as other objects frequently are.
I tested LHBP and that worked (even had grass material).
Also attached is a patch to apt.dat (gunzip, patch, gzip) that updates
KSFO and KNID tower viewpoint based on the scenery.
I am not sure we can trust the tower position in apt.dat, since the
elevation values are frequently obvious nonsense (500 for KSFO and 0
for KNID).
Please comment.
--
Csaba/Jester
Index: src/Main/fg_init.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Main/fg_init.cxx,v
retrieving revision 1.192
diff -u -r1.192 fg_init.cxx
--- src/Main/fg_init.cxx 14 Dec 2007 22:51:57 -0000 1.192
+++ src/Main/fg_init.cxx 6 Jan 2008 02:32:25 -0000
@@ -62,6 +62,7 @@
#include <simgear/misc/sg_path.hxx>
#include <simgear/misc/interpolator.hxx>
#include <simgear/scene/material/matlib.hxx>
+#include <simgear/scene/material/mat.hxx>
#include <simgear/timing/sg_time.hxx>
#include <simgear/timing/lowleveltime.h>
@@ -728,6 +729,40 @@
}
#endif
+// calculates a more precise tower altitude (separated because it needs the
scenery loaded)
+static void fgUpdateTowerAltitude()
+{
+ FGScenery* scenery = globals->get_scenery();
+ if (!scenery) return;
+
+ double ground = 999999;
+ double level = 999999;
+ const SGMaterial* material;
+ double lat = fgGetDouble("/sim/tower/latitude-deg");
+ double lon = fgGetDouble("/sim/tower/longitude-deg");
+
+ while (scenery->get_elevation_m(lat, lon, level - 1, level, &material)) {
+ ground = level;
+ string name("<unnamed>");
+ if (material) {
+ const vector<string> names = material->get_names();
+ if (names.size()) name = names[0];
+ }
+ SG_LOG(SG_GENERAL, SG_DEBUG,
+ "Found tower ground layer at " << ground * SG_METER_TO_FEET <<
+ "ft, material " << name);
+ }
+
+ if (ground < 999999) {
+ double alt = fgGetDouble("/sim/tower/height-ft") + ground *
SG_METER_TO_FEET;
+ SG_LOG(SG_GENERAL, SG_DEBUG, "Setting tower viewpoint altitude " <<
alt);
+ fgSetDouble("/sim/tower/altitude-ft", alt);
+ } else {
+ SG_LOG(SG_GENERAL, SG_DEBUG,
+ "Unable to obtain exact elevation for tower, using airport
elevation");
+ }
+}
+
// Set current tower position lon/lat given an airport id
static bool fgSetTowerPosFromAirportID( const string& id) {
@@ -736,7 +771,9 @@
SGGeod tower = a->getTowerLocation();
fgSetDouble("/sim/tower/longitude-deg", tower.getLongitudeDeg());
fgSetDouble("/sim/tower/latitude-deg", tower.getLatitudeDeg());
- fgSetDouble("/sim/tower/altitude-ft", tower.getElevationFt());
+ fgSetDouble("/sim/tower/height-ft", tower.getElevationFt());
+ fgSetDouble("/sim/tower/altitude-ft", tower.getElevationFt() +
a->getElevation());
+ fgUpdateTowerAltitude();
return true;
} else {
return false;
@@ -751,9 +788,17 @@
}
};
+struct FGTowerElevationListener : SGPropertyChangeListener {
+ void valueChanged(SGPropertyNode* node) {
+ if(node->getBoolValue()==true) fgUpdateTowerAltitude();
+ }
+};
+
void fgInitTowerLocationListener() {
fgGetNode("/sim/tower/airport-id", true)
->addChangeListener( new FGTowerLocationListener(), true );
+ fgGetNode("/sim/sceneryloaded", true)
+ ->addChangeListener( new FGTowerElevationListener(), true );
}
// Set current_options lon/lat given an airport id and heading (degrees)
--- apt.dat.orig 2008-01-06 03:29:17.000000000 +0100
+++ apt.dat 2008-01-06 02:47:38.000000000 +0100
@@ -61019,7 +61019,7 @@
10 35.688678 -117.682786 xxx 154.34 114 0.0 0.0 69 111111 1 0 0 0.35 0
10 35.688197 -117.681999 xxx 154.34 404 0.0 0.0 371 111111 2 0 0 0.35 0
10 35.687744 -117.681336 xxx 154.34 869 0.0 0.0 377 111111 2 0 0 0.35 0
-14 35.689195 -117.684753 0 0 Tower Viewpoint
+14 35.689129 -117.684691 70 0 Tower Viewpoint
18 35.688454 -117.684445 1 BCN
19 35.676731 -117.708411 1 Windsock
19 35.694412 -117.685953 1 Windsock
@@ -282103,7 +282103,7 @@
10 37.610031 -122.388839 xxx 43.13 700 0.0 0.0 450 161161 2 0 0 0.25 0
10 37.638502 -122.387909 xxx 338.00 1400 0.0 0.0 1200 161161 2 0 0 0.25 0
10 37.637101 -122.393257 xxx 338.00 1400 0.0 0.0 1200 161161 2 0 0 0.25 0
-14 37.616630 -122.385478 500 0 Tower Viewpoint
+14 37.617131 -122.384108 107 0 Tower Viewpoint
15 37.621522 -122.386777 10.00 CAL RAMP AREA
18 37.629493 -122.386207 1 Rotating Beacon
19 37.611354 -122.379740 1 Windsock
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel