From: <sv...@ww...> - 2006-04-26 21:55:48
|
Author: stormbringer Date: 2006-04-26 14:55:41 -0700 (Wed, 26 Apr 2006) New Revision: 1923 Modified: trunk/csp/cspsim/LandingGear.cpp trunk/csp/cspsim/LandingGear.h Log: added touchdown sound Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1923 Modified: trunk/csp/cspsim/LandingGear.cpp =================================================================== --- trunk/csp/cspsim/LandingGear.cpp 2006-04-26 21:53:53 UTC (rev 1922) +++ trunk/csp/cspsim/LandingGear.cpp 2006-04-26 21:55:41 UTC (rev 1923) @@ -42,10 +42,18 @@ #include <csp/cspsim/GearAnimation.h> #include <csp/cspsim/KineticsChannels.h> #include <csp/cspsim/LandingGearChannels.h> +#include <csp/cspsim/SystemsModel.h> +#include <csp/cspsim/ResourceBundle.h> +#include <csp/cspsim/sound/Sample.h> +#include <csp/cspsim/sound/SoundModel.h> #include <csp/csplib/util/Math.h> #include <csp/csplib/data/ObjectInterface.h> +#include <csp/csplib/util/osg.h> +#include <osgAL/SoundState> +#include <csp/csplib/util/undef.h> + #include <cstdio> #include <iostream> #include <iomanip> @@ -636,6 +644,27 @@ DEFINE_INPUT_INTERFACE(GearDynamics) +void GearDynamics::bindSounds(SoundModel *model, ResourceBundle *bundle) { + assert(model); + CSPLOG(DEBUG, AUDIO) << "GearDynamics::bindSounds"; + if (bundle) { + CSPLOG(DEBUG, AUDIO) << "GearDynamics::bindSounds have bundle"; + Ref<const SoundSample> sample(bundle->getSoundSample("wheel_touchdown")); + m_TouchdownSound = SoundEffect::ExternalSound(sample, model); + if (m_TouchdownSound.valid()) { + CSPLOG(DEBUG, AUDIO) << "GearDynamics::bindSounds have sound"; + m_TouchdownSound->state()->setPosition(toOSG(m_Gear[0]->getPosition())); + m_TouchdownSound->state()->setDirection(toOSG(m_Gear[0]->getPosition())); + CSPLOG(DEBUG, AUDIO) << "gear touchdown sound position " << m_Gear[0]->getPosition(); + CSPLOG(DEBUG, AUDIO) << "gear touchdown sound direction " << m_Gear[0]->getPosition(); + m_TouchdownSound->state()->apply(); + //m_TouchdownSound->play(); + } + } + CSPLOG(DEBUG, AUDIO) << "GearDynamics::bindSounds exit"; +} + + void GearDynamics::doComplexPhysics(double) { if (b_FullyRetracted->value() && !isGearExtendSelected()) return; m_Force = m_Moment = Vector3::ZERO; @@ -671,6 +700,7 @@ void GearDynamics::registerChannels(Bus *bus) { assert(bus!=0); + SoundModel *sound_model = getModel()->getSoundModel(); b_WOW = bus->registerLocalDataChannel<bool>(bus::LandingGear::WOW, false); b_FullyRetracted = bus->registerLocalDataChannel<bool>(bus::LandingGear::FullyRetracted, false); b_FullyExtended = bus->registerLocalDataChannel<bool>(bus::LandingGear::FullyExtended, true); @@ -678,6 +708,9 @@ for (unsigned i = 0; i < m_Gear.size(); ++i) { m_Gear[i]->registerChannels(bus); } + if (sound_model) { + bindSounds(sound_model, getResourceBundle()); + } } void GearDynamics::importChannels(Bus *bus) { @@ -742,6 +775,8 @@ m_Gear[i]->postSimulationStep(dt, model_origin_local, vBody, *m_Attitude, m_Height, m_GroundNormalBody); // generic WOW signal (any gear in contact with the ground triggers it) if (m_Gear[i]->getWOW()) b_WOW->value() = true; + if (m_Gear[i]->getTouchdown()) + if(m_TouchdownSound.valid()) m_TouchdownSound->play(); } } Modified: trunk/csp/cspsim/LandingGear.h =================================================================== --- trunk/csp/cspsim/LandingGear.h 2006-04-26 21:53:53 UTC (rev 1922) +++ trunk/csp/cspsim/LandingGear.h 2006-04-26 21:55:41 UTC (rev 1923) @@ -300,7 +300,11 @@ Vector3 m_WindVelocityBody; double m_Height; + // Sounds + Ref<SoundEffect> m_TouchdownSound; + virtual double onUpdate(double dt); + void bindSounds(SoundModel *model, ResourceBundle *bundle=0); private: void doComplexPhysics(double x); |