FGFX clean-ups, conversion of one more sgVec user.
This commit is contained in:
parent
05626756e7
commit
3c84e07a25
2 changed files with 39 additions and 79 deletions
|
@ -29,11 +29,14 @@
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "fg_fx.hxx"
|
||||||
|
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
#include <simgear/structure/exception.hxx>
|
#include <simgear/structure/exception.hxx>
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
#include <simgear/props/props.hxx>
|
#include <simgear/props/props.hxx>
|
||||||
#include <simgear/sound/xmlsound.hxx>
|
#include <simgear/sound/xmlsound.hxx>
|
||||||
|
#include <simgear/sound/soundmgr_openal.hxx>
|
||||||
|
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
|
|
||||||
|
@ -41,17 +44,14 @@
|
||||||
#include <Model/acmodel.hxx>
|
#include <Model/acmodel.hxx>
|
||||||
#include <Main/viewer.hxx>
|
#include <Main/viewer.hxx>
|
||||||
|
|
||||||
#include "fg_fx.hxx"
|
|
||||||
|
|
||||||
|
|
||||||
FGFX::FGFX () :
|
FGFX::FGFX () :
|
||||||
|
last_visitor_pos(SGVec3d::zeros()),
|
||||||
|
last_model_pos(SGVec3d::zeros()),
|
||||||
last_pause( true ),
|
last_pause( true ),
|
||||||
last_volume( 0.0 ),
|
last_volume( 0.0 ),
|
||||||
_pause( fgGetNode("/sim/sound/pause") ),
|
_pause( fgGetNode("/sim/sound/pause") ),
|
||||||
_volume( fgGetNode("/sim/sound/volume") )
|
_volume( fgGetNode("/sim/sound/volume") )
|
||||||
{
|
{
|
||||||
sgdSetVec3(last_visitor_pos, 0, 0, 0);
|
|
||||||
sgdSetVec3(last_model_pos, 0, 0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FGFX::~FGFX ()
|
FGFX::~FGFX ()
|
||||||
|
@ -200,7 +200,7 @@ FGFX::play_message( SGSoundSample *_sample )
|
||||||
_samplequeue.push( _sample );
|
_samplequeue.push( _sample );
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
FGFX::play_message( const string path, const string fname, double volume )
|
FGFX::play_message( const std::string& path, const std::string& fname, double volume )
|
||||||
{
|
{
|
||||||
if (globals->get_soundmgr()->is_working() == true) {
|
if (globals->get_soundmgr()->is_working() == true) {
|
||||||
SGSoundSample *sample;
|
SGSoundSample *sample;
|
||||||
|
@ -237,87 +237,50 @@ FGFX::update_pos_and_orientation(SGSoundMgr *smgr, double dt)
|
||||||
// are finally calculated in a left hand system and openal
|
// are finally calculated in a left hand system and openal
|
||||||
// lives in a right hand system. Therefore we need to pass
|
// lives in a right hand system. Therefore we need to pass
|
||||||
// the down vector to get correct stereo sound.)
|
// the down vector to get correct stereo sound.)
|
||||||
SGVec3d sgv_up, sgv_at;
|
SGVec3d sgv_up
|
||||||
sgVec3 up, at;
|
|
||||||
|
|
||||||
sgv_up
|
|
||||||
= model_or.rotateBack(surf_or.rotateBack(view_or.rotate(SGVec3d(0,1,0))));
|
= model_or.rotateBack(surf_or.rotateBack(view_or.rotate(SGVec3d(0,1,0))));
|
||||||
sgSetVec3(up, sgv_up[0], sgv_up[1], sgv_up[2]);
|
SGVec3d sgv_at
|
||||||
sgv_at
|
|
||||||
= model_or.rotateBack(surf_or.rotateBack(view_or.rotate(SGVec3d(0,0,1))));
|
= model_or.rotateBack(surf_or.rotateBack(view_or.rotate(SGVec3d(0,0,1))));
|
||||||
sgSetVec3(at, sgv_at[0], sgv_at[1], sgv_at[2]);
|
|
||||||
|
|
||||||
// get the location data for the primary FDM (now hardcoded to ac model)...
|
// get the location data for the primary FDM (now hardcoded to ac model)...
|
||||||
// EMH: to add multiple sound sources this should be replaced
|
// EMH: to add multiple sound sources this should be replaced
|
||||||
SGVec3d absolute_view_pos = SGVec3d::fromGeod(model->getPosition());
|
SGVec3d absolute_view_pos = SGVec3d::fromGeod(model->getPosition());
|
||||||
|
|
||||||
// calculate speed of visitor and model
|
// calculate speed of visitor and model
|
||||||
sgVec3 listener_vel, model_vel;
|
SGVec3d moved = last_visitor_pos - observer->get_view_pos();
|
||||||
SGVec3d SGV3d_help;
|
last_visitor_pos = observer->get_view_pos();
|
||||||
sgdVec3 sgdv3_help;
|
SGVec3f listener_vel(model_or.rotateBack(surf_or.rotateBack(moved)));
|
||||||
sgdVec3 sgdv3_null = {0, 0, 0};
|
|
||||||
|
moved = last_model_pos - absolute_view_pos;
|
||||||
|
last_model_pos = absolute_view_pos;
|
||||||
|
SGVec3f model_vel(model_or.rotateBack(surf_or.rotateBack(moved)));
|
||||||
|
|
||||||
|
|
||||||
sgdSubVec3(sgdv3_help,
|
|
||||||
last_visitor_pos, (double *)&observer->get_view_pos());
|
|
||||||
sgdAddVec3(last_visitor_pos,
|
|
||||||
sgdv3_null, (double *)&observer->get_view_pos());
|
|
||||||
|
|
||||||
SGV3d_help = model_or.rotateBack(
|
|
||||||
surf_or.rotateBack(
|
|
||||||
SGVec3d(sgdv3_help[0], sgdv3_help[1], sgdv3_help[2])
|
|
||||||
));
|
|
||||||
sgSetVec3(listener_vel, SGV3d_help[0], SGV3d_help[1], SGV3d_help[2]);
|
|
||||||
|
|
||||||
sgdSubVec3(sgdv3_help, last_model_pos, absolute_view_pos.data());
|
|
||||||
sgdAddVec3(last_model_pos, sgdv3_null, absolute_view_pos.data());
|
|
||||||
|
|
||||||
SGV3d_help = model_or.rotateBack(
|
|
||||||
surf_or.rotateBack(
|
|
||||||
SGVec3d(sgdv3_help[0], sgdv3_help[1], sgdv3_help[2])
|
|
||||||
));
|
|
||||||
sgSetVec3( model_vel, SGV3d_help[0], SGV3d_help[1], SGV3d_help[2]);
|
|
||||||
|
|
||||||
if (dt > 0) {
|
if (dt > 0) {
|
||||||
sgScaleVec3( model_vel, 1 / dt );
|
model_vel /= dt;
|
||||||
sgScaleVec3( listener_vel, 1 / dt );
|
listener_vel /= dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// checking, if the listener pos has moved suddenly
|
// checking, if the listener pos has moved suddenly
|
||||||
if (sgLengthVec3(listener_vel) > 1000)
|
if (length(listener_vel) > 1000) {
|
||||||
{
|
|
||||||
// check if the relative speed model vs listener has moved suddenly, too
|
// check if the relative speed model vs listener has moved suddenly, too
|
||||||
sgVec3 delta_vel;
|
SGVec3f delta_vel = listener_vel - model_vel;
|
||||||
sgSubVec3(delta_vel, listener_vel, model_vel);
|
if (length(delta_vel) > 1000)
|
||||||
if (sgLengthVec3(delta_vel) > 1000)
|
|
||||||
// a sane value
|
// a sane value
|
||||||
sgSetVec3(listener_vel, model_vel[0], model_vel[1], model_vel[2]);
|
smgr->set_listener_vel(model_vel.data());
|
||||||
else
|
else
|
||||||
smgr->set_listener_vel(listener_vel);
|
smgr->set_listener_vel(listener_vel.data());
|
||||||
|
} else {
|
||||||
|
smgr->set_listener_vel( listener_vel.data());
|
||||||
}
|
}
|
||||||
else
|
|
||||||
smgr->set_listener_vel( listener_vel );
|
|
||||||
|
|
||||||
// set positional offset for sources
|
// set positional offset for sources
|
||||||
sgdVec3 dsource_pos_offset;
|
SGVec3d dsource_pos_offset = observer->get_view_pos() - absolute_view_pos;
|
||||||
sgdSubVec3( dsource_pos_offset,
|
dsource_pos_offset = model_or.rotateBack(surf_or.rotateBack(
|
||||||
(double*) &observer->get_view_pos(),
|
dsource_pos_offset
|
||||||
absolute_view_pos.data() );
|
|
||||||
SGVec3d sgv_dsource_pos_offset;
|
|
||||||
sgv_dsource_pos_offset = model_or.rotateBack(
|
|
||||||
surf_or.rotateBack(
|
|
||||||
SGVec3d(dsource_pos_offset[0],
|
|
||||||
dsource_pos_offset[1],
|
|
||||||
dsource_pos_offset[2])
|
|
||||||
));
|
));
|
||||||
sgVec3 source_pos_offset;
|
|
||||||
sgSetVec3(source_pos_offset,
|
|
||||||
sgv_dsource_pos_offset[0],
|
|
||||||
sgv_dsource_pos_offset[1],
|
|
||||||
sgv_dsource_pos_offset[2]);
|
|
||||||
|
|
||||||
smgr->set_source_pos_all( source_pos_offset );
|
smgr->set_source_pos_all( SGVec3f(dsource_pos_offset).data() );
|
||||||
smgr->set_source_vel_all( model_vel );
|
smgr->set_source_vel_all(model_vel.data() );
|
||||||
|
|
||||||
float orient[6];
|
float orient[6];
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
|
@ -327,9 +290,7 @@ FGFX::update_pos_and_orientation(SGSoundMgr *smgr, double dt)
|
||||||
smgr->set_listener_orientation( orient );
|
smgr->set_listener_orientation( orient );
|
||||||
|
|
||||||
// The listener is always positioned at the origin.
|
// The listener is always positioned at the origin.
|
||||||
sgVec3 listener_pos;
|
smgr->set_listener_pos( SGVec3f::zeros().data() );
|
||||||
sgSetVec3( listener_pos, 0.0, 0.0, 0.0 );
|
|
||||||
smgr->set_listener_pos( listener_pos );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// end of fg_fx.cxx
|
// end of fg_fx.cxx
|
||||||
|
|
|
@ -29,13 +29,12 @@
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <simgear/sound/sample_openal.hxx>
|
|
||||||
#include <simgear/structure/subsystem_mgr.hxx>
|
#include <simgear/structure/subsystem_mgr.hxx>
|
||||||
|
#include <simgear/math/SGMath.hxx>
|
||||||
using std::queue;
|
|
||||||
using std::vector;
|
|
||||||
|
|
||||||
class SGXmlSound;
|
class SGXmlSound;
|
||||||
|
class SGSoundSample;
|
||||||
|
class SGSoundMgr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generator for FlightGear sound effects.
|
* Generator for FlightGear sound effects.
|
||||||
|
@ -72,16 +71,16 @@ public:
|
||||||
* in order.
|
* in order.
|
||||||
*/
|
*/
|
||||||
void play_message( SGSoundSample *_sample );
|
void play_message( SGSoundSample *_sample );
|
||||||
void play_message( const string path, const string fname, double volume );
|
void play_message( const std::string& path, const std::string& fname, double volume );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void update_pos_and_orientation(SGSoundMgr *smgr, double dt);
|
void update_pos_and_orientation(SGSoundMgr *smgr, double dt);
|
||||||
sgdVec3 last_visitor_pos;
|
SGVec3d last_visitor_pos;
|
||||||
sgdVec3 last_model_pos;
|
SGVec3d last_model_pos;
|
||||||
|
|
||||||
vector<SGXmlSound *> _sound;
|
std::vector<SGXmlSound *> _sound;
|
||||||
queue<SGSoundSample *> _samplequeue;
|
std::queue<SGSoundSample *> _samplequeue;
|
||||||
|
|
||||||
bool last_pause;
|
bool last_pause;
|
||||||
double last_volume;
|
double last_volume;
|
||||||
|
|
Loading…
Add table
Reference in a new issue