X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FMain%2Fviewmgr.cxx;h=270c579e03b82dcfd89457b8a8dd9b472bead2d5;hb=224afcc7e4cb4191be15f3df025164fcd83f5102;hp=5f8485a6820dd04f8d593fbaa64bea2405395869;hpb=ab149d0036f21fd2ad685f7efea28f84986534b0;p=flightgear.git diff --git a/src/Main/viewmgr.cxx b/src/Main/viewmgr.cxx index 5f8485a68..270c579e0 100644 --- a/src/Main/viewmgr.cxx +++ b/src/Main/viewmgr.cxx @@ -28,7 +28,6 @@ #include "viewmgr.hxx" #include // strcmp -#include #include #include @@ -163,9 +162,6 @@ 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, @@ -216,19 +212,41 @@ 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])); +// for automatic untying: +#define x(str) ((void)tied_props.push_back(str), str) + + fgTie(x("/sim/current-view/debug/orientation-w"), this, + &FGViewMgr::getCurrentViewOrientation_w); + fgTie(x("/sim/current-view/debug/orientation-x"), this, + &FGViewMgr::getCurrentViewOrientation_x); + fgTie(x("/sim/current-view/debug/orientation-y"), this, + &FGViewMgr::getCurrentViewOrientation_y); + fgTie(x("/sim/current-view/debug/orientation-z"), this, + &FGViewMgr::getCurrentViewOrientation_z); + + fgTie(x("/sim/current-view/debug/orientation_offset-w"), this, + &FGViewMgr::getCurrentViewOrOffset_w); + fgTie(x("/sim/current-view/debug/orientation_offset-x"), this, + &FGViewMgr::getCurrentViewOrOffset_x); + fgTie(x("/sim/current-view/debug/orientation_offset-y"), this, + &FGViewMgr::getCurrentViewOrOffset_y); + fgTie(x("/sim/current-view/debug/orientation_offset-z"), this, + &FGViewMgr::getCurrentViewOrOffset_z); + + fgTie(x("/sim/current-view/debug/frame-w"), this, + &FGViewMgr::getCurrentViewFrame_w); + fgTie(x("/sim/current-view/debug/frame-x"), this, + &FGViewMgr::getCurrentViewFrame_x); + fgTie(x("/sim/current-view/debug/frame-y"), this, + &FGViewMgr::getCurrentViewFrame_y); + fgTie(x("/sim/current-view/debug/frame-z"), this, + &FGViewMgr::getCurrentViewFrame_z); + #undef x } @@ -320,15 +338,15 @@ 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_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 @@ -770,52 +788,99 @@ FGViewMgr::setViewAxisLat (double axis) axis_lat = axis; } -static const char* fmt("%6.3f ; %6.3f %6.3f %6.3f"); +// reference frame orientation. +// This is the view orientation you get when you have no +// view offset, i.e. the offset operator is the identity. +// +// For example, in the familiar "cockpit lookfrom" view, +// the reference frame is equal to the aircraft attitude, +// i.e. it is the view looking towards 12:00 straight ahead. +// +// FIXME: Somebody needs to figure out what is the reference +// frame view for the other view modes. +// +// Conceptually, this quat represents a rotation relative +// to the ECEF reference orientation, as described at +// http://www.av8n.com/physics/coords.htm#sec-orientation +// +// See the NOTE concerning reference orientations, below. +// +// The components of this quat are expressed in +// the conventional aviation basis set, +// i.e. x=forward, y=starboard, z=bottom +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(); +} -// 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. + +// view offset. +// This rotation takes you from the aforementioned +// reference frame view orientation to whatever +// actual current view orientation is. +// // 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(); +// the conventional aviation basis set, +// i.e. x=forward, y=starboard, z=bottom +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) +// reference frame. +// +// NOTE: Here we remove a factor of fsb2sta so that +// 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 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: +// Suppose you are over the Gulf of Guinea, at (lat,lon) = (0,0). +// Then the reference frame orientation can be achieved via: +// -- The aircraft X-axis (nose) headed south. +// -- The aircraft Y-axis (starboard wingtip) pointing up. +// -- The aircraft Z-axis (belly) pointing west. +// To say the same thing in other words, and perhaps more to the +// point: If we use the OpenGL camera orientation conventions, +// i.e. Xprime=starboard, Yprime=top, Zprime=aft, then the +// aforementioned peculiar reference orientation at (lat,lon) +// = (0,0) can be described as: +// -- aircraft Xprime axis (starboard) pointed up +// -- aircraft Yprime axis (top) pointed east +// -- aircraft Zprime axis (aft) pointed north +// meaning the OpenGL axes are aligned with the ECEF axes. +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