diff --git a/src/Main/viewmgr.cxx b/src/Main/viewmgr.cxx index 544076b98..5f8485a68 100644 --- a/src/Main/viewmgr.cxx +++ b/src/Main/viewmgr.cxx @@ -28,6 +28,7 @@ #include "viewmgr.hxx" #include // strcmp +#include #include #include @@ -162,6 +163,9 @@ typedef double (FGViewMgr::*double_getter)() const; void FGViewMgr::bind () { +// for automatic untying: +#define x(str) ((void)tied_props.push_back(str), str) + // these are bound to the current view properties fgTie("/sim/current-view/heading-offset-deg", this, &FGViewMgr::getViewHeadingOffset_deg, @@ -212,10 +216,20 @@ FGViewMgr::bind () &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/view1200"), this, + &FGViewMgr::getCurrentView1200); + SGPropertyNode *n = fgGetNode("/sim/current-view", true); n->tie("viewer-x-m", SGRawValuePointer(&abs_viewer_position[0])); n->tie("viewer-y-m", SGRawValuePointer(&abs_viewer_position[1])); n->tie("viewer-z-m", SGRawValuePointer(&abs_viewer_position[2])); + +#undef x } void @@ -236,6 +250,12 @@ FGViewMgr::unbind () fgUntie("/sim/current-view/viewer-x-m"); fgUntie("/sim/current-view/viewer-y-m"); fgUntie("/sim/current-view/viewer-z-m"); + + list::const_iterator it; + for (it = tied_props.begin(); it != tied_props.end(); it++){ + fgUntie(*it); + } + } void @@ -290,6 +310,9 @@ FGViewMgr::update (double dt) setViewTargetYOffset_m(fgGetDouble("/sim/current-view/target-y-offset-m")); setViewTargetZOffset_m(fgGetDouble("/sim/current-view/target-z-offset-m")); + current_view_orientation = loop_view->getViewOrientation(); + current_view_or_offset = loop_view->getViewOrientationOffset(); + // Update the current view do_axes(); loop_view->update(dt); @@ -298,7 +321,7 @@ FGViewMgr::update (double dt) // update audio listener values // set the viewer posotion in Cartesian coordinates in meters smgr->set_position( abs_viewer_position ); - smgr->set_orientation( loop_view->getViewOrientation() ); + smgr->set_orientation( current_view_orientation ); // get the model velocity SGVec3f velocity = SGVec3f::zeros(); @@ -747,6 +770,54 @@ FGViewMgr::setViewAxisLat (double axis) axis_lat = axis; } +static const char* fmt("%6.3f ; %6.3f %6.3f %6.3f"); + +// current view orientation +// This is a rotation relative to the earth-centered (ec) +// refrence frame. +// However, the components of this quaternion are expressed +// in the OpenGL camera system i.e. x-right, y-up, z-back. +const char* FGViewMgr::getCurrentViewOrientation() const{ + return str(boost::format(fmt) + % current_view_orientation.w() + % current_view_orientation.x() + % current_view_orientation.y() + % current_view_orientation.z() ).c_str(); +} + +// This rotation takes you from the 12:00 direction +// i.e. body attitude +// to whatever the current view direction is. +// The components of this quaternion are expressed in +// the XYZ body frame. +const char* FGViewMgr::getCurrentViewOrOffset() const{ + return str(boost::format(fmt) + % current_view_or_offset.w() + % current_view_or_offset.x() + % current_view_or_offset.y() + % current_view_or_offset.z() ).c_str(); +} + +// This rotates the conventional aviation XYZ body system +// i.e. x-forward, y-starboard, z-bottom +// to the OpenGL camera system +// i.e. x-right, y-up, z-back. +const SGQuatd q(-0.5, -0.5, 0.5, 0.5); + +// The current attitude of the aircraft, +// i.e. the 12:00 direction. +// The components of this quaternion are expressed in +// the GL camera frame. +const char* FGViewMgr::getCurrentView1200() const{ + SGQuatd view1200 = current_view_orientation + * conj(q) * conj(current_view_or_offset) * q; + return str(boost::format(fmt) + % view1200.w() + % view1200.x() + % view1200.y() + % view1200.z() ).c_str(); +} + void FGViewMgr::do_axes () { diff --git a/src/Main/viewmgr.hxx b/src/Main/viewmgr.hxx index 2c0feb428..f1a0eccd4 100644 --- a/src/Main/viewmgr.hxx +++ b/src/Main/viewmgr.hxx @@ -25,6 +25,7 @@ #define _VIEWMGR_HXX #include +#include #include #include @@ -76,6 +77,8 @@ public: private: + list tied_props; + double axis_long; double axis_lat; @@ -116,6 +119,11 @@ private: void setViewAxisLat (double axis); int getView () const; void setView (int newview); +// quaternion accessors: + const char* getCurrentViewOrientation() const; + const char* getCurrentViewOrOffset() const; + const char* getCurrentView1200() const; + bool stationary () const; SGPropertyNode_ptr view_number; @@ -125,6 +133,7 @@ private: SGVec3d abs_viewer_position; int current; + SGQuatd current_view_orientation, current_view_or_offset; SGSoundMgr *smgr;