Alut < 1.0 fixes and finaly fix the sound orientation

This commit is contained in:
ehofman
2009-10-17 13:39:33 +02:00
committed by Tim Moore
parent a67688322d
commit fdfdfedf01
5 changed files with 22 additions and 21 deletions
+3 -3
View File
@@ -306,7 +306,7 @@ void SGSampleGroup::set_velocity( SGVec3d &vel ) {
} }
} }
// ste the source orientation of all managed sounds // set the source position of all managed sounds
void SGSampleGroup::set_position( SGGeod pos ) { void SGSampleGroup::set_position( SGGeod pos ) {
sample_map_iterator sample_current = _samples.begin(); sample_map_iterator sample_current = _samples.begin();
@@ -319,7 +319,7 @@ void SGSampleGroup::set_position( SGGeod pos ) {
} }
// ste the source orientation of all managed sounds // set the source orientation of all managed sounds
void SGSampleGroup::set_orientation( SGQuatd ori ) { void SGSampleGroup::set_orientation( SGQuatd ori ) {
if (_orientation != ori) { if (_orientation != ori) {
@@ -356,7 +356,7 @@ void SGSampleGroup::update_sample_config( SGSoundSample *sample ) {
alSourcefv( source, AL_DIRECTION, _smgr->get_direction().data() ); alSourcefv( source, AL_DIRECTION, _smgr->get_direction().data() );
alSourcefv( source, AL_VELOCITY, _smgr->get_velocity().data() ); alSourcefv( source, AL_VELOCITY, _smgr->get_velocity().data() );
} else { } else {
alSourcefv( source, AL_POSITION, sample->get_position()); alSourcefv( source, AL_POSITION, sample->get_position() );
alSourcefv( source, AL_DIRECTION, sample->get_orientation() ); alSourcefv( source, AL_DIRECTION, sample->get_orientation() );
alSourcefv( source, AL_VELOCITY, sample->get_velocity() ); alSourcefv( source, AL_VELOCITY, sample->get_velocity() );
} }
+2 -2
View File
@@ -153,9 +153,9 @@ public:
*/ */
void set_orientation( SGQuatd ori ); void set_orientation( SGQuatd ori );
inline void tie_to_listener() { _tied_to_listener = true; } void tie_to_listener() { _tied_to_listener = true; }
inline void activate() { _active = true; } void activate() { _active = true; }
protected: protected:
SGSoundMgr *_smgr; SGSoundMgr *_smgr;
+9 -9
View File
@@ -66,7 +66,8 @@ SGSoundSample::SGSoundSample() :
_playing(false), _playing(false),
_changed(true), _changed(true),
_static_changed(true), _static_changed(true),
_is_file(false) _is_file(false),
_orivec(SGVec3f::zeros())
{ {
} }
@@ -97,7 +98,8 @@ SGSoundSample::SGSoundSample( const char *path, const char *file ) :
_playing(false), _playing(false),
_changed(true), _changed(true),
_static_changed(true), _static_changed(true),
_is_file(true) _is_file(true),
_orivec(SGVec3f::zeros())
{ {
SGPath samplepath( path ); SGPath samplepath( path );
if ( strlen(file) ) { if ( strlen(file) ) {
@@ -137,7 +139,8 @@ SGSoundSample::SGSoundSample( unsigned char *data, int len, int freq, int format
_playing(false), _playing(false),
_changed(true), _changed(true),
_static_changed(true), _static_changed(true),
_is_file(false) _is_file(false),
_orivec(SGVec3f::zeros())
{ {
_sample_name = "unknown, data supplied by caller"; _sample_name = "unknown, data supplied by caller";
SG_LOG( SG_GENERAL, SG_DEBUG, "In memory sounds sample" ); SG_LOG( SG_GENERAL, SG_DEBUG, "In memory sounds sample" );
@@ -160,12 +163,6 @@ void SGSoundSample::set_direction( SGVec3d dir ) {
_changed = true; _changed = true;
} }
float *SGSoundSample::get_orientation() {
SGQuatd orient = SGQuatd::fromLonLat(_base_pos) * _orientation;
SGVec3d orivec = -orient.rotate(_direction);
return toVec3f(orivec).data();
}
void SGSoundSample::set_relative_position( SGVec3f pos ) { void SGSoundSample::set_relative_position( SGVec3f pos ) {
_relative_pos = pos; _relative_pos = pos;
update_absolute_position(); update_absolute_position();
@@ -179,6 +176,9 @@ void SGSoundSample::set_position( SGGeod pos ) {
} }
void SGSoundSample::update_absolute_position() { void SGSoundSample::update_absolute_position() {
SGQuatd orient = SGQuatd::fromLonLat(_base_pos) * _orientation;
_orivec = -toVec3f(orient.rotate(_direction));
_absolute_pos = -SGVec3d::fromGeod(_base_pos); _absolute_pos = -SGVec3d::fromGeod(_base_pos);
// TODO: add relative position // TODO: add relative position
} }
+5 -5
View File
@@ -93,6 +93,7 @@ private:
bool _static_changed; bool _static_changed;
bool _is_file; bool _is_file;
SGVec3f _orivec;
void update_absolute_position(); void update_absolute_position();
public: public:
@@ -359,11 +360,10 @@ public:
* Get the orientation of the sound source, the inner or outer angle * Get the orientation of the sound source, the inner or outer angle
* or outer gain. * or outer gain.
*/ */
float *get_orientation(); float *get_orientation() { return _orivec.data(); }
float get_innerangle() { return _inner_angle; }
inline float get_innerangle() { return _inner_angle; } float get_outerangle() { return _outer_angle; }
inline float get_outerangle() { return _outer_angle; } float get_outergain() { return _outer_gain; }
inline float get_outergain() { return _outer_gain; }
/** /**
* Set velocity of the sound source (uses same coordinate system as opengl) * Set velocity of the sound source (uses same coordinate system as opengl)
+3 -2
View File
@@ -274,6 +274,7 @@ bool SGSoundMgr::add( SGSampleGroup *sgrp, const string& refname )
return false; return false;
} }
if (_working) sgrp->activate();
_sample_groups[refname] = sgrp; _sample_groups[refname] = sgrp;
return true; return true;
@@ -502,8 +503,8 @@ bool SGSoundMgr::load(string &samplepath, void **dbuf, int *fmt,
ALboolean loop; ALboolean loop;
alutLoadWAVFile( fname, &format, &data, &size, &freq, &loop ); alutLoadWAVFile( fname, &format, &data, &size, &freq, &loop );
# endif # endif
ALenum error = alutGetError(); ALenum error = alGetError();
if ( error != ALUT_ERROR_NO_ERROR ) { if ( error != AL_NO_ERROR ) {
string msg = "Failed to load wav file: "; string msg = "Failed to load wav file: ";
msg.append(alutGetErrorString(error)); msg.append(alutGetErrorString(error));
throw sg_io_exception(msg.c_str(), sg_location(samplepath)); throw sg_io_exception(msg.c_str(), sg_location(samplepath));