Alut < 1.0 fixes and finaly fix the sound orientation

This commit is contained in:
ehofman
2009-10-16 09:45:00 +00:00
committed by Tim Moore
parent a67688322d
commit fdfdfedf01
5 changed files with 22 additions and 21 deletions

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 ) {
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 ) {
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_VELOCITY, _smgr->get_velocity().data() );
} 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_VELOCITY, sample->get_velocity() );
}

View File

@@ -153,9 +153,9 @@ public:
*/
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:
SGSoundMgr *_smgr;

View File

@@ -66,7 +66,8 @@ SGSoundSample::SGSoundSample() :
_playing(false),
_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),
_changed(true),
_static_changed(true),
_is_file(true)
_is_file(true),
_orivec(SGVec3f::zeros())
{
SGPath samplepath( path );
if ( strlen(file) ) {
@@ -137,7 +139,8 @@ SGSoundSample::SGSoundSample( unsigned char *data, int len, int freq, int format
_playing(false),
_changed(true),
_static_changed(true),
_is_file(false)
_is_file(false),
_orivec(SGVec3f::zeros())
{
_sample_name = "unknown, data supplied by caller";
SG_LOG( SG_GENERAL, SG_DEBUG, "In memory sounds sample" );
@@ -160,12 +163,6 @@ void SGSoundSample::set_direction( SGVec3d dir ) {
_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 ) {
_relative_pos = pos;
update_absolute_position();
@@ -179,6 +176,9 @@ void SGSoundSample::set_position( SGGeod pos ) {
}
void SGSoundSample::update_absolute_position() {
SGQuatd orient = SGQuatd::fromLonLat(_base_pos) * _orientation;
_orivec = -toVec3f(orient.rotate(_direction));
_absolute_pos = -SGVec3d::fromGeod(_base_pos);
// TODO: add relative position
}

View File

@@ -93,6 +93,7 @@ private:
bool _static_changed;
bool _is_file;
SGVec3f _orivec;
void update_absolute_position();
public:
@@ -359,11 +360,10 @@ public:
* Get the orientation of the sound source, the inner or outer angle
* or outer gain.
*/
float *get_orientation();
inline float get_innerangle() { return _inner_angle; }
inline float get_outerangle() { return _outer_angle; }
inline float get_outergain() { return _outer_gain; }
float *get_orientation() { return _orivec.data(); }
float get_innerangle() { return _inner_angle; }
float get_outerangle() { return _outer_angle; }
float get_outergain() { return _outer_gain; }
/**
* Set velocity of the sound source (uses same coordinate system as opengl)

View File

@@ -274,6 +274,7 @@ bool SGSoundMgr::add( SGSampleGroup *sgrp, const string& refname )
return false;
}
if (_working) sgrp->activate();
_sample_groups[refname] = sgrp;
return true;
@@ -502,8 +503,8 @@ bool SGSoundMgr::load(string &samplepath, void **dbuf, int *fmt,
ALboolean loop;
alutLoadWAVFile( fname, &format, &data, &size, &freq, &loop );
# endif
ALenum error = alutGetError();
if ( error != ALUT_ERROR_NO_ERROR ) {
ALenum error = alGetError();
if ( error != AL_NO_ERROR ) {
string msg = "Failed to load wav file: ";
msg.append(alutGetErrorString(error));
throw sg_io_exception(msg.c_str(), sg_location(samplepath));