diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index d01363fbc..1824afbaf 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -1796,8 +1796,8 @@ void fgReInitSubsystems() // model or control parameters are set fgAircraftInit(); // In the future this might not be the case. - // copy viewer settings into current-view path - globals->get_viewmgr()->copyToCurrent(); + // reload offsets from config defaults + globals->get_viewmgr()->reinit(); fgInitView(); diff --git a/src/Main/viewer.cxx b/src/Main/viewer.cxx index 538afa9a3..8fbaea6d4 100644 --- a/src/Main/viewer.cxx +++ b/src/Main/viewer.cxx @@ -130,8 +130,14 @@ static void MakeVIEW_OFFSET( sgMat4 dst, // Implementation of FGViewer. //////////////////////////////////////////////////////////////////////// -// Constructor -FGViewer::FGViewer( fgViewType Type, bool from_model, int from_model_index, bool at_model, int at_model_index, double x_offset_m, double y_offset_m, double z_offset_m, double near_m ): +// Constructor... +FGViewer::FGViewer( fgViewType Type, bool from_model, int from_model_index, + bool at_model, int at_model_index, + double x_offset_m, double y_offset_m, double z_offset_m, + double heading_offset_deg, double pitch_offset_deg, + double roll_offset_deg, double fov_deg, + double target_x_offset_m, double target_y_offset_m, + double target_z_offset_m, double near_m ): _dirty(true), _lon_deg(0), _lat_deg(0), @@ -142,13 +148,7 @@ FGViewer::FGViewer( fgViewType Type, bool from_model, int from_model_index, bool _roll_deg(0), _pitch_deg(0), _heading_deg(0), - _roll_offset_deg(0), - _pitch_offset_deg(0), - _heading_offset_deg(0), - _goal_pitch_offset_deg(0.0), - _goal_heading_offset_deg(0.0), - _scaling_type(FG_SCALING_MAX), - _fov_deg(55.0) + _scaling_type(FG_SCALING_MAX) { sgdZeroVec3(_absolute_view_pos); _type = Type; @@ -159,8 +159,22 @@ FGViewer::FGViewer( fgViewType Type, bool from_model, int from_model_index, bool _x_offset_m = x_offset_m; _y_offset_m = y_offset_m; _z_offset_m = z_offset_m; + _heading_offset_deg = heading_offset_deg; + _pitch_offset_deg = pitch_offset_deg; + _roll_offset_deg = roll_offset_deg; + _goal_heading_offset_deg = heading_offset_deg; + _goal_pitch_offset_deg = pitch_offset_deg; + _goal_roll_offset_deg = roll_offset_deg; + if (fov_deg > 0) { + _fov_deg = fov_deg; + } else { + _fov_deg = 55; + } + _target_x_offset_m = target_x_offset_m; + _target_y_offset_m = target_y_offset_m; + _target_z_offset_m = target_z_offset_m; _ground_level_nearplane_m = near_m; - //a reasonable guess for init, so that the math doesn't blow up + // a reasonable guess for init, so that the math doesn't blow up } @@ -344,6 +358,27 @@ FGViewer::setZOffset_m (double z_offset_m) _z_offset_m = z_offset_m; } +void +FGViewer::setTargetXOffset_m (double target_x_offset_m) +{ + _dirty = true; + _target_x_offset_m = target_x_offset_m; +} + +void +FGViewer::setTargetYOffset_m (double target_y_offset_m) +{ + _dirty = true; + _target_y_offset_m = target_y_offset_m; +} + +void +FGViewer::setTargetZOffset_m (double target_z_offset_m) +{ + _dirty = true; + _target_z_offset_m = target_z_offset_m; +} + void FGViewer::setPositionOffsets (double x_offset_m, double y_offset_m, double z_offset_m) { @@ -447,6 +482,12 @@ FGViewer::updateFromModelLocation (FGLocation * location) sgCopyMat4(LOCAL, location->getCachedTransformMatrix()); } +void +FGViewer::updateAtModelLocation (FGLocation * location) +{ + sgCopyMat4(ATLOCAL, location->getCachedTransformMatrix()); +} + void FGViewer::recalcOurOwnLocation (FGLocation * location, double lon_deg, double lat_deg, double alt_ft, double roll_deg, double pitch_deg, double heading_deg) @@ -517,7 +558,7 @@ FGViewer::recalcLookFrom () sgSetVec4(VIEW[2], _view_up[0], _view_up[1], _view_up[2],SG_ZERO); sgSetVec4(VIEW[3], SG_ZERO, SG_ZERO, SG_ZERO,SG_ONE); - // rotate matrix to get a matrix to apply Eye Position Offsets + // rotate model or local matrix to get a matrix to apply Eye Position Offsets sgMat4 VIEW_UP; // L0 forward L1 right L2 up sgCopyVec4(VIEW_UP[0], LOCAL[1]); sgCopyVec4(VIEW_UP[1], LOCAL[2]); @@ -546,6 +587,7 @@ FGViewer::recalcLookAt () sgVec3 right; sgVec3 eye_pos, at_pos; sgVec3 position_offset; // eye position offsets (xyz) + sgVec3 target_position_offset; // target position offsets (xyz) // The position vectors originate from the view point or target location // depending on the type of view. @@ -555,7 +597,7 @@ FGViewer::recalcLookAt () // Update location data for target... if ( _at_model ) { // update or data from model location - updateFromModelLocation(_target_location); + updateAtModelLocation(_target_location); } else { // if not model then calculate our own target position... recalcOurOwnLocation( _target_location, _target_lon_deg, _target_lat_deg, _target_alt_ft, @@ -586,24 +628,33 @@ FGViewer::recalcLookAt () sgSetVec3( _view_up, LOCAL[2][0], LOCAL[2][1], LOCAL[2][2] ); sgSetVec3( right, LOCAL[1][0], LOCAL[1][1], LOCAL[1][2] ); - // Note that when in "lookat" view the "world up" vector is always applied - // to the viewer. World up is based on verticle at a given lon/lat (see - // matrix "UP" above). + // rotate model or local matrix to get a matrix to apply Eye Position Offsets + sgMat4 VIEW_UP; // L0 forward L1 right L2 up + sgCopyVec4(VIEW_UP[0], LOCAL[1]); + sgCopyVec4(VIEW_UP[1], LOCAL[2]); + sgCopyVec4(VIEW_UP[2], LOCAL[0]); + sgZeroVec4(VIEW_UP[3]); - // Orientation Offsets matrix + // get Orientation Offsets matrix MakeVIEW_OFFSET( VIEW_OFFSET, - (_heading_offset_deg -_heading_deg) * SG_DEGREES_TO_RADIANS, _world_up, + (_heading_offset_deg - 180) * SG_DEGREES_TO_RADIANS, _view_up, _pitch_offset_deg * SG_DEGREES_TO_RADIANS, right ); - - // add in the Orientation Offsets here - sgSetVec3( position_offset, _x_offset_m, _y_offset_m, _z_offset_m ); - sgXformVec3( position_offset, position_offset, UP); + // add in the position offsets + sgSetVec3( position_offset, _y_offset_m, _x_offset_m, _z_offset_m ); + sgXformVec3( position_offset, position_offset, VIEW_UP); + + // apply the Orientation offsets sgXformVec3( position_offset, position_offset, VIEW_OFFSET ); // add the Position offsets from object to the eye position sgAddVec3( eye_pos, eye_pos, position_offset ); + // add target offsets to at_position... + sgSetVec3(target_position_offset, _target_z_offset_m, _target_x_offset_m, _target_y_offset_m ); + sgXformVec3(target_position_offset, target_position_offset, ATLOCAL); + sgAddVec3( at_pos, at_pos, target_position_offset); + // Make the VIEW matrix for a "LOOKAT". sgMakeLookAtMat4( VIEW, eye_pos, at_pos, _view_up ); diff --git a/src/Main/viewer.hxx b/src/Main/viewer.hxx index c9ea6bc3f..52cb51f37 100644 --- a/src/Main/viewer.hxx +++ b/src/Main/viewer.hxx @@ -63,8 +63,12 @@ public: // Constructor FGViewer( fgViewType Type, bool from_model, int from_model_index, - bool at_model, int at_model_index, double x_offset_m, - double y_offset_m, double z_offset_m, double near_m ); + bool at_model, int at_model_index, + double x_offset_m, double y_offset_m, double z_offset_m, + double heading_offset_deg, double pitch_offset_deg, + double roll_offset_deg, double fov_deg, + double target_x_offset_m, double target_y_offset_m, + double target_z_offset_m, double near_m ); // Destructor virtual ~FGViewer( void ); @@ -126,9 +130,15 @@ public: virtual double getXOffset_m () const { return _x_offset_m; } virtual double getYOffset_m () const { return _y_offset_m; } virtual double getZOffset_m () const { return _z_offset_m; } + virtual double getTargetXOffset_m () const { return _target_x_offset_m; } + virtual double getTargetYOffset_m () const { return _target_y_offset_m; } + virtual double getTargetZOffset_m () const { return _target_z_offset_m; } virtual void setXOffset_m (double x_offset_m); virtual void setYOffset_m (double y_offset_m); virtual void setZOffset_m (double z_offset_m); + virtual void setTargetXOffset_m (double x_offset_m); + virtual void setTargetYOffset_m (double y_offset_m); + virtual void setTargetZOffset_m (double z_offset_m); virtual void setPositionOffsets (double x_offset_m, double y_offset_m, double z_offset_m); @@ -276,13 +286,21 @@ private: double _target_pitch_deg; double _target_heading_deg; - // Position offsets from center of gravity. The X axis is positive + // Position offsets from FDM origin. The X axis is positive // out the tail, Y is out the right wing, and Z is positive up. // distance in meters double _x_offset_m; double _y_offset_m; double _z_offset_m; + // Target offsets from FDM origin (for "lookat" targets) The X + // axis is positive out the tail, Y is out the right wing, and Z + // is positive up. distance in meters + double _target_x_offset_m; + double _target_y_offset_m; + double _target_z_offset_m; + + // orientation offsets from reference (_goal* are for smoothed transitions) double _roll_offset_deg; double _pitch_offset_deg; @@ -341,7 +359,7 @@ private: // sg versions of our friendly matrices sgMat4 VIEW, UP; - sgMat4 LOCAL, TRANS, LARC_TO_SSG; + sgMat4 LOCAL, ATLOCAL, TRANS, LARC_TO_SSG; // Transformation matrix for the view direction offset relative to // the AIRCRAFT matrix @@ -356,6 +374,7 @@ private: void recalcLookAt(); void copyLocationData(); void updateFromModelLocation (FGLocation * location); + void updateAtModelLocation (FGLocation * location); void recalcOurOwnLocation (FGLocation * location, double lon_deg, double lat_deg, double alt_ft, double roll_deg, double pitch_deg, double heading_deg); diff --git a/src/Main/viewmgr.cxx b/src/Main/viewmgr.cxx index aa1f99d5b..790c990c5 100644 --- a/src/Main/viewmgr.cxx +++ b/src/Main/viewmgr.cxx @@ -51,7 +51,9 @@ FGViewMgr::init () bool at_model = false; int from_model_index = 0; int at_model_index = 0; - double x_offset_m, y_offset_m, z_offset_m; + 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++) { @@ -102,6 +104,32 @@ FGViewMgr::init () 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()); + + // 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"; @@ -110,18 +138,96 @@ FGViewMgr::init () // 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, x_offset_m, y_offset_m, - z_offset_m, near_m )); + at_model, at_model_index, x_offset_m, + y_offset_m,z_offset_m, + heading_offset_deg, pitch_offset_deg, + roll_offset_deg, fov_deg, + target_x_offset_m, target_y_offset_m, + target_z_offset_m, near_m )); else add_view(new FGViewer ( FG_LOOKFROM, from_model, from_model_index, false, - 0, x_offset_m, y_offset_m, z_offset_m, near_m )); - + 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 )); } copyToCurrent(); } +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; + + 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/pitch-offset-deg", + fgGetDouble(nodepath.c_str())); + + nodepath = viewpath; + nodepath += "/config/heading-offset-deg"; + fgSetDouble("/sim/current-view/heading-offset-deg", + fgGetDouble(nodepath.c_str())); + + nodepath = viewpath; + nodepath += "/config/roll-offset-deg"; + fgSetDouble("/sim/current-view/roll-offset-deg", + fgGetDouble(nodepath.c_str())); + + nodepath = viewpath; + nodepath += "/config/default-field-of-view-deg"; + fov_deg = fgGetDouble(nodepath.c_str()); + if (fov_deg < 10.0) { + fov_deg = 55.0; + } + 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); + +} + typedef double (FGViewMgr::*double_getter)() const; void @@ -129,22 +235,33 @@ FGViewMgr::bind () { // these are bound to the current view properties fgTie("/sim/current-view/heading-offset-deg", this, - &FGViewMgr::getViewOffset_deg, &FGViewMgr::setViewOffset_deg); + &FGViewMgr::getViewHeadingOffset_deg, + &FGViewMgr::setViewHeadingOffset_deg); fgSetArchivable("/sim/current-view/heading-offset-deg"); fgTie("/sim/current-view/goal-heading-offset-deg", this, - &FGViewMgr::getGoalViewOffset_deg, &FGViewMgr::setGoalViewOffset_deg); + &FGViewMgr::getViewGoalHeadingOffset_deg, + &FGViewMgr::setViewGoalHeadingOffset_deg); fgSetArchivable("/sim/current-view/goal-heading-offset-deg"); fgTie("/sim/current-view/pitch-offset-deg", this, - &FGViewMgr::getViewTilt_deg, &FGViewMgr::setViewTilt_deg); + &FGViewMgr::getViewPitchOffset_deg, + &FGViewMgr::setViewPitchOffset_deg); fgSetArchivable("/sim/current-view/pitch-offset-deg"); fgTie("/sim/current-view/goal-pitch-offset-deg", this, - &FGViewMgr::getGoalViewTilt_deg, &FGViewMgr::setGoalViewTilt_deg); + &FGViewMgr::getGoalViewPitchOffset_deg, + &FGViewMgr::setGoalViewPitchOffset_deg); fgSetArchivable("/sim/current-view/goal-pitch-offset-deg"); + fgTie("/sim/current-view/view-number", this, + &FGViewMgr::getView, &FGViewMgr::setView); + fgSetArchivable("/sim/current-view/view-number", FALSE); + fgTie("/sim/current-view/axes/long", this, (double_getter)0, &FGViewMgr::setViewAxisLong); + fgSetArchivable("/sim/current-view/axes/long"); + fgTie("/sim/current-view/axes/lat", this, (double_getter)0, &FGViewMgr::setViewAxisLat); + fgSetArchivable("/sim/current-view/axes/lat"); fgTie("/sim/current-view/field-of-view", this, &FGViewMgr::getFOV_deg, &FGViewMgr::setFOV_deg); @@ -166,8 +283,10 @@ FGViewMgr::unbind () fgUntie("/sim/current-view/pitch-offset-deg"); fgUntie("/sim/current-view/goal-pitch-offset-deg"); fgUntie("/sim/field-of-view"); + 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"); } void @@ -187,7 +306,6 @@ FGViewMgr::update (double dt) sprintf(stridx, "[%d]", i); viewpath += stridx; - FGViewer *loop_view = (FGViewer *)get_view( i ); // Set up view location and orientation @@ -243,16 +361,21 @@ FGViewMgr::update (double dt) nodepath = viewpath; nodepath += "/config/target-heading-deg-path"; heading_deg = fgGetDouble(fgGetString(nodepath.c_str())); - + loop_view ->setTargetPosition(lon_deg, lat_deg, alt_ft); loop_view->setTargetOrientation(roll_deg, pitch_deg, heading_deg); } else { loop_view->set_dirty(); } } - setPilotXOffset_m(fgGetDouble("/sim/current-view/x-offset-m")); - setPilotYOffset_m(fgGetDouble("/sim/current-view/y-offset-m")); - setPilotZOffset_m(fgGetDouble("/sim/current-view/z-offset-m")); + + setViewXOffset_m(fgGetDouble("/sim/current-view/x-offset-m")); + setViewYOffset_m(fgGetDouble("/sim/current-view/y-offset-m")); + setViewZOffset_m(fgGetDouble("/sim/current-view/z-offset-m")); + + setViewTargetXOffset_m(fgGetDouble("/sim/current-view/target-x-offset-m")); + setViewTargetYOffset_m(fgGetDouble("/sim/current-view/target-y-offset-m")); + setViewTargetZOffset_m(fgGetDouble("/sim/current-view/target-z-offset-m")); // Update the current view do_axes(); @@ -262,21 +385,69 @@ FGViewMgr::update (double dt) void FGViewMgr::copyToCurrent() { - fgSetDouble("/sim/current-view/x-offset-m", getPilotXOffset_m()); - fgSetDouble("/sim/current-view/y-offset-m", getPilotYOffset_m()); - fgSetDouble("/sim/current-view/z-offset-m", getPilotZOffset_m()); + char stridx [20]; + string viewpath, nodepath; + + int i = current; + viewpath = "/sim/view"; + sprintf(stridx, "[%d]", i); + viewpath += stridx; + + // 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"; + fgSetDouble("/sim/current-view/config/pitch-offset-deg", + fgGetDouble(nodepath.c_str())); + + nodepath = viewpath; + nodepath += "/config/roll-offset-deg"; + fgSetDouble("/sim/current-view/config/roll-offset-deg", + fgGetDouble(nodepath.c_str())); + + nodepath = viewpath; + nodepath += "/config/default-field-of-view-deg"; + fgSetDouble("/sim/current-view/config/default-field-of-view-deg", + fgGetDouble(nodepath.c_str())); + + // 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", + get_current_view()->getGoalPitchOffset_deg()); + fgSetDouble("/sim/current-view/goal-roll-offset-deg", + get_current_view()->getRollOffset_deg()); + fgSetDouble("/sim/current-view/heading-offset-deg", + get_current_view()->getHeadingOffset_deg()); + fgSetDouble("/sim/current-view/pitch-offset-deg", + get_current_view()->getPitchOffset_deg()); + fgSetDouble("/sim/current-view/roll-offset-deg", + get_current_view()->getRollOffset_deg()); + fgSetDouble("/sim/current-view/target-x-offset-m", + get_current_view()->getTargetXOffset_m()); + fgSetDouble("/sim/current-view/target-y-offset-m", + get_current_view()->getTargetYOffset_m()); + fgSetDouble("/sim/current-view/target-z-offset-m", + get_current_view()->getTargetZOffset_m()); } double -FGViewMgr::getViewOffset_deg () const +FGViewMgr::getViewHeadingOffset_deg () const { const FGViewer * view = get_current_view(); return (view == 0 ? 0 : view->getHeadingOffset_deg()); } void -FGViewMgr::setViewOffset_deg (double offset) +FGViewMgr::setViewHeadingOffset_deg (double offset) { FGViewer * view = get_current_view(); if (view != 0) { @@ -286,14 +457,14 @@ FGViewMgr::setViewOffset_deg (double offset) } double -FGViewMgr::getGoalViewOffset_deg () const +FGViewMgr::getViewGoalHeadingOffset_deg () const { const FGViewer * view = get_current_view(); return (view == 0 ? 0 : view->getGoalHeadingOffset_deg()); } void -FGViewMgr::setGoalViewOffset_deg (double offset) +FGViewMgr::setViewGoalHeadingOffset_deg (double offset) { FGViewer * view = get_current_view(); if (view != 0) @@ -301,14 +472,14 @@ FGViewMgr::setGoalViewOffset_deg (double offset) } double -FGViewMgr::getViewTilt_deg () const +FGViewMgr::getViewPitchOffset_deg () const { const FGViewer * view = get_current_view(); return (view == 0 ? 0 : view->getPitchOffset_deg()); } void -FGViewMgr::setViewTilt_deg (double tilt) +FGViewMgr::setViewPitchOffset_deg (double tilt) { FGViewer * view = get_current_view(); if (view != 0) { @@ -318,14 +489,14 @@ FGViewMgr::setViewTilt_deg (double tilt) } double -FGViewMgr::getGoalViewTilt_deg () const +FGViewMgr::getGoalViewPitchOffset_deg () const { const FGViewer * view = get_current_view(); return (view == 0 ? 0 : view->getGoalPitchOffset_deg()); } void -FGViewMgr::setGoalViewTilt_deg (double tilt) +FGViewMgr::setGoalViewPitchOffset_deg (double tilt) { FGViewer * view = get_current_view(); if (view != 0) @@ -333,7 +504,7 @@ FGViewMgr::setGoalViewTilt_deg (double tilt) } double -FGViewMgr::getPilotXOffset_m () const +FGViewMgr::getViewXOffset_m () const { const FGViewer * view = get_current_view(); if (view != 0) { @@ -344,7 +515,7 @@ FGViewMgr::getPilotXOffset_m () const } void -FGViewMgr::setPilotXOffset_m (double x) +FGViewMgr::setViewXOffset_m (double x) { FGViewer * view = get_current_view(); if (view != 0) { @@ -353,7 +524,7 @@ FGViewMgr::setPilotXOffset_m (double x) } double -FGViewMgr::getPilotYOffset_m () const +FGViewMgr::getViewYOffset_m () const { const FGViewer * view = get_current_view(); if (view != 0) { @@ -364,7 +535,7 @@ FGViewMgr::getPilotYOffset_m () const } void -FGViewMgr::setPilotYOffset_m (double y) +FGViewMgr::setViewYOffset_m (double y) { FGViewer * view = get_current_view(); if (view != 0) { @@ -373,7 +544,7 @@ FGViewMgr::setPilotYOffset_m (double y) } double -FGViewMgr::getPilotZOffset_m () const +FGViewMgr::getViewZOffset_m () const { const FGViewer * view = get_current_view(); if (view != 0) { @@ -384,7 +555,7 @@ FGViewMgr::getPilotZOffset_m () const } void -FGViewMgr::setPilotZOffset_m (double z) +FGViewMgr::setViewZOffset_m (double z) { FGViewer * view = get_current_view(); if (view != 0) { @@ -392,6 +563,85 @@ FGViewMgr::setPilotZOffset_m (double z) } } +double +FGViewMgr::getViewTargetXOffset_m () const +{ + const FGViewer * view = get_current_view(); + if (view != 0) { + return ((FGViewer *)view)->getTargetXOffset_m(); + } else { + return 0; + } +} + +void +FGViewMgr::setViewTargetXOffset_m (double x) +{ + FGViewer * view = get_current_view(); + if (view != 0) { + view->setTargetXOffset_m(x); + } +} + +double +FGViewMgr::getViewTargetYOffset_m () const +{ + const FGViewer * view = get_current_view(); + if (view != 0) { + return ((FGViewer *)view)->getTargetYOffset_m(); + } else { + return 0; + } +} + +void +FGViewMgr::setViewTargetYOffset_m (double y) +{ + FGViewer * view = get_current_view(); + if (view != 0) { + view->setTargetYOffset_m(y); + } +} + +double +FGViewMgr::getViewTargetZOffset_m () const +{ + const FGViewer * view = get_current_view(); + if (view != 0) { + return ((FGViewer *)view)->getTargetZOffset_m(); + } else { + return 0; + } +} + +void +FGViewMgr::setViewTargetZOffset_m (double z) +{ + FGViewer * view = get_current_view(); + if (view != 0) { + view->setTargetZOffset_m(z); + } +} + +int +FGViewMgr::getView () const +{ + return ( current ); +} + +void +FGViewMgr::setView (int newview ) +{ + if ( newview < 0 || newview > (int)views.size() ) { + newview = 0; + } + // set new view + set_view( newview ); + // copy in view data + copyToCurrent (); +} + + double FGViewMgr::getFOV_deg () const { diff --git a/src/Main/viewmgr.hxx b/src/Main/viewmgr.hxx index 9cccf8c5f..f5812db12 100644 --- a/src/Main/viewmgr.hxx +++ b/src/Main/viewmgr.hxx @@ -60,6 +60,7 @@ public: virtual void bind (); virtual void unbind (); virtual void update (double dt); + virtual void reinit (); // getters inline int size() const { return views.size(); } @@ -121,26 +122,35 @@ private: void do_axes (); - double getViewOffset_deg () const; - void setViewOffset_deg (double offset); - double getGoalViewOffset_deg () const; - void setGoalViewOffset_deg (double offset); - double getViewTilt_deg () const; - void setViewTilt_deg (double tilt); - double getGoalViewTilt_deg () const; - void setGoalViewTilt_deg (double tilt); - double getPilotXOffset_m () const; - void setPilotXOffset_m (double x); - double getPilotYOffset_m () const; - void setPilotYOffset_m (double y); - double getPilotZOffset_m () const; - void setPilotZOffset_m (double z); + // callbacks in manager to access viewer methods + double getViewHeadingOffset_deg () const; + void setViewHeadingOffset_deg (double offset); + double getViewGoalHeadingOffset_deg () const; + void setViewGoalHeadingOffset_deg (double offset); + double getViewPitchOffset_deg () const; + void setViewPitchOffset_deg (double tilt); + double getGoalViewPitchOffset_deg () const; + void setGoalViewPitchOffset_deg (double tilt); + double getViewXOffset_m () const; + void setViewXOffset_m (double x); + double getViewYOffset_m () const; + void setViewYOffset_m (double y); + double getViewZOffset_m () const; + void setViewZOffset_m (double z); + double getViewTargetXOffset_m () const; + void setViewTargetXOffset_m (double x); + double getViewTargetYOffset_m () const; + void setViewTargetYOffset_m (double y); + double getViewTargetZOffset_m () const; + void setViewTargetZOffset_m (double z); double getFOV_deg () const; void setFOV_deg (double fov); double getNear_m () const; void setNear_m (double near_m); void setViewAxisLong (double axis); void setViewAxisLat (double axis); + int getView () const; + void setView (int newview); typedef vector < FGViewer * > viewer_list; viewer_list views;