_pause(false),
_tied_to_listener(false),
_velocity(SGVec3d::zeros()),
- _orientation(SGQuatd::zeros()),
- _position_geod(SGGeod())
+ _base_pos(SGVec3d::zeros()),
+ _orientation(SGQuatd::zeros())
{
_samples.clear();
}
_pause(false),
_tied_to_listener(false),
_velocity(SGVec3d::zeros()),
- _orientation(SGQuatd::zeros()),
- _position_geod(SGGeod())
+ _base_pos(SGVec3d::zeros()),
+ _orientation(SGQuatd::zeros())
{
_smgr->add(this, refname);
_samples.clear();
}
}
-// set the source position of all managed sounds
-void SGSampleGroup::update_pos_and_orientation() {
-
- SGVec3d position = SGVec3d::fromGeod( _position_geod );
- SGVec3d pos_offs = SGVec3d::fromGeod( _smgr->get_position_geod() );
-
- // The rotation rotating from the earth centerd frame to
- // the horizontal local frame
- SGQuatd hlOr = SGQuatd::fromLonLat(_position_geod);
-
- // Rotate the x-forward, y-right, z-down coordinate system
- // into the OpenGL camera system with x-right, y-up, z-back.
- SGQuatd q(-0.5, -0.5, 0.5, 0.5);
-
- // Compute the sounds orientation and position
- // wrt the earth centered frame - that is global coorinates
- SGQuatd sc2body = hlOr*_orientation*q;
+void SGSampleGroup::set_volume( float vol )
+{
+ _volume = vol;
+ if (_volume < 0.0) _volume = 0.0;
+ if (_volume > 1.0) _volume = 1.0;
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_position( position - pos_offs );
- sample->set_orientation( _orientation );
- sample->set_rotation( sc2body );
+ sample->set_master_volume( _volume );
}
}
-void SGSampleGroup::set_volume( float vol )
-{
- _volume = vol;
- if (_volume < 0.0) _volume = 0.0;
- if (_volume > 1.0) _volume = 1.0;
+// set the source position and orientation of all managed sounds
+void SGSampleGroup::update_pos_and_orientation() {
+
+ SGVec3d position = _base_pos - _smgr->get_position();
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_master_volume( _volume );
+ sample->set_position( position );
+ sample->set_orientation( _orientation );
}
}
if ( _tied_to_listener ) {
orientation = _smgr->get_direction();
- position = _smgr->get_position();
+ position = SGVec3d::zeros();
velocity = _smgr->get_velocity();
} else {
sample->update_pos_and_orientation();
* @param pos Base position
*/
void set_position_geod( const SGGeod& pos ) {
- _position_geod = pos; _changed = true;
+ _base_pos = SGVec3d::fromGeod( pos ); _changed = true;
}
/**
bool _tied_to_listener;
SGVec3f _velocity;
+ SGVec3d _base_pos;
SGQuatd _orientation;
- SGGeod _position_geod;
sample_map _samples;
std::vector< SGSharedPtr<SGSoundSample> > _removed_samples;
_direction(SGVec3d::zeros()),
_velocity(SGVec3f::zeros()),
_orientation(SGQuatd::zeros()),
- _rotation(SGQuatd::zeros()),
_orivec(SGVec3f::zeros()),
_base_pos(SGVec3d::zeros()),
_refname(random_string()),
_direction(SGVec3d::zeros()),
_velocity(SGVec3f::zeros()),
_orientation(SGQuatd::zeros()),
- _rotation(SGQuatd::zeros()),
_orivec(SGVec3f::zeros()),
_base_pos(SGVec3d::zeros()),
_refname(file),
_direction(SGVec3d::zeros()),
_velocity(SGVec3f::zeros()),
_orientation(SGQuatd::zeros()),
- _rotation(SGQuatd::zeros()),
_orivec(SGVec3f::zeros()),
_base_pos(SGVec3d::zeros()),
_refname(random_string()),
_direction(SGVec3d::zeros()),
_velocity(SGVec3f::zeros()),
_orientation(SGQuatd::zeros()),
- _rotation(SGQuatd::zeros()),
_orivec(SGVec3f::zeros()),
_base_pos(SGVec3d::zeros()),
_refname(random_string()),
_absolute_pos = _base_pos;
if ( _relative_pos[0] || _relative_pos[1] || _relative_pos[2] ) {
- _absolute_pos += _rotation.backTransform(_relative_pos);
+ _absolute_pos += _orientation.backTransform(_relative_pos);
}
if ( _direction[0] || _direction[1] || _direction[2] ) {
- _orivec = toVec3f( _rotation.rotate(_direction) );
+ _orivec = toVec3f( _orientation.rotate(_direction) );
}
else
_orivec = SGVec3f::zeros();
_orientation = ori; _changed = true;
}
- /**
- * Set the rotation quatgernion of this sound.
- * @param rotation Quaternion containing the rotation information
- */
- inline void set_rotation( const SGQuatd& rotation ) {
- _rotation = rotation; _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
// The position and orientation of this sound
SGQuatd _orientation; // base orientation
- SGQuatd _rotation; // rotation vector for relative offsets
SGVec3f _orivec; // orientation vector for OpenAL
SGVec3d _base_pos; // base position
_volume(0.0),
_device(NULL),
_context(NULL),
- _position_geod(SGGeod::fromDeg(0,0)),
_absolute_pos(SGVec3d::zeros()),
_velocity(SGVec3d::zeros()),
_orientation(SGQuatd::zeros()),
}
void SGSoundMgr::update_pos_and_orientation() {
- // cartesian position of the listener
- _absolute_pos = SGVec3d::fromGeod( _position_geod );
-
/**
* Description: ORIENTATION is a pair of 3-tuples representing the
* 'at' direction vector and 'up' direction of the Object in
* @param pos OpenAL listener position
*/
void set_position_geod( const SGGeod& pos ) {
- _position_geod = pos; _changed = true;
+ _absolute_pos = SGVec3d::fromGeod( pos ); _changed = true;
}
/**
* @return OpenAL listener position
*/
SGVec3d& get_position() { return _absolute_pos; }
- SGGeod& get_position_geod() { return _position_geod; }
/**
* Set the velocity vector (in meters per second) of the sound manager
ALCcontext *_context;
// Position of the listener.
- SGGeod _position_geod;
SGVec3d _absolute_pos;
// Velocity of the listener.
SGPropertyNode_ptr prop = node->getChild("position");
if ( prop != NULL ) {
offset_pos[0] = prop->getDoubleValue("y", 0.0);
- offset_pos[1] = prop->getDoubleValue("z", 0.0);
- offset_pos[2] = prop->getDoubleValue("x", 0.0);
+ offset_pos[1] = -prop->getDoubleValue("z", 0.0);
+ offset_pos[2] = -prop->getDoubleValue("x", 0.0);
}
//
prop = node->getChild("orientation");
if ( prop != NULL ) {
dir = SGVec3f(prop->getFloatValue("y", 0.0),
- prop->getFloatValue("z", 0.0),
- prop->getFloatValue("x", 0.0));
+ -prop->getFloatValue("z", 0.0),
+ -prop->getFloatValue("x", 0.0));
inner = prop->getFloatValue("inner-angle", 360.0);
outer = prop->getFloatValue("outer-angle", 360.0);
outer_gain = prop->getFloatValue("outer-gain", 0.0);