SG_LOG( SG_GENERAL, SG_DEBUG, "From file sounds sample = "
<< samplepath.str() );
- ALuint error;
-
- source_pos[0] = 0.0; source_pos[1] = 0.0; source_pos[2] = 0.0;
+ source_pos[0] = 0.0; source_pos[1] = 0.0; source_pos[2] = 0.0;
+ offset_pos[0] = 0.0; offset_pos[1] = 0.0; offset_pos[2] = 0.0;
source_vel[0] = 0.0; source_vel[1] = 0.0; source_vel[2] = 0.0;
// clear errors from elsewhere?
// create an OpenAL buffer handle
alGenBuffers(1, &buffer);
- error = alGetError();
+ ALuint error = alGetError();
if ( error != AL_NO_ERROR ) {
print_openal_error( error );
throw sg_exception("Failed to gen OpenAL buffer.");
sample_name = "unknown, generated from data";
source_pos[0] = 0.0; source_pos[1] = 0.0; source_pos[2] = 0.0;
+ offset_pos[0] = 0.0; offset_pos[1] = 0.0; offset_pos[2] = 0.0;
source_vel[0] = 0.0; source_vel[1] = 0.0; source_vel[2] = 0.0;
+ // clear errors from elsewhere?
+ alGetError();
+
// Load wav data into a buffer.
alGenBuffers(1, &buffer);
- if (alGetError() != AL_NO_ERROR) {
+ ALuint error = alGetError();
+ if ( error != AL_NO_ERROR ) {
+ print_openal_error( error );
throw sg_exception("Failed to gen buffer." );
return;
}
# include <AL/alut.h>
#endif
+#include <plib/sg.h>
+
#include <simgear/debug/logstream.hxx>
SG_USING_STD(string);
// Position of the source sound.
ALfloat source_pos[3];
+ // A constant offset to be applied to the final source_pos
+ ALfloat offset_pos[3];
+
// Velocity of the source sound.
ALfloat source_vel[3];
double max_dist;
ALboolean loop;
+
public:
/**
source_pos[0] = pos[0];
source_pos[1] = pos[1];
source_pos[2] = pos[2];
- alSourcefv( source, AL_POSITION, source_pos );
+
+ sgVec3 final_pos;
+ sgAddVec3( final_pos, source_pos, offset_pos );
+
+ alSourcefv( source, AL_POSITION, final_pos );
+ }
+
+ /**
+ * Set "constant" offset position of sound source (uses same
+ * coordinate system as opengl)
+ */
+ inline void set_offset_pos( ALfloat *pos ) {
+ offset_pos[0] = pos[0];
+ offset_pos[1] = pos[1];
+ offset_pos[2] = pos[2];
+
+ sgVec3 final_pos;
+ sgAddVec3( final_pos, source_pos, offset_pos );
+
+ alSourcefv( source, AL_POSITION, final_pos );
}
/**
p += pitch.offset;
}
+ //
+ // Relative position
+ //
+ sgVec3 offset_pos;
+ sgSetVec3( offset_pos, 0.0, 0.0, 0.0 );
+ SGPropertyNode_ptr pos = node->getChild("position");
+ if ( pos != NULL ) {
+ offset_pos[0] = pos->getDoubleValue("x", 0.0);
+ offset_pos[1] = pos->getDoubleValue("y", 0.0);
+ offset_pos[2] = pos->getDoubleValue("z", 0.0);
+ }
+
//
// Initialize the sample
//
_mgr->add( _sample, _name );
}
+ _sample->set_offset_pos( offset_pos );
_sample->set_volume(v);
_sample->set_reference_dist( reference_dist );
_sample->set_max_dist( max_dist );