From 6ccad915373fe367f8d63eb69282146054d0a401 Mon Sep 17 00:00:00 2001 From: ehofman Date: Sun, 1 Nov 2009 14:51:10 +0000 Subject: [PATCH] proper orientation(?) and comment out relative position and direction code since it messes with OpenAL in such a way that volume doesn't work properly anymore --- simgear/sound/sample_openal.cxx | 14 ++++++++------ simgear/sound/sample_openal.hxx | 5 ++--- simgear/sound/soundmgr_openal.cxx | 11 ++++++++--- simgear/sound/xmlsound.cxx | 6 +++--- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/simgear/sound/sample_openal.cxx b/simgear/sound/sample_openal.cxx index 7e06a64e..4be9d811 100644 --- a/simgear/sound/sample_openal.cxx +++ b/simgear/sound/sample_openal.cxx @@ -46,7 +46,7 @@ SGSoundSample::SGSoundSample() : _absolute_pos(SGVec3d::zeros()), _relative_pos(SGVec3d::zeros()), _direction(SGVec3d::zeros()), - _velocity(SGVec3d::zeros()), + _velocity(SGVec3f::zeros()), _orientation(SGQuatd::zeros()), _orivec(SGVec3f::zeros()), _base_pos(SGGeod::fromDeg(0,0)), @@ -80,7 +80,7 @@ SGSoundSample::SGSoundSample( const char *path, const char *file ) : _absolute_pos(SGVec3d::zeros()), _relative_pos(SGVec3d::zeros()), _direction(SGVec3d::zeros()), - _velocity(SGVec3d::zeros()), + _velocity(SGVec3f::zeros()), _orientation(SGQuatd::zeros()), _orivec(SGVec3f::zeros()), _base_pos(SGGeod::fromDeg(0,0)), @@ -120,7 +120,7 @@ SGSoundSample::SGSoundSample( const unsigned char** data, _absolute_pos(SGVec3d::zeros()), _relative_pos(SGVec3d::zeros()), _direction(SGVec3d::zeros()), - _velocity(SGVec3d::zeros()), + _velocity(SGVec3f::zeros()), _orientation(SGQuatd::zeros()), _orivec(SGVec3f::zeros()), _base_pos(SGGeod::fromDeg(0,0)), @@ -155,7 +155,7 @@ SGSoundSample::SGSoundSample( void** data, int len, int freq, int format ) : _absolute_pos(SGVec3d::zeros()), _relative_pos(SGVec3d::zeros()), _direction(SGVec3d::zeros()), - _velocity(SGVec3d::zeros()), + _velocity(SGVec3f::zeros()), _orientation(SGQuatd::zeros()), _orivec(SGVec3f::zeros()), _base_pos(SGGeod::fromDeg(0,0)), @@ -204,15 +204,17 @@ void SGSoundSample::update_pos_and_orientation() { // simulation runs into the OpenGL camera system with x-right, y-up, z-back. SGQuatd q(-0.5, -0.5, 0.5, 0.5); - // The cartesian position of the base sound coordinate + // The cartesian position of the sounds base location SGVec3d position = SGVec3d::fromGeod(_base_pos); _absolute_pos = position; +#if 0 if ( _relative_pos[0] || _relative_pos[1] || _relative_pos[2] ) { _absolute_pos += (sc2body*q).backTransform(_relative_pos); } +#endif if ( _direction[0] || _direction[1] || _direction[2] ) { - _orivec = toVec3f((sc2body*q).backTransform(toVec3d(_direction))); + _orivec = toVec3f( (sc2body*q).backTransform(_direction) ); } } diff --git a/simgear/sound/sample_openal.hxx b/simgear/sound/sample_openal.hxx index d419d767..8f310233 100644 --- a/simgear/sound/sample_openal.hxx +++ b/simgear/sound/sample_openal.hxx @@ -336,7 +336,7 @@ public: * @param dir Sound emission direction */ inline void set_direction( const SGVec3f& dir ) { - _direction = dir; _changed = true; + _direction = toVec3d(dir); _changed = true; } /** @@ -359,7 +359,6 @@ public: * @return Orientaton vector */ SGVec3f& get_orientation() { return _orivec; } - SGVec3f& get_direction() { return _direction; } /** * Get the inner angle of the audio cone. @@ -442,7 +441,7 @@ private: // Position of the source sound. SGVec3d _absolute_pos; // absolute position SGVec3d _relative_pos; // position relative to the base position - SGVec3f _direction; // orientation offset + SGVec3d _direction; // orientation offset SGVec3f _velocity; // Velocity of the source sound. // The position and orientation of this sound diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index c01f144f..b6177948 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -477,7 +477,12 @@ void SGSoundMgr::update_pos_and_orientation() { // simulation runs into the OpenGL camera system with x-right, y-up, z-back. SGQuatd q(-0.5, -0.5, 0.5, 0.5); - _absolute_pos = position + (lc2body*q).backTransform( _position_offs ); + _absolute_pos = position; +#if 0 + if (_position_offs[0] || _position_offs[1] || _position_offs[2] ) { + _absolute_pos += (lc2body*q).backTransform( _position_offs ); + } +#endif /** * Description: ORIENTATION is a pair of 3-tuples representing the @@ -489,8 +494,8 @@ void SGSoundMgr::update_pos_and_orientation() { * behavior is undefined. * This is in the same coordinate system as OpenGL; y=up, z=back, x=right. */ - SGQuatd lViewOrientation = lc2body*_orient_offs*q; - SGVec3d sgv_up = lViewOrientation.rotate(SGVec3d::e2()); + SGQuatd lViewOrientation = hlOr*_orient_offs*q; + SGVec3d sgv_up = -lViewOrientation.rotate(SGVec3d::e2()); SGVec3d sgv_at = lViewOrientation.rotate(SGVec3d::e3()); _at_up_vec[0] = sgv_at[0]; _at_up_vec[1] = sgv_at[1]; diff --git a/simgear/sound/xmlsound.cxx b/simgear/sound/xmlsound.cxx index 04b8e060..29bf06b5 100644 --- a/simgear/sound/xmlsound.cxx +++ b/simgear/sound/xmlsound.cxx @@ -229,9 +229,9 @@ SGXmlSound::init(SGPropertyNode *root, SGPropertyNode *node, SGVec3f offset_pos = SGVec3f::zeros(); SGPropertyNode_ptr prop = node->getChild("position"); if ( prop != NULL ) { - offset_pos[0] = prop->getDoubleValue("x", 0.0); - offset_pos[1] = -prop->getDoubleValue("y", 0.0); - offset_pos[2] = prop->getDoubleValue("z", 0.0); + offset_pos[0] = prop->getDoubleValue("y", 0.0); + offset_pos[1] = prop->getDoubleValue("z", 0.0); + offset_pos[2] = prop->getDoubleValue("x", 0.0); } // -- 2.39.5