_pause(false),
_tied_to_listener(false),
_velocity(SGVec3d::zeros()),
- _base_pos(SGVec3d::zeros()),
_orientation(SGQuatd::zeros())
{
_samples.clear();
_pause(false),
_tied_to_listener(false),
_velocity(SGVec3d::zeros()),
- _base_pos(SGVec3d::zeros()),
_orientation(SGQuatd::zeros())
{
_smgr->add(this, refname);
return true;
}
-// set source velocity of all managed sounds
-void SGSampleGroup::set_velocity( const SGVec3f &vel ) {
- if ( isnan(vel[0]) || isnan(vel[1]) || isnan(vel[2]) )
- {
- SG_LOG( SG_GENERAL, SG_ALERT, "NAN's found in SampleGroup velocity");
- return;
- }
-
- if (_velocity != 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_velocity( vel );
- }
- _velocity = vel;
- }
-}
-
void SGSampleGroup::set_volume( float vol )
{
_volume = vol;
// 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;
+ static const SGQuatd q(-0.5, -0.5, 0.5, 0.5);
+
+ SGVec3d position = SGVec3d::fromGeod(_base_pos) - _smgr->get_position();
+
+ SGQuatd hlOr = SGQuatd::fromLonLat(_base_pos);
+ SGQuatd ec2gl = hlOr*_orientation*q;
+
+ SGVec3f velocity = SGVec3f::zeros();
+ if ( _velocity[0] || _velocity[1] || _velocity[2] ) {
+ velocity = toVec3f( (hlOr*q).backTransform(_velocity) );
+ }
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_velocity( velocity );
sample->set_orientation( _orientation );
- sample->set_rotation( hlOr );
+ sample->set_rotation( ec2gl );
}
}
* This is in the local frame coordinate system; x=north, y=east, z=down
* @param vel Velocity vector
*/
- void set_velocity( const SGVec3f& vel );
+ void set_velocity( const SGVec3d& vel ) {
+ _velocity = vel; _changed = true;
+ }
/**
* Set the position of this sample group.
* @param pos Base position
*/
void set_position_geod( const SGGeod& pos ) {
- _position_geod = pos;
- _base_pos = SGVec3d::fromGeod( pos ); _changed = true;
+ _base_pos = pos; _changed = true;
}
/**
float _volume;
bool _tied_to_listener;
- SGVec3f _velocity;
- SGVec3d _base_pos;
- SGGeod _position_geod;
+ SGVec3d _velocity;
+ SGGeod _base_pos;
SGQuatd _orientation;
sample_map _samples;
SGVec3f offset_pos = SGVec3f::zeros();
SGPropertyNode_ptr prop = node->getChild("position");
if ( prop != NULL ) {
- offset_pos[0] = -prop->getDoubleValue("x", 0.0);
+ offset_pos[0] = prop->getDoubleValue("z", 0.0);
offset_pos[1] = prop->getDoubleValue("y", 0.0);
- offset_pos[2] = -prop->getDoubleValue("z", 0.0);
+ offset_pos[2] = prop->getDoubleValue("x", 0.0);
}
//
float outer_gain = 0.0;
prop = node->getChild("orientation");
if ( prop != NULL ) {
- dir = SGVec3f(-prop->getFloatValue("x", 0.0),
+ dir = SGVec3f(prop->getFloatValue("z", 0.0),
prop->getFloatValue("y", 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);