Remove more unneeded code and properly set relative position and sound direction
This commit is contained in:
@@ -41,8 +41,8 @@ SGSampleGroup::SGSampleGroup () :
|
||||
_pause(false),
|
||||
_tied_to_listener(false),
|
||||
_velocity(SGVec3d::zeros()),
|
||||
_orientation(SGQuatd::zeros()),
|
||||
_position_geod(SGGeod())
|
||||
_base_pos(SGVec3d::zeros()),
|
||||
_orientation(SGQuatd::zeros())
|
||||
{
|
||||
_samples.clear();
|
||||
}
|
||||
@@ -55,8 +55,8 @@ SGSampleGroup::SGSampleGroup ( SGSoundMgr *smgr, const string &refname ) :
|
||||
_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();
|
||||
@@ -334,34 +334,6 @@ void SGSampleGroup::set_velocity( const SGVec3f &vel ) {
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
void SGSampleGroup::set_volume( float vol )
|
||||
{
|
||||
_volume = vol;
|
||||
@@ -376,13 +348,27 @@ 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();
|
||||
|
||||
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_orientation( _orientation );
|
||||
}
|
||||
}
|
||||
|
||||
void SGSampleGroup::update_sample_config( SGSoundSample *sample ) {
|
||||
SGVec3f orientation, velocity;
|
||||
SGVec3d position;
|
||||
|
||||
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();
|
||||
|
||||
@@ -197,7 +197,7 @@ public:
|
||||
* @param pos Base position
|
||||
*/
|
||||
void set_position_geod( const SGGeod& pos ) {
|
||||
_position_geod = pos; _changed = true;
|
||||
_base_pos = SGVec3d::fromGeod( pos ); _changed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -225,8 +225,8 @@ private:
|
||||
bool _tied_to_listener;
|
||||
|
||||
SGVec3f _velocity;
|
||||
SGVec3d _base_pos;
|
||||
SGQuatd _orientation;
|
||||
SGGeod _position_geod;
|
||||
|
||||
sample_map _samples;
|
||||
std::vector< SGSharedPtr<SGSoundSample> > _removed_samples;
|
||||
|
||||
@@ -48,7 +48,6 @@ SGSoundSample::SGSoundSample() :
|
||||
_direction(SGVec3d::zeros()),
|
||||
_velocity(SGVec3f::zeros()),
|
||||
_orientation(SGQuatd::zeros()),
|
||||
_rotation(SGQuatd::zeros()),
|
||||
_orivec(SGVec3f::zeros()),
|
||||
_base_pos(SGVec3d::zeros()),
|
||||
_refname(random_string()),
|
||||
@@ -83,7 +82,6 @@ SGSoundSample::SGSoundSample( const char *path, const char *file ) :
|
||||
_direction(SGVec3d::zeros()),
|
||||
_velocity(SGVec3f::zeros()),
|
||||
_orientation(SGQuatd::zeros()),
|
||||
_rotation(SGQuatd::zeros()),
|
||||
_orivec(SGVec3f::zeros()),
|
||||
_base_pos(SGVec3d::zeros()),
|
||||
_refname(file),
|
||||
@@ -124,7 +122,6 @@ SGSoundSample::SGSoundSample( const unsigned char** data,
|
||||
_direction(SGVec3d::zeros()),
|
||||
_velocity(SGVec3f::zeros()),
|
||||
_orientation(SGQuatd::zeros()),
|
||||
_rotation(SGQuatd::zeros()),
|
||||
_orivec(SGVec3f::zeros()),
|
||||
_base_pos(SGVec3d::zeros()),
|
||||
_refname(random_string()),
|
||||
@@ -160,7 +157,6 @@ SGSoundSample::SGSoundSample( void** data, int len, int freq, int format ) :
|
||||
_direction(SGVec3d::zeros()),
|
||||
_velocity(SGVec3f::zeros()),
|
||||
_orientation(SGQuatd::zeros()),
|
||||
_rotation(SGQuatd::zeros()),
|
||||
_orivec(SGVec3f::zeros()),
|
||||
_base_pos(SGVec3d::zeros()),
|
||||
_refname(random_string()),
|
||||
@@ -199,11 +195,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 += _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();
|
||||
|
||||
@@ -337,14 +337,6 @@ public:
|
||||
_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
|
||||
@@ -461,7 +453,6 @@ private:
|
||||
|
||||
// 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
|
||||
|
||||
|
||||
@@ -63,7 +63,6 @@ SGSoundMgr::SGSoundMgr() :
|
||||
_volume(0.0),
|
||||
_device(NULL),
|
||||
_context(NULL),
|
||||
_position_geod(SGGeod::fromDeg(0,0)),
|
||||
_absolute_pos(SGVec3d::zeros()),
|
||||
_velocity(SGVec3d::zeros()),
|
||||
_orientation(SGQuatd::zeros()),
|
||||
@@ -462,9 +461,6 @@ void SGSoundMgr::release_buffer(SGSoundSample *sample)
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -157,7 +157,7 @@ public:
|
||||
* @param pos OpenAL listener position
|
||||
*/
|
||||
void set_position_geod( const SGGeod& pos ) {
|
||||
_position_geod = pos; _changed = true;
|
||||
_absolute_pos = SGVec3d::fromGeod( pos ); _changed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,7 +166,6 @@ public:
|
||||
* @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
|
||||
@@ -281,7 +280,6 @@ private:
|
||||
ALCcontext *_context;
|
||||
|
||||
// Position of the listener.
|
||||
SGGeod _position_geod;
|
||||
SGVec3d _absolute_pos;
|
||||
|
||||
// Velocity of the listener.
|
||||
|
||||
@@ -230,8 +230,8 @@ SGXmlSound::init(SGPropertyNode *root, SGPropertyNode *node,
|
||||
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);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -244,8 +244,8 @@ SGXmlSound::init(SGPropertyNode *root, SGPropertyNode *node,
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user