FGViewMgr::FGViewMgr( void ) :
axis_long(0),
axis_lat(0),
+ inited(false),
view_number(fgGetNode("/sim/current-view/view-number", true)),
config_list(fgGetNode("/sim", true)->getChildren("view")),
- current(0)
+ abs_viewer_position(SGVec3d::zeros()),
+ current(0),
+ current_view_orientation(SGQuatd::zeros()),
+ current_view_or_offset(SGQuatd::zeros()),
+ smgr(globals->get_soundmgr())
{
- smgr = globals->get_soundmgr();
}
// Destructor
void
FGViewMgr::init ()
{
+ if (inited) {
+ SG_LOG(SG_VIEW, SG_WARN, "duplicate init of view manager");
+ return;
+ }
+
+ inited = true;
+
double aspect_ratio_multiplier
= fgGetDouble("/sim/current-view/aspect-ratio-multiplier");
}
copyToCurrent();
+ do_bind();
}
void
typedef double (FGViewMgr::*double_getter)() const;
void
-FGViewMgr::bind ()
+FGViewMgr::bind()
+{
+ // view-manager code was designed to init before bind, so
+ // this is a no-op; init() calls the real bind() impl below
+}
+
+void
+FGViewMgr::do_bind()
{
// these are bound to the current view properties
fgTie("/sim/current-view/heading-offset-deg", this,
fgTie("/sim/current-view/view-number", this,
&FGViewMgr::getView, &FGViewMgr::setView);
- fgSetArchivable("/sim/current-view/view-number", FALSE);
+ fgSetArchivable("/sim/current-view/view-number", false);
fgTie("/sim/current-view/axes/long", this,
(double_getter)0, &FGViewMgr::setViewAxisLong);
fgUntie("/sim/current-view/viewer-y-m");
fgUntie("/sim/current-view/viewer-z-m");
- list<const char*>::const_iterator it;
+ std::list<const char*>::const_iterator it;
for (it = tied_props.begin(); it != tied_props.end(); it++){
fgUntie(*it);
}
abs_viewer_position = loop_view->getViewPosition();
// update audio listener values
- // set the viewer posotion in Cartesian coordinates in meters
- smgr->set_position( SGVec3d::fromGeod(loop_view->getPosition()) );
- smgr->set_position_offset( loop_view->getOffset_m() );
+ // set the viewer position in Cartesian coordinates in meters
+ smgr->set_position( abs_viewer_position, loop_view->getPosition() );
smgr->set_orientation( current_view_orientation );
// get the model velocity
- SGVec3f velocity = SGVec3f::zeros();
+ SGVec3d velocity = SGVec3d::zeros();
if ( !stationary() ) {
velocity = globals->get_aircraft_model()->getVelocity();
}
- smgr->set_velocity(velocity);
+ smgr->set_velocity( velocity );
}
void
FGViewMgr::copyToCurrent()
{
+ if (!inited) {
+ return;
+ }
+
SGPropertyNode *n = config_list[current];
fgSetString("/sim/current-view/name", n->getStringValue("name"));
fgSetString("/sim/current-view/type", n->getStringValue("type"));
newview = 0;
// set new view
- set_view(newview);
+ current = newview;
// copy in view data
copyToCurrent();
-
- // Copy the fdm's position into the SGLocation which is shared with
- // some views ...
- globals->get_aircraft_model()->update(0);
- // Do the update ...
- update(0);
}
void
FGViewMgr::setARM_deg (double aspect_ratio_multiplier)
-{
+{
FGViewer * view = get_current_view();
if (view != 0)
view->set_aspect_ratio_multiplier(aspect_ratio_multiplier);