#include "soundmgr_openal.hxx"
#include "sample_group.hxx"
+bool isNaN(float *v) {
+ return (isnan(v[0]) || isnan(v[1]) || isnan(v[2]));
+}
+
SGSampleGroup::SGSampleGroup () :
_smgr(NULL),
_refname(""),
if ( sample->is_valid_source() ) {
unsigned int source = sample->get_source();
- if ( _tied_to_listener && _smgr->has_changed() ) {
- alSourcefv( source, AL_POSITION, _smgr->get_position().data() );
- alSourcefv( source, AL_VELOCITY, _smgr->get_velocity().data() );
- alSourcefv( source, AL_DIRECTION, _smgr->get_direction().data() );
+ float *position, *orientation, *velocity;
+ if ( _tied_to_listener ) {
+ position = _smgr->get_position().data();
+ orientation = _smgr->get_velocity().data();
+ velocity = _smgr->get_direction().data();
} else {
- alSourcefv( source, AL_POSITION, sample->get_position() );
- alSourcefv( source, AL_VELOCITY, sample->get_velocity() );
- alSourcefv( source, AL_DIRECTION, sample->get_orientation() );
+ sample->update_absolute_position();
+ position = sample->get_position();
+ orientation = sample->get_velocity();
+ velocity = sample->get_orientation();
}
+ if (dist(_smgr->get_position(), sample->get_position_vec()) > 50000)
+ printf("source and listener distance greater than 50km!\n");
+ if (isNaN(position)) printf("NaN in source position\n");
+ if (isNaN(orientation)) printf("NaN in source orientation\n");
+ if (isNaN(velocity)) printf("NaN in source velocity\n");
+
+ alSourcefv( source, AL_POSITION, position );
+ alSourcefv( source, AL_VELOCITY, velocity );
+ alSourcefv( source, AL_DIRECTION, orientation );
testForALError("position and orientation");
alSourcef( source, AL_PITCH, sample->get_pitch() );
_data = NULL;
}
-void SGSoundSample::set_orientation( const SGQuatd& ori ) {
- _orientation = ori;
- update_absolute_position();
- _changed = true;
-}
-
-void SGSoundSample::set_direction( const SGVec3d& dir ) {
- _direction = dir;
- update_absolute_position();
- _changed = true;
-}
-
-void SGSoundSample::set_relative_position( const SGVec3f& pos ) {
- _relative_pos = toVec3d(pos);
- update_absolute_position();
- _changed = true;
-}
-
-void SGSoundSample::set_position( const SGGeod& pos ) {
- _base_pos = pos;
- update_absolute_position();
- _changed = true;
-}
-
void SGSoundSample::update_absolute_position() {
- // SGQuatd orient = SGQuatd::fromLonLat(_base_pos) * _orientation;
- // _orivec = -toVec3f(orient.rotate(-SGVec3d::e1()));
-
// The rotation rotating from the earth centerd frame to
// the horizontal local frame
SGQuatd hlOr = SGQuatd::fromLonLat(_base_pos);
- // Compute the eyepoints orientation and position
+ // Compute the sounds orientation and position
// wrt the earth centered frame - that is global coorinates
- SGQuatd ec2body = hlOr*_orientation;
+ SGQuatd sc2body = _orientation*hlOr;
// This is rotates the x-forward, y-right, z-down coordinate system where
// simulation runs into the OpenGL camera system with x-right, y-up, z-back.
SGQuatd q(-0.5, -0.5, 0.5, 0.5);
- // The cartesian position of the basic view coordinate
+ // The cartesian position of the base sound coordinate
SGVec3d position = SGVec3d::fromGeod(_base_pos);
- _absolute_pos = position + (ec2body*q).backTransform(_relative_pos);
- _orivec = toVec3f( (ec2body*q).backTransform(_direction) );
+ _absolute_pos = position + (sc2body*q).backTransform(_relative_pos);
+ _orivec = toVec3f( (sc2body*q).backTransform(_direction) );
}
string SGSoundSample::random_string() {
return rstr;
}
+
* This is in the same coordinate system as OpenGL; y=up, z=back, x=right.
* @param pos Relative position of this sound
*/
- void set_relative_position( const SGVec3f& pos );
+ inline void set_relative_position( const SGVec3f& pos ) {
+ _relative_pos = toVec3d(pos); _changed = true;
+ }
/**
* Set the base position of this sound in Geodetic coordinates.
* @param pos Geodetic position
*/
- void set_position( const SGGeod& pos );
+ inline void set_position( const SGGeod& pos ) {
+ _base_pos = pos; _changed = true;
+ }
/**
* Get the absolute position of this sound.
* @return Absolute position
*/
float *get_position() const { return toVec3f(_absolute_pos).data(); }
+ SGVec3f get_position_vec() const { return toVec3f(_absolute_pos); }
/**
* Set the orientation of this sound.
* @param ori Quaternation containing the orientation information
*/
- void set_orientation( const SGQuatd& ori );
+ inline void set_orientation( const SGQuatd& ori ) {
+ _orientation = 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
* @param dir Sound emission direction
*/
- void set_direction( const SGVec3d& dir );
+ inline void set_direction( const SGVec3d& dir ) {
+ _direction = dir; _changed = true;
+ }
/**
* Define the audio cone parameters for directional audio.
*/
inline std::string get_sample_name() const { return _refname; }
+ void update_absolute_position();
+
private:
// Position of the source sound.
bool _static_changed;
bool _is_file;
- void update_absolute_position();
string random_string();
};