#include <stdlib.h> // rand(), free()
#include <cstring>
+#include <stdio.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/structure/exception.hxx>
_playing(false),
_static_changed(true),
_out_of_range(false),
- _is_file(false)
+ _is_file(false),
+ _use_pos_props(false)
{
+ _pos_prop[0] = 0;
+ _pos_prop[1] = 0;
+ _pos_prop[2] = 0;
}
// constructor
_playing(false),
_static_changed(true),
_out_of_range(false),
- _is_file(true)
+ _is_file(true),
+ _use_pos_props(false)
{
SGPath p = simgear::ResourceManager::instance()->findPath(file, currentDir);
_refname = p.str();
+ _pos_prop[0] = 0;
+ _pos_prop[1] = 0;
+ _pos_prop[2] = 0;
}
// constructor
_playing(false),
_static_changed(true),
_out_of_range(false),
- _is_file(false)
+ _is_file(false),
+ _use_pos_props(false)
{
SG_LOG( SG_SOUND, SG_DEBUG, "In memory sounds sample" );
_data = (unsigned char*)*data; *data = NULL;
+ _pos_prop[0] = 0;
+ _pos_prop[1] = 0;
+ _pos_prop[2] = 0;
}
// constructor
_playing(false),
_static_changed(true),
_out_of_range(false),
- _is_file(false)
+ _is_file(false),
+ _use_pos_props(false)
{
SG_LOG( SG_SOUND, SG_DEBUG, "In memory sounds sample" );
_data = (unsigned char*)*data; *data = NULL;
+ _pos_prop[0] = 0;
+ _pos_prop[1] = 0;
+ _pos_prop[2] = 0;
}
void SGSoundSample::update_pos_and_orientation() {
- _absolute_pos = _base_pos;
- if (_relative_pos[0] || _relative_pos[1] || _relative_pos[2] ) {
- _absolute_pos += _rotation.rotate( _relative_pos );
+ if (_use_pos_props) {
+ if (_pos_prop[0]) _absolute_pos[0] = _pos_prop[0]->getDoubleValue();
+ if (_pos_prop[1]) _absolute_pos[1] = _pos_prop[1]->getDoubleValue();
+ if (_pos_prop[2]) _absolute_pos[2] = _pos_prop[2]->getDoubleValue();
+ }
+ else {
+ _absolute_pos = _base_pos;
+ if (_relative_pos[0] || _relative_pos[1] || _relative_pos[2] ) {
+ _absolute_pos += _rotation.rotate( _relative_pos );
+ }
}
_orivec = SGVec3f::zeros();
#include <simgear/structure/SGReferenced.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
#include <simgear/math/SGMath.hxx>
+#include <simgear/props/props.hxx>
class SGPath;
* @param pos position in Cartesian coordinates
*/
inline void set_position( const SGVec3d& pos ) {
- _base_pos = pos; _changed = true;
+ _base_pos = pos; _changed = true;
+ }
+
+ inline void set_position_properties(SGPropertyNode_ptr pos[3]) {
+ _pos_prop[0] = pos[0]; _pos_prop[1] = pos[1]; _pos_prop[2] = pos[2];
+ if (pos[0] || pos[1] || pos[2]) _use_pos_props = true;
+ _changed = true;
}
/**
private:
// Position of the source sound.
+ SGPropertyNode_ptr _pos_prop[3]; // always absolute
SGVec3d _absolute_pos; // absolute position
SGVec3d _relative_pos; // position relative to the base position
SGVec3d _direction; // orientation offset
bool _static_changed;
bool _out_of_range;
bool _is_file;
+ bool _use_pos_props;
std::string random_string();
};
#include <simgear/compiler.h>
#include <string.h>
+#include <stdio.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/props/props.hxx>
//
SGVec3f offset_pos = SGVec3f::zeros();
SGPropertyNode_ptr prop = node->getChild("position");
+ SGPropertyNode_ptr pos_prop[3];
if ( prop != NULL ) {
offset_pos[0] = -prop->getDoubleValue("x", 0.0);
offset_pos[1] = -prop->getDoubleValue("y", 0.0);
offset_pos[2] = -prop->getDoubleValue("z", 0.0);
+
+ pos_prop[0] = prop->getChild("x");
+ if (pos_prop[0]) pos_prop[0] = pos_prop[0]->getNode("property");
+ if (pos_prop[0]) {
+ pos_prop[0] = root->getNode(pos_prop[0]->getStringValue(), true);
+ }
+ pos_prop[1] = prop->getChild("y");
+ if (pos_prop[1]) pos_prop[1] = pos_prop[1]->getNode("property");
+ if (pos_prop[1]) {
+ pos_prop[1] = root->getNode(pos_prop[1]->getStringValue(), true);
+ }
+ pos_prop[2] = prop->getChild("z");
+ if (pos_prop[2]) pos_prop[2] = pos_prop[1]->getNode("property");
+ if (pos_prop[2]) {
+ pos_prop[2] = root->getNode(pos_prop[2]->getStringValue(), true);
+ }
}
//
_sample = new SGSoundSample(soundFileStr.c_str(), path);
if (!_sample->file_path().exists()) {
throw sg_io_exception("XML sound: couldn't find file: '" + soundFileStr + "'");
+ return;
}
_sample->set_relative_position( offset_pos );
+ _sample->set_position_properties( pos_prop );
_sample->set_direction( dir );
_sample->set_audio_cone( inner, outer, outer_gain );
_sample->set_reference_dist( reference_dist );