move some of the sound postion and orientation calculations over to the sample class which also makes the main code nice and clean
This commit is contained in:
parent
b582c118bd
commit
a9b3fc7a56
5 changed files with 22 additions and 51 deletions
src
|
@ -2106,16 +2106,6 @@ MK_VIII::VoicePlayer::Speaker::bind (SGPropertyNode *node)
|
|||
// uses xmlsound property names
|
||||
tie(node, "volume", &volume);
|
||||
tie(node, "pitch", &pitch);
|
||||
tie(node, "position/x", &position[0]);
|
||||
tie(node, "position/y", &position[1]);
|
||||
tie(node, "position/z", &position[2]);
|
||||
tie(node, "orientation/x", &orientation[0]);
|
||||
tie(node, "orientation/y", &orientation[1]);
|
||||
tie(node, "orientation/z", &orientation[2]);
|
||||
tie(node, "orientation/inner-cone", &inner_cone);
|
||||
tie(node, "orientation/outer-cone", &outer_cone);
|
||||
tie(node, "reference-dist", &reference_dist);
|
||||
tie(node, "max-dist", &max_dist);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -2127,11 +2117,6 @@ MK_VIII::VoicePlayer::Speaker::update_configuration ()
|
|||
SGSoundSample *sample = (*iter).second;
|
||||
|
||||
sample->set_pitch(pitch);
|
||||
sample->set_base_position(position); // TODO: tie to listener pos
|
||||
sample->set_orientation(orientation);
|
||||
sample->set_audio_cone(inner_cone, outer_cone, outer_gain);
|
||||
sample->set_reference_dist(reference_dist);
|
||||
sample->set_max_dist(max_dist);
|
||||
}
|
||||
|
||||
if (player->voice)
|
||||
|
|
|
@ -889,13 +889,6 @@ public:
|
|||
VoicePlayer *player;
|
||||
|
||||
double pitch;
|
||||
SGVec3d position;
|
||||
SGVec3f orientation;
|
||||
float inner_cone;
|
||||
float outer_cone;
|
||||
float outer_gain;
|
||||
float reference_dist;
|
||||
float max_dist;
|
||||
|
||||
template <class T>
|
||||
inline void tie (SGPropertyNode *node, const char *name, T *ptr)
|
||||
|
@ -920,15 +913,8 @@ public:
|
|||
inline Speaker (VoicePlayer *_player)
|
||||
: player(_player),
|
||||
pitch(1),
|
||||
inner_cone(360),
|
||||
outer_cone(360),
|
||||
outer_gain(0),
|
||||
reference_dist(3),
|
||||
max_dist(10),
|
||||
volume(1)
|
||||
{
|
||||
position[0] = 0; position[1] = 0; position[2] = 0;
|
||||
orientation[0] = 0; orientation[1] = 0; orientation[2] = 0;
|
||||
}
|
||||
|
||||
void bind (SGPropertyNode *node);
|
||||
|
|
|
@ -298,11 +298,11 @@ FGViewMgr::update (double dt)
|
|||
|
||||
// update audio listener values
|
||||
// set the viewer posotion in Cartesian coordinates in meters
|
||||
smgr->set_position(-abs_viewer_position);
|
||||
smgr->set_position( abs_viewer_position );
|
||||
smgr->set_orientation(loop_view->getViewOrientation());
|
||||
|
||||
// get the model velocity for the in-cockpit view
|
||||
SGVec3f velocity = SGVec3f(0,0,0);
|
||||
SGVec3d velocity = SGVec3d(0,0,0);
|
||||
if ( !stationary() ) {
|
||||
FGAircraftModel *aircraft = globals->get_aircraft_model();
|
||||
velocity = aircraft->getVelocity();
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
|
||||
FGAircraftModel::FGAircraftModel ()
|
||||
: _aircraft(0),
|
||||
_velocity(SGVec3f::zeros()),
|
||||
_velocity(SGVec3d::zeros()),
|
||||
_fx(0),
|
||||
_lon(0),
|
||||
_lat(0),
|
||||
|
@ -44,7 +44,9 @@ FGAircraftModel::FGAircraftModel ()
|
|||
_pitch(0),
|
||||
_roll(0),
|
||||
_heading(0),
|
||||
_speed(0)
|
||||
_speed_n(0),
|
||||
_speed_e(0),
|
||||
_speed_d(0)
|
||||
{
|
||||
SGSoundMgr *smgr;
|
||||
smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
||||
|
@ -91,7 +93,9 @@ FGAircraftModel::bind ()
|
|||
_pitch = fgGetNode("orientation/pitch-deg", true);
|
||||
_roll = fgGetNode("orientation/roll-deg", true);
|
||||
_heading = fgGetNode("orientation/heading-deg", true);
|
||||
_speed = fgGetNode("velocities/groundspeed-kt", true);
|
||||
_speed_n = fgGetNode("velocities/speed-north-fps", true);
|
||||
_speed_e = fgGetNode("velocities/speed-east-fps", true);
|
||||
_speed_d = fgGetNode("velocities/speed-down-fps", true);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -121,21 +125,16 @@ FGAircraftModel::update (double dt)
|
|||
_aircraft->update();
|
||||
|
||||
// update model's audio sample values
|
||||
// Get the Cartesian coordinates in meters
|
||||
SGVec3d pos = SGVec3d::fromGeod(_aircraft->getPosition());
|
||||
_fx->set_position( -pos );
|
||||
_fx->set_position( _aircraft->getPosition() );
|
||||
|
||||
SGQuatd orient_m = SGQuatd::fromLonLat(_aircraft->getPosition());
|
||||
orient_m *= SGQuatd::fromYawPitchRollDeg(_heading->getDoubleValue(),
|
||||
SGQuatd orient = SGQuatd::fromYawPitchRollDeg(_heading->getDoubleValue(),
|
||||
_pitch->getDoubleValue(),
|
||||
_roll->getDoubleValue());
|
||||
SGVec3d orient = -orient_m.rotate(SGVec3d::e1());
|
||||
_fx->set_orientation( toVec3f( orient ) );
|
||||
_fx->set_orientation( orient );
|
||||
|
||||
// For now assume the aircraft speed is always along the longitudinal
|
||||
// axis, so sideslipping is not taken into account. This should be fine
|
||||
// for audio.
|
||||
_velocity = toVec3f(orient * _speed->getDoubleValue() * SG_KT_TO_MPS);
|
||||
_velocity = SGVec3d( -_speed_n->getDoubleValue(),
|
||||
-_speed_e->getDoubleValue(),
|
||||
-_speed_d->getDoubleValue());
|
||||
_fx->set_velocity( _velocity );
|
||||
}
|
||||
|
||||
|
|
|
@ -39,12 +39,12 @@ public:
|
|||
virtual void unbind ();
|
||||
virtual void update (double dt);
|
||||
virtual SGModelPlacement * get3DModel() { return _aircraft; }
|
||||
virtual SGVec3f getVelocity() { return _velocity; }
|
||||
virtual SGVec3d getVelocity() { return _velocity; }
|
||||
|
||||
private:
|
||||
|
||||
SGModelPlacement * _aircraft;
|
||||
SGVec3f _velocity;
|
||||
SGVec3d _velocity;
|
||||
FGFX * _fx;
|
||||
|
||||
SGPropertyNode * _lon;
|
||||
|
@ -53,8 +53,9 @@ private:
|
|||
SGPropertyNode * _pitch;
|
||||
SGPropertyNode * _roll;
|
||||
SGPropertyNode * _heading;
|
||||
SGPropertyNode * _speed;
|
||||
|
||||
SGPropertyNode * _speed_n;
|
||||
SGPropertyNode * _speed_e;
|
||||
SGPropertyNode * _speed_d;
|
||||
};
|
||||
|
||||
#endif // __ACMODEL_HXX
|
||||
|
|
Loading…
Add table
Reference in a new issue