From 7c693d81076bef2b6e028179774256ab8393d707 Mon Sep 17 00:00:00 2001 From: ehofman Date: Mon, 23 Nov 2009 09:35:12 +0000 Subject: [PATCH] proper listener velocity calculation, this has no effect yet but is required when other models start emitting sounds. --- simgear/sound/sample_group.cxx | 3 ++- simgear/sound/soundmgr_openal.cxx | 9 ++++++++- simgear/sound/soundmgr_openal.hxx | 11 ++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/simgear/sound/sample_group.cxx b/simgear/sound/sample_group.cxx index f3846631..9f486413 100644 --- a/simgear/sound/sample_group.cxx +++ b/simgear/sound/sample_group.cxx @@ -361,7 +361,8 @@ void SGSampleGroup::update_sample_config( SGSoundSample *sample ) { #if 0 if (length(position) > 20000) - printf("source and listener distance greater than 20km!\n"); + printf("%s source and listener distance greater than 20km!\n", + _refname.c_str()); if (isNaN(toVec3f(position).data())) printf("NaN in source position\n"); if (isNaN(orientation.data())) printf("NaN in source orientation\n"); if (isNaN(velocity.data())) printf("NaN in source velocity\n"); diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index 6066a560..ebd3a4b4 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -66,6 +66,7 @@ SGSoundMgr::SGSoundMgr() : _absolute_pos(SGVec3d::zeros()), _offset_pos(SGVec3d::zeros()), _base_pos(SGVec3d::zeros()), + _geod_pos(SGGeod::fromCart(SGVec3d::zeros())), _velocity(SGVec3d::zeros()), _orientation(SGQuatd::zeros()), _devname(NULL) @@ -264,7 +265,13 @@ if (isNaN(_velocity.data())) printf("NaN in listener velocity\n"); alListenerf( AL_GAIN, _volume ); alListenerfv( AL_ORIENTATION, _at_up_vec ); // alListenerfv( AL_POSITION, toVec3f(_absolute_pos).data() ); - alListenerfv( AL_VELOCITY, _velocity.data() ); + + SGQuatd hlOr = SGQuatd::fromLonLat( _geod_pos ); + SGVec3d velocity = SGVec3d::zeros(); + if ( _velocity[0] || _velocity[1] || _velocity[2] ) { + velocity = hlOr.backTransform(_velocity*SG_FEET_TO_METER); + } + alListenerfv( AL_VELOCITY, toVec3f(velocity).data() ); // alDopplerVelocity(340.3); // TODO: altitude dependent testForALError("update"); _changed = false; diff --git a/simgear/sound/soundmgr_openal.hxx b/simgear/sound/soundmgr_openal.hxx index ecfd2637..f3163018 100644 --- a/simgear/sound/soundmgr_openal.hxx +++ b/simgear/sound/soundmgr_openal.hxx @@ -156,8 +156,8 @@ public: * Set the Cartesian position of the sound manager. * @param pos OpenAL listener position */ - void set_position( const SGVec3d& pos ) { - _base_pos = pos; _changed = true; + void set_position( const SGVec3d& pos, const SGGeod& pos_geod ) { + _base_pos = pos; _geod_pos = pos_geod; _changed = true; } void set_position_offset( const SGVec3d& pos ) { @@ -176,7 +176,7 @@ public: * This is the horizontal local frame; x=north, y=east, z=down * @param Velocity vector */ - void set_velocity( const SGVec3f& vel ) { + void set_velocity( const SGVec3d& vel ) { _velocity = vel; _changed = true; } @@ -185,7 +185,7 @@ public: * This is in the same coordinate system as OpenGL; y=up, z=back, x=right. * @return Velocity vector of the OpenAL listener */ - inline SGVec3f& get_velocity() { return _velocity; } + inline SGVec3f get_velocity() { return toVec3f(_velocity); } /** * Set the orientation of the sound manager @@ -287,9 +287,10 @@ private: SGVec3d _absolute_pos; SGVec3d _offset_pos; SGVec3d _base_pos; + SGGeod _geod_pos; // Velocity of the listener. - SGVec3f _velocity; + SGVec3d _velocity; // Orientation of the listener. // first 3 elements are "at" vector, second 3 are "up" vector -- 2.39.5