X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FMain%2Fviewmgr.cxx;h=5a978be63608ffa4634a553b405effd6dbcbc8d1;hb=8a089f6d6f9e7851e73fd118cb9a5f5583cfe517;hp=3ebcbbc081a79cec22862244ccfd80e50a7e6fc3;hpb=a0d90b9746e8deb331bd1075de0bf052357c5d16;p=flightgear.git diff --git a/src/Main/viewmgr.cxx b/src/Main/viewmgr.cxx index 3ebcbbc08..5a978be63 100644 --- a/src/Main/viewmgr.cxx +++ b/src/Main/viewmgr.cxx @@ -3,7 +3,7 @@ // Written by Curtis Olson, started October 2000. // partially rewritten by Jim Wilson March 2002 // -// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org +// Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as @@ -17,27 +17,36 @@ // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // $Id$ -#include // strcmp - -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif #include "viewmgr.hxx" -#include "fg_props.hxx" +#include // strcmp + +#include +#include +#include +#include
+#include
// Constructor 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) { + smgr = globals->get_soundmgr(); } - // Destructor FGViewMgr::~FGViewMgr( void ) { } @@ -45,213 +54,129 @@ FGViewMgr::~FGViewMgr( void ) { void FGViewMgr::init () { - char stridx [ 20 ]; - string viewpath, nodepath, strdata; - bool from_model = false; - bool at_model = false; - int from_model_index = 0; - int at_model_index = 0; - double damp_alt, damp_roll, damp_pitch, damp_heading; - double x_offset_m, y_offset_m, z_offset_m, fov_deg; - double heading_offset_deg, pitch_offset_deg, roll_offset_deg; - double target_x_offset_m, target_y_offset_m, target_z_offset_m; - double near_m; - - for (int i = 0; i < fgGetInt("/sim/number-views"); i++) { - viewpath = "/sim/view"; - sprintf(stridx, "[%d]", i); - viewpath += stridx; - - // find out what type of view this is... - nodepath = viewpath; - nodepath += "/type"; - strdata = fgGetString(nodepath.c_str()); + if (inited) { + SG_LOG(SG_GENERAL, SG_WARN, "duplicate init of view manager"); + return; + } + + inited = true; + + double aspect_ratio_multiplier + = fgGetDouble("/sim/current-view/aspect-ratio-multiplier"); + + for (unsigned int i = 0; i < config_list.size(); i++) { + SGPropertyNode *n = config_list[i]; + + // find out if this is an internal view (e.g. in cockpit, low near plane) + bool internal = n->getBoolValue("internal", false); // FIXME: // this is assumed to be an aircraft model...we will need to read // model-from-type as well. + // find out if this is a model we are looking from... - nodepath = viewpath; - nodepath += "/config/from-model"; - from_model = fgGetBool(nodepath.c_str()); - - // get model index (which model) - if (from_model) { - nodepath = viewpath; - nodepath += "/config/from-model-idx"; - from_model_index = fgGetInt(nodepath.c_str()); - } + bool from_model = n->getBoolValue("config/from-model"); + int from_model_index = n->getIntValue("config/from-model-idx"); - if ( strcmp("lookat",strdata.c_str()) == 0 ) { - // find out if this is a model we are looking at... - nodepath = viewpath; - nodepath += "/config/at-model"; - at_model = fgGetBool(nodepath.c_str()); - - // get model index (which model) - if (at_model) { - nodepath = viewpath; - nodepath += "/config/at-model-idx"; - at_model_index = fgGetInt(nodepath.c_str()); - - // view damping (0.0: no damping; <0.0: all but alt; >0.0: damp all) - nodepath = viewpath; - nodepath += "/config/at-model-alt-damping"; - damp_alt = fgGetDouble(nodepath.c_str(), 0.0); - - nodepath = viewpath; - nodepath += "/config/at-model-roll-damping"; - damp_roll = fgGetDouble(nodepath.c_str(), 0.0); - - nodepath = viewpath; - nodepath += "/config/at-model-pitch-damping"; - damp_pitch = fgGetDouble(nodepath.c_str(), 0.0); - - nodepath = viewpath; - nodepath += "/config/at-model-heading-damping"; - damp_heading = fgGetDouble(nodepath.c_str(), 0.0); - } - } + double x_offset_m = n->getDoubleValue("config/x-offset-m"); + double y_offset_m = n->getDoubleValue("config/y-offset-m"); + double z_offset_m = n->getDoubleValue("config/z-offset-m"); - nodepath = viewpath; - nodepath += "/config/x-offset-m"; - x_offset_m = fgGetDouble(nodepath.c_str()); - nodepath = viewpath; - nodepath += "/config/y-offset-m"; - y_offset_m = fgGetDouble(nodepath.c_str()); - nodepath = viewpath; - nodepath += "/config/z-offset-m"; - z_offset_m = fgGetDouble(nodepath.c_str()); - nodepath = viewpath; - nodepath += "/config/pitch-offset-deg"; - pitch_offset_deg = fgGetDouble(nodepath.c_str()); - fgSetDouble(nodepath.c_str(),pitch_offset_deg); - nodepath = viewpath; - nodepath += "/config/heading-offset-deg"; - heading_offset_deg = fgGetDouble(nodepath.c_str()); - fgSetDouble(nodepath.c_str(),heading_offset_deg); - nodepath = viewpath; - nodepath += "/config/roll-offset-deg"; - roll_offset_deg = fgGetDouble(nodepath.c_str()); - fgSetDouble(nodepath.c_str(),roll_offset_deg); - nodepath = viewpath; - nodepath += "/config/default-field-of-view-deg"; - fov_deg = fgGetDouble(nodepath.c_str()); + double heading_offset_deg = n->getDoubleValue("config/heading-offset-deg"); + n->setDoubleValue("config/heading-offset-deg", heading_offset_deg); + double pitch_offset_deg = n->getDoubleValue("config/pitch-offset-deg"); + n->setDoubleValue("config/pitch-offset-deg", pitch_offset_deg); + double roll_offset_deg = n->getDoubleValue("config/roll-offset-deg"); + n->setDoubleValue("config/roll-offset-deg", roll_offset_deg); + + double fov_deg = n->getDoubleValue("config/default-field-of-view-deg"); + double near_m = n->getDoubleValue("config/ground-level-nearplane-m"); + + // supporting two types "lookat" = 1 and "lookfrom" = 0 + const char *type = n->getStringValue("type"); + if (!strcmp(type, "lookat")) { + + bool at_model = n->getBoolValue("config/at-model"); + int at_model_index = n->getIntValue("config/at-model-idx"); + + double damp_roll = n->getDoubleValue("config/at-model-roll-damping"); + double damp_pitch = n->getDoubleValue("config/at-model-pitch-damping"); + double damp_heading = n->getDoubleValue("config/at-model-heading-damping"); + + double target_x_offset_m = n->getDoubleValue("config/target-x-offset-m"); + double target_y_offset_m = n->getDoubleValue("config/target-y-offset-m"); + double target_z_offset_m = n->getDoubleValue("config/target-z-offset-m"); - // target offsets for lookat mode only... - nodepath = viewpath; - nodepath += "/config/target-x-offset-m"; - target_x_offset_m = fgGetDouble(nodepath.c_str()); - nodepath = viewpath; - nodepath += "/config/target-y-offset-m"; - target_y_offset_m = fgGetDouble(nodepath.c_str()); - nodepath = viewpath; - nodepath += "/config/target-z-offset-m"; - target_z_offset_m = fgGetDouble(nodepath.c_str()); - - nodepath = viewpath; - nodepath += "/config/ground-level-nearplane-m"; - near_m = fgGetDouble(nodepath.c_str()); - - // supporting two types now "lookat" = 1 and "lookfrom" = 0 - if ( strcmp("lookat",strdata.c_str()) == 0 ) add_view(new FGViewer ( FG_LOOKAT, from_model, from_model_index, at_model, at_model_index, - damp_alt, damp_roll, damp_pitch, damp_heading, + damp_roll, damp_pitch, damp_heading, x_offset_m, y_offset_m,z_offset_m, heading_offset_deg, pitch_offset_deg, - roll_offset_deg, fov_deg, + roll_offset_deg, fov_deg, aspect_ratio_multiplier, target_x_offset_m, target_y_offset_m, - target_z_offset_m, near_m )); - else + target_z_offset_m, near_m, internal )); + } else { add_view(new FGViewer ( FG_LOOKFROM, from_model, from_model_index, - false, 0, 0.0, 0.0, 0.0, 0.0, + false, 0, 0.0, 0.0, 0.0, x_offset_m, y_offset_m, z_offset_m, heading_offset_deg, pitch_offset_deg, - roll_offset_deg, fov_deg, 0, 0, 0, near_m )); + roll_offset_deg, fov_deg, aspect_ratio_multiplier, + 0, 0, 0, near_m, internal )); + } } copyToCurrent(); - + do_bind(); } void FGViewMgr::reinit () { - char stridx [ 20 ]; - string viewpath, nodepath, strdata; - double fov_deg; - // reset offsets and fov to configuration defaults - - for (int i = 0; i < fgGetInt("/sim/number-views"); i++) { - viewpath = "/sim/view"; - sprintf(stridx, "[%d]", i); - viewpath += stridx; - + for (unsigned int i = 0; i < config_list.size(); i++) { + SGPropertyNode *n = config_list[i]; setView(i); - nodepath = viewpath; - nodepath += "/config/x-offset-m"; - fgSetDouble("/sim/current-view/x-offset-m",fgGetDouble(nodepath.c_str())); - - nodepath = viewpath; - nodepath += "/config/y-offset-m"; - fgSetDouble("/sim/current-view/y-offset-m",fgGetDouble(nodepath.c_str())); - - nodepath = viewpath; - nodepath += "/config/z-offset-m"; - fgSetDouble("/sim/current-view/z-offset-m",fgGetDouble(nodepath.c_str())); - - nodepath = viewpath; - nodepath += "/config/pitch-offset-deg"; + fgSetDouble("/sim/current-view/x-offset-m", + n->getDoubleValue("config/x-offset-m")); + fgSetDouble("/sim/current-view/y-offset-m", + n->getDoubleValue("config/y-offset-m")); + fgSetDouble("/sim/current-view/z-offset-m", + n->getDoubleValue("config/z-offset-m")); fgSetDouble("/sim/current-view/pitch-offset-deg", - fgGetDouble(nodepath.c_str())); - - nodepath = viewpath; - nodepath += "/config/heading-offset-deg"; + n->getDoubleValue("config/pitch-offset-deg")); fgSetDouble("/sim/current-view/heading-offset-deg", - fgGetDouble(nodepath.c_str())); - - nodepath = viewpath; - nodepath += "/config/roll-offset-deg"; + n->getDoubleValue("config/heading-offset-deg")); fgSetDouble("/sim/current-view/roll-offset-deg", - fgGetDouble(nodepath.c_str())); + n->getDoubleValue("config/roll-offset-deg")); - nodepath = viewpath; - nodepath += "/config/default-field-of-view-deg"; - fov_deg = fgGetDouble(nodepath.c_str()); - if (fov_deg < 10.0) { + double fov_deg = n->getDoubleValue("config/default-field-of-view-deg"); + if (fov_deg < 10.0) fov_deg = 55.0; - } - fgSetDouble("/sim/current-view/field-of-view",fov_deg); + fgSetDouble("/sim/current-view/field-of-view", fov_deg); // target offsets for lookat mode only... - nodepath = viewpath; - nodepath += "/config/target-x-offset-m"; - fgSetDouble("/sim/current-view/target-x-offset-deg", - fgGetDouble(nodepath.c_str())); - - nodepath = viewpath; - nodepath += "/config/target-y-offset-m"; - fgSetDouble("/sim/current-view/target-y-offset-deg", - fgGetDouble(nodepath.c_str())); - - nodepath = viewpath; - nodepath += "/config/target-z-offset-m"; - fgSetDouble("/sim/current-view/target-z-offset-deg", - fgGetDouble(nodepath.c_str())); - - } - - setView(0); - + fgSetDouble("/sim/current-view/target-x-offset-m", + n->getDoubleValue("config/target-x-offset-m")); + fgSetDouble("/sim/current-view/target-y-offset-m", + n->getDoubleValue("config/target-y-offset-m")); + fgSetDouble("/sim/current-view/target-z-offset-m", + n->getDoubleValue("config/target-z-offset-m")); + } + setView(0); } typedef double (FGViewMgr::*double_getter)() const; void -FGViewMgr::bind () +FGViewMgr::bind() +{ + // 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, @@ -270,10 +195,18 @@ FGViewMgr::bind () &FGViewMgr::getGoalViewPitchOffset_deg, &FGViewMgr::setGoalViewPitchOffset_deg); fgSetArchivable("/sim/current-view/goal-pitch-offset-deg"); - - fgTie("/sim/current-view/view-number", this, + fgTie("/sim/current-view/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); + fgSetArchivable("/sim/current-view/goal-roll-offset-deg"); + + fgTie("/sim/current-view/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); @@ -287,10 +220,50 @@ FGViewMgr::bind () &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); + fgSetArchivable("/sim/current-view/field-of-view"); + fgTie("/sim/current-view/ground-level-nearplane-m", this, &FGViewMgr::getNear_m, &FGViewMgr::setNear_m); fgSetArchivable("/sim/current-view/ground-level-nearplane-m"); + 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 } void @@ -302,55 +275,43 @@ FGViewMgr::unbind () 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/field-of-view"); + 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_iterator it; + for (it = tied_props.begin(); it != tied_props.end(); it++){ + fgUntie(*it); + } + } void FGViewMgr::update (double dt) { - char stridx [20]; - string viewpath, nodepath; + + FGViewer *loop_view = (FGViewer *)get_current_view(); + if (loop_view == 0) return; + + SGPropertyNode *n = config_list[current]; double lon_deg, lat_deg, alt_ft, roll_deg, pitch_deg, heading_deg; - FGViewer * view = get_current_view(); - if (view == 0) - return; + // Set up view location and orientation + + if (!n->getBoolValue("config/from-model")) { + lon_deg = fgGetDouble(n->getStringValue("config/eye-lon-deg-path")); + lat_deg = fgGetDouble(n->getStringValue("config/eye-lat-deg-path")); + alt_ft = fgGetDouble(n->getStringValue("config/eye-alt-ft-path")); + roll_deg = fgGetDouble(n->getStringValue("config/eye-roll-deg-path")); + pitch_deg = fgGetDouble(n->getStringValue("config/eye-pitch-deg-path")); + heading_deg = fgGetDouble(n->getStringValue("config/eye-heading-deg-path")); - // - int i = current; - viewpath = "/sim/view"; - sprintf(stridx, "[%d]", i); - viewpath += stridx; - - FGViewer *loop_view = (FGViewer *)get_view( i ); - - // Set up view location and orientation - - nodepath = viewpath; - nodepath += "/config/from-model"; - if (!fgGetBool(nodepath.c_str())) { - nodepath = viewpath; - nodepath += "/config/eye-lon-deg-path"; - lon_deg = fgGetDouble(fgGetString(nodepath.c_str())); - nodepath = viewpath; - nodepath += "/config/eye-lat-deg-path"; - lat_deg = fgGetDouble(fgGetString(nodepath.c_str())); - nodepath = viewpath; - nodepath += "/config/eye-alt-ft-path"; - alt_ft = fgGetDouble(fgGetString(nodepath.c_str())); - nodepath = viewpath; - nodepath += "/config/eye-roll-deg-path"; - roll_deg = fgGetDouble(fgGetString(nodepath.c_str())); - nodepath = viewpath; - nodepath += "/config/eye-pitch-deg-path"; - pitch_deg = fgGetDouble(fgGetString(nodepath.c_str())); - nodepath = viewpath; - nodepath += "/config/eye-heading-deg-path"; - heading_deg = fgGetDouble(fgGetString(nodepath.c_str())); loop_view->setPosition(lon_deg, lat_deg, alt_ft); loop_view->setOrientation(roll_deg, pitch_deg, heading_deg); } else { @@ -360,27 +321,13 @@ FGViewMgr::update (double dt) // if lookat (type 1) then get target data... if (loop_view->getType() == FG_LOOKAT) { - nodepath = viewpath; - nodepath += "/config/from-model"; - if (!fgGetBool(nodepath.c_str())) { - nodepath = viewpath; - nodepath += "/config/target-lon-deg-path"; - lon_deg = fgGetDouble(fgGetString(nodepath.c_str())); - nodepath = viewpath; - nodepath += "/config/target-lat-deg-path"; - lat_deg = fgGetDouble(fgGetString(nodepath.c_str())); - nodepath = viewpath; - nodepath += "/config/target-alt-ft-path"; - alt_ft = fgGetDouble(fgGetString(nodepath.c_str())); - nodepath = viewpath; - nodepath += "/config/target-roll-deg-path"; - roll_deg = fgGetDouble(fgGetString(nodepath.c_str())); - nodepath = viewpath; - nodepath += "/config/target-pitch-deg-path"; - pitch_deg = fgGetDouble(fgGetString(nodepath.c_str())); - nodepath = viewpath; - nodepath += "/config/target-heading-deg-path"; - heading_deg = fgGetDouble(fgGetString(nodepath.c_str())); + if (!n->getBoolValue("config/from-model")) { + lon_deg = fgGetDouble(n->getStringValue("config/target-lon-deg-path")); + lat_deg = fgGetDouble(n->getStringValue("config/target-lat-deg-path")); + alt_ft = fgGetDouble(n->getStringValue("config/target-alt-ft-path")); + roll_deg = fgGetDouble(n->getStringValue("config/target-roll-deg-path")); + pitch_deg = fgGetDouble(n->getStringValue("config/target-pitch-deg-path")); + heading_deg = fgGetDouble(n->getStringValue("config/target-heading-deg-path")); loop_view->setTargetPosition(lon_deg, lat_deg, alt_ft); loop_view->setTargetOrientation(roll_deg, pitch_deg, heading_deg); @@ -397,47 +344,55 @@ FGViewMgr::update (double dt) setViewTargetYOffset_m(fgGetDouble("/sim/current-view/target-y-offset-m")); setViewTargetZOffset_m(fgGetDouble("/sim/current-view/target-z-offset-m")); - // Update the current view + current_view_orientation = loop_view->getViewOrientation(); + current_view_or_offset = loop_view->getViewOrientationOffset(); + + // Update the current view do_axes(); - view->update(dt); + loop_view->update(dt); + 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, loop_view->getPosition() ); + smgr->set_orientation( current_view_orientation ); + + // get the model velocity + SGVec3d velocity = SGVec3d::zeros(); + if ( !stationary() ) { + velocity = globals->get_aircraft_model()->getVelocity(); + } + smgr->set_velocity( velocity ); } void FGViewMgr::copyToCurrent() { - char stridx [20]; - string viewpath, nodepath; - - int i = current; - viewpath = "/sim/view"; - sprintf(stridx, "[%d]", i); - viewpath += stridx; + if (!inited) { + return; + } + + SGPropertyNode *n = config_list[current]; + fgSetString("/sim/current-view/name", n->getStringValue("name")); + fgSetString("/sim/current-view/type", n->getStringValue("type")); // copy certain view config data for default values - nodepath = viewpath; - nodepath += "/config/default-heading-offset-deg"; fgSetDouble("/sim/current-view/config/heading-offset-deg", - fgGetDouble(nodepath.c_str())); - - nodepath = viewpath; - nodepath += "/config/pitch-offset-deg"; + n->getDoubleValue("config/default-heading-offset-deg")); fgSetDouble("/sim/current-view/config/pitch-offset-deg", - fgGetDouble(nodepath.c_str())); - - nodepath = viewpath; - nodepath += "/config/roll-offset-deg"; + n->getDoubleValue("config/pitch-offset-deg")); fgSetDouble("/sim/current-view/config/roll-offset-deg", - fgGetDouble(nodepath.c_str())); - - nodepath = viewpath; - nodepath += "/config/default-field-of-view-deg"; + n->getDoubleValue("config/roll-offset-deg")); fgSetDouble("/sim/current-view/config/default-field-of-view-deg", - fgGetDouble(nodepath.c_str())); + n->getDoubleValue("config/default-field-of-view-deg")); + fgSetBool("/sim/current-view/config/from-model", + n->getBoolValue("config/from-model")); // copy view data fgSetDouble("/sim/current-view/x-offset-m", getViewXOffset_m()); fgSetDouble("/sim/current-view/y-offset-m", getViewYOffset_m()); fgSetDouble("/sim/current-view/z-offset-m", getViewZOffset_m()); + fgSetDouble("/sim/current-view/goal-heading-offset-deg", get_current_view()->getGoalHeadingOffset_deg()); fgSetDouble("/sim/current-view/goal-pitch-offset-deg", @@ -456,9 +411,75 @@ FGViewMgr::copyToCurrent() get_current_view()->getTargetYOffset_m()); fgSetDouble("/sim/current-view/target-z-offset-m", get_current_view()->getTargetZOffset_m()); + fgSetBool("/sim/current-view/internal", + get_current_view()->getInternal()); } +void FGViewMgr::clear() +{ + views.clear(); +} +FGViewer* +FGViewMgr::get_current_view() +{ + if ( current < (int)views.size() ) { + return views[current]; + } else { + return NULL; + } +} + +const FGViewer* +FGViewMgr::get_current_view() const +{ + if ( current < (int)views.size() ) { + return views[current]; + } else { + return NULL; + } +} + + +FGViewer* +FGViewMgr::get_view( int i ) +{ + if ( i < 0 ) { i = 0; } + if ( i >= (int)views.size() ) { i = views.size() - 1; } + return views[i]; +} + +const FGViewer* +FGViewMgr::get_view( int i ) const +{ + if ( i < 0 ) { i = 0; } + if ( i >= (int)views.size() ) { i = views.size() - 1; } + return views[i]; +} + +FGViewer* +FGViewMgr::next_view() +{ + setView((current+1 < (int)views.size()) ? (current + 1) : 0); + view_number->fireValueChanged(); + return views[current]; +} + +FGViewer* +FGViewMgr::prev_view() +{ + setView((0 < current) ? (current - 1) : (views.size() - 1)); + view_number->fireValueChanged(); + return views[current]; +} + +void +FGViewMgr::add_view( FGViewer * v ) +{ + views.push_back(v); + v->init(); +} + double FGViewMgr::getViewHeadingOffset_deg () const { @@ -523,6 +544,38 @@ FGViewMgr::setGoalViewPitchOffset_deg (double tilt) view->setGoalPitchOffset_deg(tilt); } +double +FGViewMgr::getViewRollOffset_deg () const +{ + const FGViewer * view = get_current_view(); + return (view == 0 ? 0 : view->getRollOffset_deg()); +} + +void +FGViewMgr::setViewRollOffset_deg (double tilt) +{ + FGViewer * view = get_current_view(); + if (view != 0) { + view->setGoalRollOffset_deg(tilt); + view->setRollOffset_deg(tilt); + } +} + +double +FGViewMgr::getGoalViewRollOffset_deg () const +{ + const FGViewer * view = get_current_view(); + return (view == 0 ? 0 : view->getGoalRollOffset_deg()); +} + +void +FGViewMgr::setGoalViewRollOffset_deg (double tilt) +{ + FGViewer * view = get_current_view(); + if (view != 0) + view->setGoalRollOffset_deg(tilt); +} + double FGViewMgr::getViewXOffset_m () const { @@ -583,6 +636,20 @@ FGViewMgr::setViewZOffset_m (double z) } } +bool +FGViewMgr::stationary () const +{ + const FGViewer * view = get_current_view(); + if (view != 0) { + if (((FGViewer *)view)->getXOffset_m() == 0.0 && + ((FGViewer *)view)->getYOffset_m() == 0.0 && + ((FGViewer *)view)->getZOffset_m() == 0.0) + return true; + } + + return false; +} + double FGViewMgr::getViewTargetXOffset_m () const { @@ -650,20 +717,31 @@ FGViewMgr::getView () const } void -FGViewMgr::setView (int newview ) -{ - // if newview number too low wrap to last view... - if ( newview < 0 ) { - newview = (int)views.size() -1; +FGViewMgr::setView (int newview) +{ + // negative numbers -> set view with node index -newview + if (newview < 0) { + for (int i = 0; i < (int)config_list.size(); i++) { + int index = -config_list[i]->getIndex(); + if (index == newview) + newview = i; + } + if (newview < 0) + return; } + + // if newview number too low wrap to last view... + if (newview < 0) + newview = (int)views.size() - 1; + // if newview number to high wrap to zero... - if ( newview > ((int)views.size() -1) ) { + if (newview >= (int)views.size()) newview = 0; - } + // set new view - set_view( newview ); + current = newview; // copy in view data - copyToCurrent (); + copyToCurrent(); } @@ -682,6 +760,21 @@ FGViewMgr::setFOV_deg (double fov) view->set_fov(fov); } +double +FGViewMgr::getARM_deg () const +{ + const FGViewer * view = get_current_view(); + return (view == 0 ? 0 : view->get_aspect_ratio_multiplier()); +} + +void +FGViewMgr::setARM_deg (double aspect_ratio_multiplier) +{ + FGViewer * view = get_current_view(); + if (view != 0) + view->set_aspect_ratio_multiplier(aspect_ratio_multiplier); +} + double FGViewMgr::getNear_m () const { @@ -709,6 +802,101 @@ FGViewMgr::setViewAxisLat (double axis) axis_lat = axis; } +// 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(); +} + + +// 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 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 FGViewMgr::do_axes () {