From: ehofman Date: Sun, 11 Oct 2009 13:40:12 +0000 (+0000) Subject: Correct (and verrified) position, orientation and velocity vector. Todo: proper sound... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b582c118bd6bba58a32d75d2d8ef45b612b231d3;p=flightgear.git Correct (and verrified) position, orientation and velocity vector. Todo: proper sound orientation (the all face forward using the airplane orientation now) and disabling doppler effect when tied to the listener --- diff --git a/src/Main/viewmgr.cxx b/src/Main/viewmgr.cxx index d429c219c..18b16a6a2 100644 --- a/src/Main/viewmgr.cxx +++ b/src/Main/viewmgr.cxx @@ -248,7 +248,6 @@ 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 @@ -265,10 +264,6 @@ 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... @@ -303,8 +298,15 @@ FGViewMgr::update (double dt) // update audio listener values // set the viewer posotion in Cartesian coordinates in meters - smgr->set_position(abs_viewer_position); + smgr->set_position(-abs_viewer_position); smgr->set_orientation(loop_view->getViewOrientation()); + + // get the model velocity for the in-cockpit view + SGVec3f velocity = SGVec3f(0,0,0); + if ( !stationary() ) { + FGAircraftModel *aircraft = globals->get_aircraft_model(); + velocity = aircraft->getVelocity(); + } smgr->set_velocity(velocity); } @@ -575,6 +577,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 { diff --git a/src/Main/viewmgr.hxx b/src/Main/viewmgr.hxx index 76ede702e..2c0feb428 100644 --- a/src/Main/viewmgr.hxx +++ b/src/Main/viewmgr.hxx @@ -116,6 +116,7 @@ private: void setViewAxisLat (double axis); int getView () const; void setView (int newview); + bool stationary () const; SGPropertyNode_ptr view_number; vector config_list; diff --git a/src/Model/acmodel.cxx b/src/Model/acmodel.cxx index 0541a1159..ff2c81aa0 100644 --- a/src/Model/acmodel.cxx +++ b/src/Model/acmodel.cxx @@ -44,8 +44,7 @@ FGAircraftModel::FGAircraftModel () _pitch(0), _roll(0), _heading(0), - _speed(0), - _speed_up(0) + _speed(0) { SGSoundMgr *smgr; smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr"); @@ -92,8 +91,7 @@ FGAircraftModel::bind () _pitch = fgGetNode("orientation/pitch-deg", true); _roll = fgGetNode("orientation/roll-deg", true); _heading = fgGetNode("orientation/heading-deg", true); - _speed = fgGetNode("velocities/true-airspeed-kt", true); - _speed_up = fgGetNode("velocities/vertical-speed-fps", true); + _speed = fgGetNode("velocities/groundspeed-kt", true); } void @@ -125,21 +123,19 @@ FGAircraftModel::update (double dt) // update model's audio sample values // Get the Cartesian coordinates in meters SGVec3d pos = SGVec3d::fromGeod(_aircraft->getPosition()); - _fx->set_position( pos ); + _fx->set_position( -pos ); SGQuatd orient_m = SGQuatd::fromLonLat(_aircraft->getPosition()); orient_m *= SGQuatd::fromYawPitchRollDeg(_heading->getDoubleValue(), _pitch->getDoubleValue(), _roll->getDoubleValue()); SGVec3d orient = -orient_m.rotate(SGVec3d::e1()); - _fx->set_orientation( toVec3f(orient) ); + _fx->set_orientation( toVec3f( orient ) ); // 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; + _velocity = toVec3f(orient * _speed->getDoubleValue() * SG_KT_TO_MPS); _fx->set_velocity( _velocity ); } diff --git a/src/Model/acmodel.hxx b/src/Model/acmodel.hxx index 5a0b31a0e..dd6e3b01f 100644 --- a/src/Model/acmodel.hxx +++ b/src/Model/acmodel.hxx @@ -54,7 +54,6 @@ private: SGPropertyNode * _roll; SGPropertyNode * _heading; SGPropertyNode * _speed; - SGPropertyNode * _speed_up; }; diff --git a/src/Sound/fg_fx.cxx b/src/Sound/fg_fx.cxx index 6e06fa403..934ec5c1a 100644 --- a/src/Sound/fg_fx.cxx +++ b/src/Sound/fg_fx.cxx @@ -45,6 +45,7 @@ FGFX::FGFX ( SGSoundMgr *smgr, const string &refname ) : _volume( fgGetNode("/sim/sound/volume") ) { SGSampleGroup::_smgr = smgr; + SGSampleGroup::_refname = refname; SGSampleGroup::_smgr->add(this, refname); SGSampleGroup::_active = _smgr->is_working(); }