fix directional sound orientation

This commit is contained in:
ehofman
2009-11-03 11:42:32 +00:00
committed by Tim Moore
parent 346a22f684
commit 8d551c2664
4 changed files with 16 additions and 2 deletions

View File

@@ -352,6 +352,7 @@ void SGSampleGroup::set_volume( float vol )
void SGSampleGroup::update_pos_and_orientation() {
SGVec3d position = _base_pos - _smgr->get_position();
SGQuatd hlOr = SGQuatd::fromLonLat(_position_geod) * _orientation;
sample_map_iterator sample_current = _samples.begin();
sample_map_iterator sample_end = _samples.end();
@@ -359,6 +360,7 @@ void SGSampleGroup::update_pos_and_orientation() {
SGSoundSample *sample = sample_current->second;
sample->set_position( position );
sample->set_orientation( _orientation );
sample->set_rotation( hlOr );
}
}

View File

@@ -197,6 +197,7 @@ public:
* @param pos Base position
*/
void set_position_geod( const SGGeod& pos ) {
_position_geod = pos;
_base_pos = SGVec3d::fromGeod( pos ); _changed = true;
}
@@ -226,6 +227,7 @@ private:
SGVec3f _velocity;
SGVec3d _base_pos;
SGGeod _position_geod;
SGQuatd _orientation;
sample_map _samples;

View File

@@ -50,6 +50,7 @@ SGSoundSample::SGSoundSample() :
_orientation(SGQuatd::zeros()),
_orivec(SGVec3f::zeros()),
_base_pos(SGVec3d::zeros()),
_rotation(SGQuatd::zeros()),
_refname(random_string()),
_data(NULL),
_format(AL_FORMAT_MONO8),
@@ -84,6 +85,7 @@ SGSoundSample::SGSoundSample( const char *path, const char *file ) :
_orientation(SGQuatd::zeros()),
_orivec(SGVec3f::zeros()),
_base_pos(SGVec3d::zeros()),
_rotation(SGQuatd::zeros()),
_refname(file),
_data(NULL),
_format(AL_FORMAT_MONO8),
@@ -124,6 +126,7 @@ SGSoundSample::SGSoundSample( const unsigned char** data,
_orientation(SGQuatd::zeros()),
_orivec(SGVec3f::zeros()),
_base_pos(SGVec3d::zeros()),
_rotation(SGQuatd::zeros()),
_refname(random_string()),
_format(format),
_size(len),
@@ -159,6 +162,7 @@ SGSoundSample::SGSoundSample( void** data, int len, int freq, int format ) :
_orientation(SGQuatd::zeros()),
_orivec(SGVec3f::zeros()),
_base_pos(SGVec3d::zeros()),
_rotation(SGQuatd::zeros()),
_refname(random_string()),
_format(format),
_size(len),
@@ -195,11 +199,11 @@ void SGSoundSample::update_pos_and_orientation() {
_absolute_pos = _base_pos;
if ( _relative_pos[0] || _relative_pos[1] || _relative_pos[2] ) {
_absolute_pos += _orientation.backTransform(_relative_pos);
_absolute_pos += _rotation.backTransform(_relative_pos);
}
if ( _direction[0] || _direction[1] || _direction[2] ) {
_orivec = toVec3f( _orientation.rotate(_direction) );
_orivec = toVec3f(_rotation.rotate(_direction) );
}
else
_orivec = SGVec3f::zeros();

View File

@@ -337,6 +337,10 @@ public:
_orientation = ori; _changed = true;
}
inline void set_rotation( const SGQuatd& ori ) {
_rotation = ori; _changed = true;
}
/**
* Set direction of this sound relative to the orientation.
* This is in the same coordinate system as OpenGL; y=up, z=back, x=right
@@ -454,6 +458,8 @@ private:
SGVec3f _orivec; // orientation vector for OpenAL
SGVec3d _base_pos; // base position
SGQuatd _rotation;
std::string _refname; // name or file path
unsigned char* _data;