From 5107a9d07fe6a0e976fb7ab0d6fee4c2552e7887 Mon Sep 17 00:00:00 2001 From: ehofman Date: Tue, 6 Oct 2009 12:09:50 +0000 Subject: [PATCH] (try to) properly align model and viewer --- src/Main/viewmgr.cxx | 7 ++++++- src/Model/acmodel.cxx | 26 +++++++++++++------------- src/Model/acmodel.hxx | 5 +++-- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/Main/viewmgr.cxx b/src/Main/viewmgr.cxx index 20db9476b..d429c219c 100644 --- a/src/Main/viewmgr.cxx +++ b/src/Main/viewmgr.cxx @@ -248,6 +248,7 @@ FGViewMgr::update (double dt) FGViewer *loop_view = (FGViewer *)get_view(current); SGPropertyNode *n = config_list[current]; double lon_deg, lat_deg, alt_ft, roll_deg, pitch_deg, heading_deg; + SGVec3f velocity = SGVec3f(0,0,0); // Set up view location and orientation @@ -264,6 +265,10 @@ FGViewMgr::update (double dt) } else { // force recalc in viewer loop_view->set_dirty(); + + // get the model velocity for the in-cockpit view + FGAircraftModel *aircraft = globals->get_aircraft_model(); + velocity = aircraft->getVelocity(); } // if lookat (type 1) then get target data... @@ -300,7 +305,7 @@ FGViewMgr::update (double dt) // set the viewer posotion in Cartesian coordinates in meters smgr->set_position(abs_viewer_position); smgr->set_orientation(loop_view->getViewOrientation()); - smgr->set_velocity(SGVec3f(0,0,0)); // TODO: in meters per second + smgr->set_velocity(velocity); } void diff --git a/src/Model/acmodel.cxx b/src/Model/acmodel.cxx index f54e4721e..0541a1159 100644 --- a/src/Model/acmodel.cxx +++ b/src/Model/acmodel.cxx @@ -36,6 +36,7 @@ FGAircraftModel::FGAircraftModel () : _aircraft(0), + _velocity(SGVec3f::zeros()), _fx(0), _lon(0), _lat(0), @@ -43,8 +44,7 @@ FGAircraftModel::FGAircraftModel () _pitch(0), _roll(0), _heading(0), - _speed_north(0), - _speed_east(0), + _speed(0), _speed_up(0) { SGSoundMgr *smgr; @@ -92,9 +92,8 @@ FGAircraftModel::bind () _pitch = fgGetNode("orientation/pitch-deg", true); _roll = fgGetNode("orientation/roll-deg", true); _heading = fgGetNode("orientation/heading-deg", true); - _speed_north = fgGetNode("/velocities/speed-north-fps", true); - _speed_east = fgGetNode("/velocities/speed-east-fps", true); - _speed_up = fgGetNode("/velocities/vertical-speed-fps", true); + _speed = fgGetNode("velocities/true-airspeed-kt", true); + _speed_up = fgGetNode("velocities/vertical-speed-fps", true); } void @@ -123,7 +122,7 @@ FGAircraftModel::update (double dt) _heading->getDoubleValue()); _aircraft->update(); - // update model's sample group values + // update model's audio sample values // Get the Cartesian coordinates in meters SGVec3d pos = SGVec3d::fromGeod(_aircraft->getPosition()); _fx->set_position( pos ); @@ -132,15 +131,16 @@ FGAircraftModel::update (double dt) orient_m *= SGQuatd::fromYawPitchRollDeg(_heading->getDoubleValue(), _pitch->getDoubleValue(), _roll->getDoubleValue()); - SGVec3d orient = orient_m.rotateBack(SGVec3d::e1()); + SGVec3d orient = -orient_m.rotate(SGVec3d::e1()); _fx->set_orientation( toVec3f(orient) ); - SGVec3f vel = SGVec3f( _speed_north->getFloatValue(), - _speed_east->getFloatValue(), - _speed_up->getFloatValue()); -// TODO: rotate to properly align with the model orientation - - _fx->set_velocity( vel*SG_FEET_TO_METER ); + // For now assume the aircraft speed is always along the longitudinal + // axis, so sideslipping is not taken into account. This should be fine + // for audio. + _velocity = toVec3f(orient * _speed->getDoubleValue() * SG_KT_TO_FPS); + // _velocity[2] = _speed_up->getFloatValue(); + _velocity *= SG_FEET_TO_METER; + _fx->set_velocity( _velocity ); } diff --git a/src/Model/acmodel.hxx b/src/Model/acmodel.hxx index da728fcf6..5a0b31a0e 100644 --- a/src/Model/acmodel.hxx +++ b/src/Model/acmodel.hxx @@ -39,10 +39,12 @@ public: virtual void unbind (); virtual void update (double dt); virtual SGModelPlacement * get3DModel() { return _aircraft; } + virtual SGVec3f getVelocity() { return _velocity; } private: SGModelPlacement * _aircraft; + SGVec3f _velocity; FGFX * _fx; SGPropertyNode * _lon; @@ -51,8 +53,7 @@ private: SGPropertyNode * _pitch; SGPropertyNode * _roll; SGPropertyNode * _heading; - SGPropertyNode * _speed_north; - SGPropertyNode * _speed_east; + SGPropertyNode * _speed; SGPropertyNode * _speed_up; }; -- 2.39.5