#include "viewmgr.hxx"
#include <string.h> // strcmp
-#include <boost/format.hpp>
#include <simgear/compiler.h>
#include <simgear/sound/soundmgr_openal.hxx>
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()
{
-// for automatic untying:
-#define x(str) ((void)tied_props.push_back(str), str)
+ // 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,
- &FGViewMgr::getViewHeadingOffset_deg,
- &FGViewMgr::setViewHeadingOffset_deg);
+ _tiedProperties.setRoot(fgGetNode("/sim/current-view", true));
+ _tiedProperties.Tie("heading-offset-deg", this,
+ &FGViewMgr::getViewHeadingOffset_deg,
+ &FGViewMgr::setViewHeadingOffset_deg);
fgSetArchivable("/sim/current-view/heading-offset-deg");
- fgTie("/sim/current-view/goal-heading-offset-deg", this,
- &FGViewMgr::getViewGoalHeadingOffset_deg,
- &FGViewMgr::setViewGoalHeadingOffset_deg);
+ _tiedProperties.Tie("goal-heading-offset-deg", this,
+ &FGViewMgr::getViewGoalHeadingOffset_deg,
+ &FGViewMgr::setViewGoalHeadingOffset_deg);
fgSetArchivable("/sim/current-view/goal-heading-offset-deg");
- fgTie("/sim/current-view/pitch-offset-deg", this,
- &FGViewMgr::getViewPitchOffset_deg,
- &FGViewMgr::setViewPitchOffset_deg);
+ _tiedProperties.Tie("pitch-offset-deg", this,
+ &FGViewMgr::getViewPitchOffset_deg,
+ &FGViewMgr::setViewPitchOffset_deg);
fgSetArchivable("/sim/current-view/pitch-offset-deg");
- fgTie("/sim/current-view/goal-pitch-offset-deg", this,
- &FGViewMgr::getGoalViewPitchOffset_deg,
- &FGViewMgr::setGoalViewPitchOffset_deg);
+ _tiedProperties.Tie("goal-pitch-offset-deg", this,
+ &FGViewMgr::getGoalViewPitchOffset_deg,
+ &FGViewMgr::setGoalViewPitchOffset_deg);
fgSetArchivable("/sim/current-view/goal-pitch-offset-deg");
- fgTie("/sim/current-view/roll-offset-deg", this,
- &FGViewMgr::getViewRollOffset_deg,
- &FGViewMgr::setViewRollOffset_deg);
+ _tiedProperties.Tie("roll-offset-deg", this,
+ &FGViewMgr::getViewRollOffset_deg,
+ &FGViewMgr::setViewRollOffset_deg);
fgSetArchivable("/sim/current-view/roll-offset-deg");
- fgTie("/sim/current-view/goal-roll-offset-deg", this,
- &FGViewMgr::getGoalViewRollOffset_deg,
- &FGViewMgr::setGoalViewRollOffset_deg);
+ _tiedProperties.Tie("goal-roll-offset-deg", this,
+ &FGViewMgr::getGoalViewRollOffset_deg,
+ &FGViewMgr::setGoalViewRollOffset_deg);
fgSetArchivable("/sim/current-view/goal-roll-offset-deg");
- fgTie("/sim/current-view/view-number", this,
+ _tiedProperties.Tie("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);
+ _tiedProperties.Tie("axes/long", this,
+ (double_getter)0, &FGViewMgr::setViewAxisLong);
fgSetArchivable("/sim/current-view/axes/long");
- fgTie("/sim/current-view/axes/lat", this,
- (double_getter)0, &FGViewMgr::setViewAxisLat);
+ _tiedProperties.Tie("axes/lat", this,
+ (double_getter)0, &FGViewMgr::setViewAxisLat);
fgSetArchivable("/sim/current-view/axes/lat");
- fgTie("/sim/current-view/field-of-view", this,
- &FGViewMgr::getFOV_deg, &FGViewMgr::setFOV_deg);
+ _tiedProperties.Tie("field-of-view", this,
+ &FGViewMgr::getFOV_deg, &FGViewMgr::setFOV_deg);
fgSetArchivable("/sim/current-view/field-of-view");
- fgTie("/sim/current-view/aspect-ratio-multiplier", this,
- &FGViewMgr::getARM_deg, &FGViewMgr::setARM_deg);
+ _tiedProperties.Tie("aspect-ratio-multiplier", this,
+ &FGViewMgr::getARM_deg, &FGViewMgr::setARM_deg);
fgSetArchivable("/sim/current-view/field-of-view");
- fgTie("/sim/current-view/ground-level-nearplane-m", this,
- &FGViewMgr::getNear_m, &FGViewMgr::setNear_m);
+ _tiedProperties.Tie("ground-level-nearplane-m", this,
+ &FGViewMgr::getNear_m, &FGViewMgr::setNear_m);
fgSetArchivable("/sim/current-view/ground-level-nearplane-m");
- fgTie(x("/sim/current-view/view_orientation"), this,
- &FGViewMgr::getCurrentViewOrientation);
- fgTie(x("/sim/current-view/view_or_offset"), this,
- &FGViewMgr::getCurrentViewOrOffset);
-
- fgTie(x("/sim/current-view/view_frame"), this,
- &FGViewMgr::getCurrentViewFrame);
-
SGPropertyNode *n = fgGetNode("/sim/current-view", true);
- n->tie("viewer-x-m", SGRawValuePointer<double>(&abs_viewer_position[0]));
- n->tie("viewer-y-m", SGRawValuePointer<double>(&abs_viewer_position[1]));
- n->tie("viewer-z-m", SGRawValuePointer<double>(&abs_viewer_position[2]));
-
-#undef x
+ _tiedProperties.Tie(n->getNode("viewer-x-m", true),SGRawValuePointer<double>(&abs_viewer_position[0]));
+ _tiedProperties.Tie(n->getNode("viewer-y-m", true),SGRawValuePointer<double>(&abs_viewer_position[1]));
+ _tiedProperties.Tie(n->getNode("viewer-z-m", true),SGRawValuePointer<double>(&abs_viewer_position[2]));
+
+ _tiedProperties.Tie("debug/orientation-w", this,
+ &FGViewMgr::getCurrentViewOrientation_w);
+ _tiedProperties.Tie("debug/orientation-x", this,
+ &FGViewMgr::getCurrentViewOrientation_x);
+ _tiedProperties.Tie("debug/orientation-y", this,
+ &FGViewMgr::getCurrentViewOrientation_y);
+ _tiedProperties.Tie("debug/orientation-z", this,
+ &FGViewMgr::getCurrentViewOrientation_z);
+
+ _tiedProperties.Tie("debug/orientation_offset-w", this,
+ &FGViewMgr::getCurrentViewOrOffset_w);
+ _tiedProperties.Tie("debug/orientation_offset-x", this,
+ &FGViewMgr::getCurrentViewOrOffset_x);
+ _tiedProperties.Tie("debug/orientation_offset-y", this,
+ &FGViewMgr::getCurrentViewOrOffset_y);
+ _tiedProperties.Tie("debug/orientation_offset-z", this,
+ &FGViewMgr::getCurrentViewOrOffset_z);
+
+ _tiedProperties.Tie("debug/frame-w", this,
+ &FGViewMgr::getCurrentViewFrame_w);
+ _tiedProperties.Tie("debug/frame-x", this,
+ &FGViewMgr::getCurrentViewFrame_x);
+ _tiedProperties.Tie("debug/frame-y", this,
+ &FGViewMgr::getCurrentViewFrame_y);
+ _tiedProperties.Tie("debug/frame-z", this,
+ &FGViewMgr::getCurrentViewFrame_z);
}
void
FGViewMgr::unbind ()
{
- // FIXME:
- // need to redo these bindings to the new locations (move to viewer?)
- fgUntie("/sim/current-view/heading-offset-deg");
- fgUntie("/sim/current-view/goal-heading-offset-deg");
- fgUntie("/sim/current-view/pitch-offset-deg");
- fgUntie("/sim/current-view/goal-pitch-offset-deg");
- fgUntie("/sim/current-view/field-of-view");
- fgUntie("/sim/current-view/aspect-ratio-multiplier");
- fgUntie("/sim/current-view/view-number");
- fgUntie("/sim/current-view/axes/long");
- fgUntie("/sim/current-view/axes/lat");
- fgUntie("/sim/current-view/ground-level-nearplane-m");
- fgUntie("/sim/current-view/viewer-x-m");
- fgUntie("/sim/current-view/viewer-y-m");
- fgUntie("/sim/current-view/viewer-z-m");
-
- list<const char*>::const_iterator it;
- for (it = tied_props.begin(); it != tied_props.end(); it++){
- fgUntie(*it);
- }
-
+ _tiedProperties.Untie();
}
void
FGViewMgr::update (double dt)
{
-
FGViewer *loop_view = (FGViewer *)get_current_view();
if (loop_view == 0) return;
abs_viewer_position = loop_view->getViewPosition();
// update audio listener values
- // set the viewer posotion in Cartesian coordinates in meters
- smgr->set_position( abs_viewer_position );
+ // 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);
axis_lat = axis;
}
-// Convert a quat to a string.
-// We assume the quat is being used as a rotor, so we
-// coerce it to standard rotor form, making the scalar
-// part non-negative, to eliminate double coverage of
-// the rotation group.
-// The format is "w ; x y z" with a semicolon separating
-// the scalar part from the bivector components.
-const char* format_rotor(const SGQuatd _quat){
- SGQuatd quat(_quat);
- if (quat.w() < 0.) quat *= -1.; // remove double coverage
- return str(boost::format("%6.3f ; %6.3f %6.3f %6.3f")
- % quat.w()
- % quat.x()
- % quat.y()
- % quat.z() ).c_str();
-}
-
// reference frame orientation.
// This is the view orientation you get when you have no
// view offset, i.e. the offset operator is the identity.
// The components of this quat are expressed in
// the conventional aviation basis set,
// i.e. x=forward, y=starboard, z=bottom
-const char* FGViewMgr::getCurrentViewFrame() const{
- return format_rotor(current_view_orientation * conj(fsb2sta)
- * conj(current_view_or_offset) );
+double FGViewMgr::getCurrentViewFrame_w() const{
+ return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).w();
+}
+double FGViewMgr::getCurrentViewFrame_x() const{
+ return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).x();
}
+double FGViewMgr::getCurrentViewFrame_y() const{
+ return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).y();
+}
+double FGViewMgr::getCurrentViewFrame_z() const{
+ return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).z();
+}
+
// view offset.
// This rotation takes you from the aforementioned
// The components of this quaternion are expressed in
// the conventional aviation basis set,
// i.e. x=forward, y=starboard, z=bottom
-const char* FGViewMgr::getCurrentViewOrOffset() const{
- return format_rotor(current_view_or_offset);
+double FGViewMgr::getCurrentViewOrOffset_w() const{
+ return current_view_or_offset.w();
}
+double FGViewMgr::getCurrentViewOrOffset_x() const{
+ return current_view_or_offset.x();
+}
+double FGViewMgr::getCurrentViewOrOffset_y() const{
+ return current_view_or_offset.y();
+}
+double FGViewMgr::getCurrentViewOrOffset_z() const{
+ return current_view_or_offset.z();
+}
+
// current view orientation.
// This is a rotation relative to the earth-centered (ec)
// the components of this quat are displayed using the
// conventional ECEF basis set. This is *not* the way
// the view orientation is stored in the views[] array,
-// but is easier for most people to understand.
+// but is easier for non-graphics hackers to understand.
// If we did not remove this factor of fsb2sta here and
// in getCurrentViewFrame, that would be equivalent to
// the following peculiar reference orientation:
// -- aircraft Yprime axis (top) pointed east
// -- aircraft Zprime axis (aft) pointed north
// meaning the OpenGL axes are aligned with the ECEF axes.
-const char* FGViewMgr::getCurrentViewOrientation() const{
- return format_rotor(current_view_orientation * conj(fsb2sta));
+double FGViewMgr::getCurrentViewOrientation_w() const{
+ return (current_view_orientation * conj(fsb2sta())).w();
+}
+double FGViewMgr::getCurrentViewOrientation_x() const{
+ return (current_view_orientation * conj(fsb2sta())).x();
+}
+double FGViewMgr::getCurrentViewOrientation_y() const{
+ return (current_view_orientation * conj(fsb2sta())).y();
+}
+double FGViewMgr::getCurrentViewOrientation_z() const{
+ return (current_view_orientation * conj(fsb2sta())).z();
}
void