_pause(false),
_tied_to_listener(false),
_velocity(SGVec3d::zeros()),
- _orientation(SGQuatd::zeros()),
- _position(SGVec3d::zeros()),
- _pos_offs(SGVec3d::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(SGVec3d::zeros()),
- _pos_offs(SGVec3d::zeros()),
- _position_geod(SGGeod())
+ _base_pos(SGVec3d::zeros()),
+ _orientation(SGQuatd::zeros())
{
_smgr->add(this, refname);
_samples.clear();
}
// Update the position and orientation information for all samples.
- if ( _changed ) {
+ if ( _changed || _smgr->has_changed() ) {
update_pos_and_orientation();
_changed = false;
}
}
}
-// 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() );
-
- if (_position != position || _pos_offs != pos_offs) {
- _position = position;
- _pos_offs = pos_offs;
-
- 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 );
- sample->set_position_offset( _pos_offs );
- }
- }
-
- // 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_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();
+ SGQuatd hlOr = SGQuatd::fromLonLat(_position_geod) * _orientation;
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 );
+ sample->set_rotation( hlOr );
}
}
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();