commit 11baad01b3f3ca9729627fe59ecb2aa3a19d040a Author: John Denker Date: Wed Nov 11 08:05:04 2009 -0700 Do not pass automatic (stack) variables to tie() mechanism. diff --git a/src/Main/viewmgr.cxx b/src/Main/viewmgr.cxx index 6d48451..72f8ee3 100644 --- a/src/Main/viewmgr.cxx +++ b/src/Main/viewmgr.cxx @@ -45,10 +45,16 @@ FGViewMgr::FGViewMgr( void ) : current(0) { smgr = globals->get_soundmgr(); + CurrentViewOrientation_str = new char[formatted_rotor_size]; + CurrentViewOrOffset_str = new char[formatted_rotor_size]; + CurrentViewFrame_str = new char[formatted_rotor_size]; } // Destructor FGViewMgr::~FGViewMgr( void ) { + delete [] CurrentViewOrientation_str; + delete [] CurrentViewOrOffset_str; + delete [] CurrentViewFrame_str; } void @@ -770,21 +776,29 @@ FGViewMgr::setViewAxisLat (double axis) axis_lat = axis; } -// Convert a quat to a string. +// Convert a quat to a char*. +// +// FIXME: This ought to be implemented in terms of strings +// not char*s, but strings are not supported by the simgear +// tie mechanism. +// // 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){ +// +// A bufsize of at least formatted_rotor_size is required. + +void format_rotor(const SGQuatd _quat, char* buf, const size_t bufsize){ 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(); + snprintf(buf, bufsize, "%6.3f ; %6.3f %6.3f %6.3f", + quat.w(), + quat.x(), + quat.y(), + quat.z() ); } // reference frame orientation. @@ -807,9 +821,12 @@ const char* format_rotor(const SGQuatd _quat){ // 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) ); + format_rotor(current_view_orientation * conj(fsb2sta) + * conj(current_view_or_offset), + CurrentViewFrame_str, formatted_rotor_size); + return CurrentViewFrame_str; } // view offset. @@ -821,37 +838,26 @@ const char* FGViewMgr::getCurrentViewFrame() const{ // 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); + format_rotor(current_view_or_offset, + CurrentViewOrOffset_str, formatted_rotor_size); + return CurrentViewOrOffset_str; } // 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 most people 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. +// NOTE: Here we remove a factor of fsb2sta so that this +// quat is displayed as a rotation relative to the standard +// ECEF orientation of the conventional aviation XYZ body axes +// http://www.av8n.com/physics/coords.htm#sec-ecef-body +// ... which is *not* the same as ECEF+OpenGL camera axes: +// http://www.av8n.com/physics/coords.htm#sec-ecef-opengl + const char* FGViewMgr::getCurrentViewOrientation() const{ - return format_rotor(current_view_orientation * conj(fsb2sta)); + format_rotor(current_view_orientation * conj(fsb2sta), + CurrentViewOrientation_str, formatted_rotor_size); + return CurrentViewOrientation_str; } void diff --git a/src/Main/viewmgr.hxx b/src/Main/viewmgr.hxx index 30f81be..8795591 100644 --- a/src/Main/viewmgr.hxx +++ b/src/Main/viewmgr.hxx @@ -120,9 +120,13 @@ private: int getView () const; void setView (int newview); // quaternion accessors: +#define formatted_rotor_size 30 const char* getCurrentViewOrientation() const; + char* CurrentViewOrientation_str; const char* getCurrentViewOrOffset() const; + char* CurrentViewOrOffset_str; const char* getCurrentViewFrame() const; + char* CurrentViewFrame_str; bool stationary () const;