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:
parent
4456f42e67
commit
649d579124
8 changed files with 33 additions and 19 deletions
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
#include <Viewer/viewer.hxx>
|
|
||||||
#include <Scenery/scenery.hxx>
|
#include <Scenery/scenery.hxx>
|
||||||
#include <Scenery/tilemgr.hxx>
|
#include <Scenery/tilemgr.hxx>
|
||||||
#include <Airports/dynamics.hxx>
|
#include <Airports/dynamics.hxx>
|
||||||
|
@ -172,8 +171,7 @@ void FGAIAircraft::setPerformance(const std::string& acclass) {
|
||||||
void FGAIAircraft::checkVisibility()
|
void FGAIAircraft::checkVisibility()
|
||||||
{
|
{
|
||||||
double visibility_meters = fgGetDouble("/environment/visibility-m");
|
double visibility_meters = fgGetDouble("/environment/visibility-m");
|
||||||
FGViewer* vw = globals->get_current_view();
|
invisible = (SGGeodesy::distanceM(globals->get_view_position(), pos) > visibility_meters);
|
||||||
invisible = (SGGeodesy::distanceM(vw->getPosition(), 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.
|
// Only do the proper hitlist stuff if we are within visible range of the viewer.
|
||||||
if (!invisible) {
|
if (!invisible) {
|
||||||
double visibility_meters = fgGetDouble("/environment/visibility-m");
|
double visibility_meters = fgGetDouble("/environment/visibility-m");
|
||||||
FGViewer* vw = globals->get_current_view();
|
if (SGGeodesy::distanceM(globals->get_view_position(), pos) > visibility_meters) {
|
||||||
|
|
||||||
if (SGGeodesy::distanceM(vw->getPosition(), pos) > visibility_meters) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -839,7 +835,7 @@ bool FGAIAircraft::aiTrafficVisible()
|
||||||
SGVec3d cartPos = SGVec3d::fromGeod(pos);
|
SGVec3d cartPos = SGVec3d::fromGeod(pos);
|
||||||
const double d2 = (TRAFFICTOAIDISTTODIE * SG_NM_TO_METER) *
|
const double d2 = (TRAFFICTOAIDISTTODIE * SG_NM_TO_METER) *
|
||||||
(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <Main/util.hxx>
|
#include <Main/util.hxx>
|
||||||
#include <Viewer/viewer.hxx>
|
|
||||||
|
|
||||||
#include "AICarrier.hxx"
|
#include "AICarrier.hxx"
|
||||||
|
|
||||||
|
@ -166,7 +165,7 @@ void FGAICarrier::update(double dt) {
|
||||||
SGVec3d cartPos = SGVec3d::fromGeod(pos);
|
SGVec3d cartPos = SGVec3d::fromGeod(pos);
|
||||||
|
|
||||||
// The position of the eyepoint - at least near that ...
|
// 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
|
// Add the position offset of the AIModel to gain the earth
|
||||||
// centered position
|
// centered position
|
||||||
SGVec3d eyeWrtCarrier = eyePos - cartPos;
|
SGVec3d eyeWrtCarrier = eyePos - cartPos;
|
||||||
|
|
|
@ -164,7 +164,7 @@ ADF::update (double delta_time_sec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the bearing to the transmitter
|
// 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 distance_nm = dist(_transmitter_cart, location) * SG_METER_TO_NM;
|
||||||
double range_nm = adjust_range(_transmitter_pos.getElevationFt(),
|
double range_nm = adjust_range(_transmitter_pos.getElevationFt(),
|
||||||
|
|
|
@ -148,6 +148,10 @@ FGGlobals::FGGlobals() :
|
||||||
positionLat = props->getNode("position/latitude-deg", true);
|
positionLat = props->getNode("position/latitude-deg", true);
|
||||||
positionAlt = props->getNode("position/altitude-ft", 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);
|
orientPitch = props->getNode("orientation/pitch-deg", true);
|
||||||
orientHeading = props->getNode("orientation/heading-deg", true);
|
orientHeading = props->getNode("orientation/heading-deg", true);
|
||||||
orientRoll = props->getNode("orientation/roll-deg", true);
|
orientRoll = props->getNode("orientation/roll-deg", true);
|
||||||
|
@ -380,7 +384,7 @@ FGGlobals::get_aircraft_position() const
|
||||||
}
|
}
|
||||||
|
|
||||||
SGVec3d
|
SGVec3d
|
||||||
FGGlobals::get_aircraft_positon_cart() const
|
FGGlobals::get_aircraft_position_cart() const
|
||||||
{
|
{
|
||||||
return SGVec3d::fromGeod(get_aircraft_position());
|
return SGVec3d::fromGeod(get_aircraft_position());
|
||||||
}
|
}
|
||||||
|
@ -392,6 +396,19 @@ void FGGlobals::get_aircraft_orientation(double& heading, double& pitch, double&
|
||||||
roll = orientRoll->getDoubleValue();
|
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.
|
// Save the current state as the initial state.
|
||||||
void
|
void
|
||||||
|
|
|
@ -148,6 +148,7 @@ private:
|
||||||
bool haveUserSettings;
|
bool haveUserSettings;
|
||||||
|
|
||||||
SGPropertyNode_ptr positionLon, positionLat, positionAlt;
|
SGPropertyNode_ptr positionLon, positionLat, positionAlt;
|
||||||
|
SGPropertyNode_ptr viewLon, viewLat, viewAlt;
|
||||||
SGPropertyNode_ptr orientHeading, orientPitch, orientRoll;
|
SGPropertyNode_ptr orientHeading, orientPitch, orientRoll;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -249,10 +250,14 @@ public:
|
||||||
|
|
||||||
SGGeod get_aircraft_position() const;
|
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);
|
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 () {
|
inline string_list *get_channel_options_list () {
|
||||||
return channel_options_list;
|
return channel_options_list;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,6 @@
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
#include <Viewer/renderer.hxx>
|
#include <Viewer/renderer.hxx>
|
||||||
#include <Viewer/viewer.hxx>
|
|
||||||
#include <Viewer/splash.hxx>
|
#include <Viewer/splash.hxx>
|
||||||
#include <Scripting/NasalSys.hxx>
|
#include <Scripting/NasalSys.hxx>
|
||||||
|
|
||||||
|
@ -314,9 +313,8 @@ void FGTileMgr::update_queues()
|
||||||
// disk.
|
// disk.
|
||||||
void FGTileMgr::update(double)
|
void FGTileMgr::update(double)
|
||||||
{
|
{
|
||||||
SGVec3d viewPos = globals->get_current_view()->get_view_pos();
|
|
||||||
double vis = _visibilityMeters->getDoubleValue();
|
double vis = _visibilityMeters->getDoubleValue();
|
||||||
schedule_tiles_at(SGGeod::fromCart(viewPos), vis);
|
schedule_tiles_at(globals->get_view_position(), vis);
|
||||||
|
|
||||||
update_queues();
|
update_queues();
|
||||||
|
|
||||||
|
|
|
@ -410,8 +410,7 @@ void FGLight::updateSunPos()
|
||||||
_sun_vec_inv = - _sun_vec;
|
_sun_vec_inv = - _sun_vec;
|
||||||
|
|
||||||
// calculate the sun's relative angle to local up
|
// calculate the sun's relative angle to local up
|
||||||
FGViewer *v = globals->get_current_view();
|
SGQuatd hlOr = SGQuatd::fromLonLat( globals->get_view_position() );
|
||||||
SGQuatd hlOr = SGQuatd::fromLonLat( v->getPosition() );
|
|
||||||
SGVec3d world_up = hlOr.backTransform( -SGVec3d::e3() );
|
SGVec3d world_up = hlOr.backTransform( -SGVec3d::e3() );
|
||||||
// cout << "nup = " << nup[0] << "," << nup[1] << ","
|
// cout << "nup = " << nup[0] << "," << nup[1] << ","
|
||||||
// << nup[2] << endl;
|
// << nup[2] << endl;
|
||||||
|
|
|
@ -303,7 +303,7 @@ void FGTrafficManager::update(double /*dt */ )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SGVec3d userCart = globals->get_aircraft_positon_cart();
|
SGVec3d userCart = globals->get_aircraft_position_cart();
|
||||||
|
|
||||||
if (currAircraft == scheduledAircraft.end()) {
|
if (currAircraft == scheduledAircraft.end()) {
|
||||||
currAircraft = scheduledAircraft.begin();
|
currAircraft = scheduledAircraft.begin();
|
||||||
|
|
Loading…
Reference in a new issue