Expose some of the positional components of the OpenAL API.
This commit is contained in:
@@ -129,6 +129,10 @@ SGSoundSample::SGSoundSample( const char *path, const char *file,
|
||||
alSourcefv( source, AL_POSITION, source_pos );
|
||||
alSourcefv( source, AL_VELOCITY, source_vel );
|
||||
alSourcei( source, AL_LOOPING, loop );
|
||||
|
||||
alSourcei( source, AL_SOURCE_RELATIVE, AL_TRUE );
|
||||
alSourcef( source, AL_REFERENCE_DISTANCE, 250.0f );
|
||||
alSourcef( source, AL_MAX_DISTANCE, 2000.0f );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -189,6 +189,27 @@ public:
|
||||
inline char *get_data() {
|
||||
return (char *)data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set position of sound source (uses same coordinate system as opengl)
|
||||
*/
|
||||
inline void set_source_pos( ALfloat *pos ) {
|
||||
source_pos[0] = pos[0];
|
||||
source_pos[1] = pos[1];
|
||||
source_pos[2] = pos[2];
|
||||
alSourcefv( source, AL_POSITION, source_pos );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set velocity of sound source (uses same coordinate system as opengl)
|
||||
*/
|
||||
inline void set_source_vel( ALfloat *vel ) {
|
||||
source_vel[0] = vel[0];
|
||||
source_vel[1] = vel[1];
|
||||
source_vel[2] = vel[2];
|
||||
alSourcefv( source, AL_VELOCITY, source_vel );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -83,6 +83,9 @@ SGSoundMgr::SGSoundMgr() {
|
||||
SG_LOG( SG_GENERAL, SG_ALERT,
|
||||
"Oops AL error after audio initialization!" );
|
||||
}
|
||||
|
||||
// exaggerate the ear candy?
|
||||
alDopplerFactor(1.0);
|
||||
}
|
||||
|
||||
// destructor
|
||||
@@ -267,3 +270,25 @@ bool SGSoundMgr::stop( const string& refname ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// set source position of all managed sounds
|
||||
void SGSoundMgr::set_source_pos_all( ALfloat *pos ) {
|
||||
sample_map_iterator sample_current = samples.begin();
|
||||
sample_map_iterator sample_end = samples.end();
|
||||
for ( ; sample_current != sample_end; ++sample_current ) {
|
||||
SGSoundSample *sample = sample_current->second;
|
||||
sample->set_source_pos( pos );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// set source velocity of all managed sounds
|
||||
void SGSoundMgr::set_source_vel_all( ALfloat *vel ) {
|
||||
sample_map_iterator sample_current = samples.begin();
|
||||
sample_map_iterator sample_end = samples.end();
|
||||
for ( ; sample_current != sample_end; ++sample_current ) {
|
||||
SGSoundSample *sample = sample_current->second;
|
||||
sample->set_source_vel( vel );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,6 +173,57 @@ public:
|
||||
* immediate stop playing the sound
|
||||
*/
|
||||
bool stop( const string& refname );
|
||||
|
||||
/**
|
||||
* set the position of the listener (in opengl coordinates)
|
||||
*/
|
||||
inline void set_listener_pos( ALfloat *pos ) {
|
||||
listener_pos[0] = pos[0];
|
||||
listener_pos[1] = pos[1];
|
||||
listener_pos[2] = pos[2];
|
||||
alListenerfv( AL_POSITION, listener_pos );
|
||||
}
|
||||
|
||||
/**
|
||||
* set the velocity of the listener (in opengl coordinates)
|
||||
*/
|
||||
inline void set_listener_vel( ALfloat *vel ) {
|
||||
listener_vel[0] = vel[0];
|
||||
listener_vel[1] = vel[1];
|
||||
listener_vel[2] = vel[2];
|
||||
alListenerfv( AL_VELOCITY, listener_vel );
|
||||
}
|
||||
|
||||
/**
|
||||
* set the orientation of the listener (in opengl coordinates)
|
||||
*
|
||||
* Description: ORIENTATION is a pair of 3-tuples representing the
|
||||
* 'at' direction vector and 'up' direction of the Object in
|
||||
* Cartesian space. AL expects two vectors that are orthogonal to
|
||||
* each other. These vectors are not expected to be normalized. If
|
||||
* one or more vectors have zero length, implementation behavior
|
||||
* is undefined. If the two vectors are linearly dependent,
|
||||
* behavior is undefined.
|
||||
*/
|
||||
inline void set_listener_orientation( ALfloat *ori ) {
|
||||
listener_ori[0] = ori[0];
|
||||
listener_ori[1] = ori[1];
|
||||
listener_ori[2] = ori[2];
|
||||
listener_ori[3] = ori[3];
|
||||
listener_ori[4] = ori[4];
|
||||
listener_ori[5] = ori[5];
|
||||
alListenerfv( AL_ORIENTATION, listener_ori );
|
||||
}
|
||||
|
||||
/**
|
||||
* set the positions of all managaged sound sources
|
||||
*/
|
||||
void set_source_pos_all( ALfloat *pos );
|
||||
|
||||
/**
|
||||
* set the velocities of all managaged sound sources
|
||||
*/
|
||||
void set_source_vel_all( ALfloat *pos );
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user