1
0
Fork 0

Helpers to access view position.

Avoid direct use of FGViewer in various places, by providing property-based accessors to the current view position.
This commit is contained in:
James Turner 2012-09-25 10:06:30 +01:00
parent 4456f42e67
commit 649d579124
8 changed files with 33 additions and 19 deletions

View file

@ -24,7 +24,6 @@
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
#include <Viewer/viewer.hxx>
#include <Scenery/scenery.hxx>
#include <Scenery/tilemgr.hxx>
#include <Airports/dynamics.hxx>
@ -172,8 +171,7 @@ void FGAIAircraft::setPerformance(const std::string& acclass) {
void FGAIAircraft::checkVisibility()
{
double visibility_meters = fgGetDouble("/environment/visibility-m");
FGViewer* vw = globals->get_current_view();
invisible = (SGGeodesy::distanceM(vw->getPosition(), pos) > visibility_meters);
invisible = (SGGeodesy::distanceM(globals->get_view_position(), pos) > visibility_meters);
}
@ -516,10 +514,8 @@ void FGAIAircraft::getGroundElev(double dt) {
// Only do the proper hitlist stuff if we are within visible range of the viewer.
if (!invisible) {
double visibility_meters = fgGetDouble("/environment/visibility-m");
FGViewer* vw = globals->get_current_view();
if (SGGeodesy::distanceM(vw->getPosition(), pos) > visibility_meters) {
double visibility_meters = fgGetDouble("/environment/visibility-m");
if (SGGeodesy::distanceM(globals->get_view_position(), pos) > visibility_meters) {
return;
}
@ -839,7 +835,7 @@ bool FGAIAircraft::aiTrafficVisible()
SGVec3d cartPos = SGVec3d::fromGeod(pos);
const double d2 = (TRAFFICTOAIDISTTODIE * SG_NM_TO_METER) *
(TRAFFICTOAIDISTTODIE * SG_NM_TO_METER);
return (distSqr(cartPos, globals->get_aircraft_positon_cart()) < d2);
return (distSqr(cartPos, globals->get_aircraft_position_cart()) < d2);
}

View file

@ -30,7 +30,6 @@
#include <math.h>
#include <Main/util.hxx>
#include <Viewer/viewer.hxx>
#include "AICarrier.hxx"
@ -166,7 +165,7 @@ void FGAICarrier::update(double dt) {
SGVec3d cartPos = SGVec3d::fromGeod(pos);
// The position of the eyepoint - at least near that ...
SGVec3d eyePos(globals->get_current_view()->get_view_pos());
SGVec3d eyePos(globals->get_view_position_cart());
// Add the position offset of the AIModel to gain the earth
// centered position
SGVec3d eyeWrtCarrier = eyePos - cartPos;

View file

@ -164,7 +164,7 @@ ADF::update (double delta_time_sec)
}
// Calculate the bearing to the transmitter
SGVec3d location = globals->get_aircraft_positon_cart();
SGVec3d location = globals->get_aircraft_position_cart();
double distance_nm = dist(_transmitter_cart, location) * SG_METER_TO_NM;
double range_nm = adjust_range(_transmitter_pos.getElevationFt(),

View file

@ -148,6 +148,10 @@ FGGlobals::FGGlobals() :
positionLat = props->getNode("position/latitude-deg", true);
positionAlt = props->getNode("position/altitude-ft", true);
viewLon = props->getNode("sim/current-view/viewer-lon-deg", true);
viewLat = props->getNode("sim/current-view/viewer-lat-deg", true);
viewAlt = props->getNode("sim/current-view/viewer-elev-ft", true);
orientPitch = props->getNode("orientation/pitch-deg", true);
orientHeading = props->getNode("orientation/heading-deg", true);
orientRoll = props->getNode("orientation/roll-deg", true);
@ -380,7 +384,7 @@ FGGlobals::get_aircraft_position() const
}
SGVec3d
FGGlobals::get_aircraft_positon_cart() const
FGGlobals::get_aircraft_position_cart() const
{
return SGVec3d::fromGeod(get_aircraft_position());
}
@ -392,6 +396,19 @@ void FGGlobals::get_aircraft_orientation(double& heading, double& pitch, double&
roll = orientRoll->getDoubleValue();
}
SGGeod
FGGlobals::get_view_position() const
{
return SGGeod::fromDegFt(viewLon->getDoubleValue(),
viewLat->getDoubleValue(),
viewAlt->getDoubleValue());
}
SGVec3d
FGGlobals::get_view_position_cart() const
{
return SGVec3d::fromGeod(get_view_position());
}
// Save the current state as the initial state.
void

View file

@ -148,6 +148,7 @@ private:
bool haveUserSettings;
SGPropertyNode_ptr positionLon, positionLat, positionAlt;
SGPropertyNode_ptr viewLon, viewLat, viewAlt;
SGPropertyNode_ptr orientHeading, orientPitch, orientRoll;
public:
@ -249,10 +250,14 @@ public:
SGGeod get_aircraft_position() const;
SGVec3d get_aircraft_positon_cart() const;
SGVec3d get_aircraft_position_cart() const;
void get_aircraft_orientation(double& heading, double& pitch, double& roll);
SGGeod get_view_position() const;
SGVec3d get_view_position_cart() const;
inline string_list *get_channel_options_list () {
return channel_options_list;
}

View file

@ -41,7 +41,6 @@
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
#include <Viewer/renderer.hxx>
#include <Viewer/viewer.hxx>
#include <Viewer/splash.hxx>
#include <Scripting/NasalSys.hxx>
@ -314,9 +313,8 @@ void FGTileMgr::update_queues()
// disk.
void FGTileMgr::update(double)
{
SGVec3d viewPos = globals->get_current_view()->get_view_pos();
double vis = _visibilityMeters->getDoubleValue();
schedule_tiles_at(SGGeod::fromCart(viewPos), vis);
schedule_tiles_at(globals->get_view_position(), vis);
update_queues();

View file

@ -410,8 +410,7 @@ void FGLight::updateSunPos()
_sun_vec_inv = - _sun_vec;
// calculate the sun's relative angle to local up
FGViewer *v = globals->get_current_view();
SGQuatd hlOr = SGQuatd::fromLonLat( v->getPosition() );
SGQuatd hlOr = SGQuatd::fromLonLat( globals->get_view_position() );
SGVec3d world_up = hlOr.backTransform( -SGVec3d::e3() );
// cout << "nup = " << nup[0] << "," << nup[1] << ","
// << nup[2] << endl;

View file

@ -303,7 +303,7 @@ void FGTrafficManager::update(double /*dt */ )
return;
}
SGVec3d userCart = globals->get_aircraft_positon_cart();
SGVec3d userCart = globals->get_aircraft_position_cart();
if (currAircraft == scheduledAircraft.end()) {
currAircraft = scheduledAircraft.begin();