1
0
Fork 0

John Denker:

Together with previous patch, make view reference frame, view offset,
and current view visible in property tree.
Also some comments about the concepts behind these variables.
This commit is contained in:
ehofman 2009-11-08 13:41:03 +00:00 committed by Tim Moore
parent b8f5013751
commit e750dc368d
2 changed files with 85 additions and 43 deletions

View file

@ -221,8 +221,8 @@ FGViewMgr::bind ()
fgTie(x("/sim/current-view/view_or_offset"), this, fgTie(x("/sim/current-view/view_or_offset"), this,
&FGViewMgr::getCurrentViewOrOffset); &FGViewMgr::getCurrentViewOrOffset);
fgTie(x("/sim/current-view/view1200"), this, fgTie(x("/sim/current-view/view_frame"), this,
&FGViewMgr::getCurrentView1200); &FGViewMgr::getCurrentViewFrame);
SGPropertyNode *n = fgGetNode("/sim/current-view", true); SGPropertyNode *n = fgGetNode("/sim/current-view", true);
n->tie("viewer-x-m", SGRawValuePointer<double>(&abs_viewer_position[0])); n->tie("viewer-x-m", SGRawValuePointer<double>(&abs_viewer_position[0]));
@ -770,52 +770,88 @@ FGViewMgr::setViewAxisLat (double axis)
axis_lat = axis; axis_lat = axis;
} }
static const char* fmt("%6.3f ; %6.3f %6.3f %6.3f"); // Convert a quat to a string.
// We assume the quat is being used as a rotor, so we
// current view orientation // coerce it to standard rotor form, making the scalar
// This is a rotation relative to the earth-centered (ec) // part non-negative, to eliminate double coverage of
// refrence frame. // the rotation group.
// However, the components of this quaternion are expressed // The format is "w ; x y z" with a semicolon separating
// in the OpenGL camera system i.e. x-right, y-up, z-back. // the scalar part from the bivector components.
const char* FGViewMgr::getCurrentViewOrientation() const{ const char* format_rotor(const SGQuatd _quat){
return str(boost::format(fmt) SGQuatd quat(_quat);
% current_view_orientation.w() if (quat.w() < 0.) quat *= -1.; // remove double coverage
% current_view_orientation.x() return str(boost::format("%6.3f ; %6.3f %6.3f %6.3f")
% current_view_orientation.y() % quat.w()
% current_view_orientation.z() ).c_str(); % quat.x()
% quat.y()
% quat.z() ).c_str();
} }
// This rotation takes you from the 12:00 direction // reference frame orientation.
// i.e. body attitude // This is the view orientation you get when you have no
// to whatever the current view direction is. // 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
const char* FGViewMgr::getCurrentViewFrame() const{
return format_rotor(current_view_orientation * conj(fsb2sta)
* conj(current_view_or_offset) );
}
// 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 components of this quaternion are expressed in
// the XYZ body frame. // the conventional aviation basis set,
// i.e. x=forward, y=starboard, z=bottom
const char* FGViewMgr::getCurrentViewOrOffset() const{ const char* FGViewMgr::getCurrentViewOrOffset() const{
return str(boost::format(fmt) return format_rotor(current_view_or_offset);
% 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 // current view orientation.
// i.e. x-forward, y-starboard, z-bottom // This is a rotation relative to the earth-centered (ec)
// to the OpenGL camera system // reference frame.
// i.e. x-right, y-up, z-back. //
const SGQuatd q(-0.5, -0.5, 0.5, 0.5); // NOTE: Here we remove a factor of fsb2sta so that
// the components of this quat are displayed using the
// The current attitude of the aircraft, // conventional ECEF basis set. This is *not* the way
// i.e. the 12:00 direction. // the view orientation is stored in the views[] array,
// The components of this quaternion are expressed in // but is easier for most people to understand.
// the GL camera frame. // If we did not remove this factor of fsb2sta here and
const char* FGViewMgr::getCurrentView1200() const{ // in getCurrentViewFrame, that would be equivalent to
SGQuatd view1200 = current_view_orientation // the following peculiar reference orientation:
* conj(q) * conj(current_view_or_offset) * q; // Suppose you are over the Gulf of Guinea, at (lat,lon) = (0,0).
return str(boost::format(fmt) // Then the reference frame orientation can be achieved via:
% view1200.w() // -- The aircraft X-axis (nose) headed south.
% view1200.x() // -- The aircraft Y-axis (starboard wingtip) pointing up.
% view1200.y() // -- The aircraft Z-axis (belly) pointing west.
% view1200.z() ).c_str(); // 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.
const char* FGViewMgr::getCurrentViewOrientation() const{
return format_rotor(current_view_orientation * conj(fsb2sta));
} }
void void

View file

@ -122,7 +122,7 @@ private:
// quaternion accessors: // quaternion accessors:
const char* getCurrentViewOrientation() const; const char* getCurrentViewOrientation() const;
const char* getCurrentViewOrOffset() const; const char* getCurrentViewOrOffset() const;
const char* getCurrentView1200() const; const char* getCurrentViewFrame() const;
bool stationary () const; bool stationary () const;
@ -139,5 +139,11 @@ private:
}; };
// This takes the conventional aviation XYZ body system
// i.e. x=forward, y=starboard, z=bottom
// which is widely used in FGFS
// and rotates it into the OpenGL camera system
// i.e. Xprime=starboard, Yprime=top, Zprime=aft.
const SGQuatd fsb2sta(-0.5, -0.5, 0.5, 0.5);
#endif // _VIEWMGR_HXX #endif // _VIEWMGR_HXX