1
0
Fork 0

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

This commit is contained in:
ehofman 2009-10-11 13:40:12 +00:00 committed by Tim Moore
parent 33e816abb9
commit b582c118bd
5 changed files with 29 additions and 16 deletions

View file

@ -248,7 +248,6 @@ FGViewMgr::update (double dt)
FGViewer *loop_view = (FGViewer *)get_view(current); FGViewer *loop_view = (FGViewer *)get_view(current);
SGPropertyNode *n = config_list[current]; SGPropertyNode *n = config_list[current];
double lon_deg, lat_deg, alt_ft, roll_deg, pitch_deg, heading_deg; 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 // Set up view location and orientation
@ -265,10 +264,6 @@ FGViewMgr::update (double dt)
} else { } else {
// force recalc in viewer // force recalc in viewer
loop_view->set_dirty(); 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... // if lookat (type 1) then get target data...
@ -303,8 +298,15 @@ FGViewMgr::update (double dt)
// update audio listener values // update audio listener values
// set the viewer posotion in Cartesian coordinates in meters // 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()); 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); 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 double
FGViewMgr::getViewTargetXOffset_m () const FGViewMgr::getViewTargetXOffset_m () const
{ {

View file

@ -116,6 +116,7 @@ private:
void setViewAxisLat (double axis); void setViewAxisLat (double axis);
int getView () const; int getView () const;
void setView (int newview); void setView (int newview);
bool stationary () const;
SGPropertyNode_ptr view_number; SGPropertyNode_ptr view_number;
vector<SGPropertyNode_ptr> config_list; vector<SGPropertyNode_ptr> config_list;

View file

@ -44,8 +44,7 @@ FGAircraftModel::FGAircraftModel ()
_pitch(0), _pitch(0),
_roll(0), _roll(0),
_heading(0), _heading(0),
_speed(0), _speed(0)
_speed_up(0)
{ {
SGSoundMgr *smgr; SGSoundMgr *smgr;
smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr"); smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
@ -92,8 +91,7 @@ FGAircraftModel::bind ()
_pitch = fgGetNode("orientation/pitch-deg", true); _pitch = fgGetNode("orientation/pitch-deg", true);
_roll = fgGetNode("orientation/roll-deg", true); _roll = fgGetNode("orientation/roll-deg", true);
_heading = fgGetNode("orientation/heading-deg", true); _heading = fgGetNode("orientation/heading-deg", true);
_speed = fgGetNode("velocities/true-airspeed-kt", true); _speed = fgGetNode("velocities/groundspeed-kt", true);
_speed_up = fgGetNode("velocities/vertical-speed-fps", true);
} }
void void
@ -125,21 +123,19 @@ FGAircraftModel::update (double dt)
// update model's audio sample values // update model's audio sample values
// Get the Cartesian coordinates in meters // Get the Cartesian coordinates in meters
SGVec3d pos = SGVec3d::fromGeod(_aircraft->getPosition()); SGVec3d pos = SGVec3d::fromGeod(_aircraft->getPosition());
_fx->set_position( pos ); _fx->set_position( -pos );
SGQuatd orient_m = SGQuatd::fromLonLat(_aircraft->getPosition()); SGQuatd orient_m = SGQuatd::fromLonLat(_aircraft->getPosition());
orient_m *= SGQuatd::fromYawPitchRollDeg(_heading->getDoubleValue(), orient_m *= SGQuatd::fromYawPitchRollDeg(_heading->getDoubleValue(),
_pitch->getDoubleValue(), _pitch->getDoubleValue(),
_roll->getDoubleValue()); _roll->getDoubleValue());
SGVec3d orient = -orient_m.rotate(SGVec3d::e1()); 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 // For now assume the aircraft speed is always along the longitudinal
// axis, so sideslipping is not taken into account. This should be fine // axis, so sideslipping is not taken into account. This should be fine
// for audio. // for audio.
_velocity = toVec3f(orient * _speed->getDoubleValue() * SG_KT_TO_FPS); _velocity = toVec3f(orient * _speed->getDoubleValue() * SG_KT_TO_MPS);
// _velocity[2] = _speed_up->getFloatValue();
_velocity *= SG_FEET_TO_METER;
_fx->set_velocity( _velocity ); _fx->set_velocity( _velocity );
} }

View file

@ -54,7 +54,6 @@ private:
SGPropertyNode * _roll; SGPropertyNode * _roll;
SGPropertyNode * _heading; SGPropertyNode * _heading;
SGPropertyNode * _speed; SGPropertyNode * _speed;
SGPropertyNode * _speed_up;
}; };

View file

@ -45,6 +45,7 @@ FGFX::FGFX ( SGSoundMgr *smgr, const string &refname ) :
_volume( fgGetNode("/sim/sound/volume") ) _volume( fgGetNode("/sim/sound/volume") )
{ {
SGSampleGroup::_smgr = smgr; SGSampleGroup::_smgr = smgr;
SGSampleGroup::_refname = refname;
SGSampleGroup::_smgr->add(this, refname); SGSampleGroup::_smgr->add(this, refname);
SGSampleGroup::_active = _smgr->is_working(); SGSampleGroup::_active = _smgr->is_working();
} }