also recalculate the velocity in update_pos_and_orienation, so pass the north-east-down velocity directly and orientate position, orientation and velocity to OpenGL/OpenAL frames (x-right, y-up and z-back)

This commit is contained in:
ehofman
2009-11-10 14:28:28 +00:00
committed by Tim Moore
parent 59df72c4b0
commit 5b2af1f6b3
5 changed files with 26 additions and 37 deletions

View File

@@ -41,7 +41,6 @@ SGSampleGroup::SGSampleGroup () :
_pause(false),
_tied_to_listener(false),
_velocity(SGVec3d::zeros()),
_base_pos(SGVec3d::zeros()),
_orientation(SGQuatd::zeros())
{
_samples.clear();
@@ -55,7 +54,6 @@ SGSampleGroup::SGSampleGroup ( SGSoundMgr *smgr, const string &refname ) :
_pause(false),
_tied_to_listener(false),
_velocity(SGVec3d::zeros()),
_base_pos(SGVec3d::zeros()),
_orientation(SGQuatd::zeros())
{
_smgr->add(this, refname);
@@ -315,25 +313,6 @@ bool SGSampleGroup::stop( const string& 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;
@@ -351,16 +330,26 @@ void SGSampleGroup::set_volume( float 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 );
}
}

View File

@@ -189,7 +189,9 @@ public:
* 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.
@@ -197,8 +199,7 @@ public:
* @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;
}
/**
@@ -225,9 +226,8 @@ private:
float _volume;
bool _tied_to_listener;
SGVec3f _velocity;
SGVec3d _base_pos;
SGGeod _position_geod;
SGVec3d _velocity;
SGGeod _base_pos;
SGQuatd _orientation;
sample_map _samples;

View File

@@ -199,11 +199,11 @@ void SGSoundSample::update_pos_and_orientation() {
_absolute_pos = _base_pos;
if ( _relative_pos[0] || _relative_pos[1] || _relative_pos[2] ) {
_absolute_pos += _rotation.backTransform(_relative_pos);
_absolute_pos += _rotation.backTransform( _relative_pos );
}
if ( _direction[0] || _direction[1] || _direction[2] ) {
_orivec = toVec3f(_rotation.rotate(_direction) );
_orivec = toVec3f( _rotation.rotate(_direction) );
}
else
_orivec = SGVec3f::zeros();

View File

@@ -153,7 +153,7 @@ public:
SGSampleGroup *find( const string& refname, bool create = false );
/**
* Set the Geodetic position of the sound manager.
* Set the Cartesian position of the sound manager.
* @param pos OpenAL listener position
*/
void set_position( const SGVec3d& pos ) {

View File

@@ -235,9 +235,9 @@ SGXmlSound::init(SGPropertyNode *root, SGPropertyNode *node,
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);
}
//
@@ -249,9 +249,9 @@ SGXmlSound::init(SGPropertyNode *root, SGPropertyNode *node,
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);