diff --git a/src/Systems/Makefile.am b/src/Systems/Makefile.am index 93ff9c946..c40edae4c 100644 --- a/src/Systems/Makefile.am +++ b/src/Systems/Makefile.am @@ -5,6 +5,7 @@ libSystems_a_SOURCES = \ electrical.cxx electrical.hxx \ pitot.cxx pitot.hxx \ static.cxx static.hxx \ - vacuum.cxx vacuum.hxx + vacuum.cxx vacuum.hxx \ + submodel.cxx submodel.hxx INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src diff --git a/src/Systems/submodel.cxx b/src/Systems/submodel.cxx new file mode 100644 index 000000000..a6d04e494 --- /dev/null +++ b/src/Systems/submodel.cxx @@ -0,0 +1,100 @@ +// submodel.cxx - models a releasable submodel. +// Written by Dave Culp, started Aug 2004 +// +// This file is in the Public Domain and comes with no warranty. + +#include "submodel.hxx" +#include
+#include
+#include + + +SubmodelSystem::SubmodelSystem () +{ + firing = false; + x_offset = y_offset = 0.0; + z_offset = -4.0; + pitch_offset = 2.0; + yaw_offset = 0.0; +} + +SubmodelSystem::~SubmodelSystem () +{ +} + +void +SubmodelSystem::init () +{ + _serviceable_node = fgGetNode("/systems/submodel/serviceable", true); + _serviceable_node->setBoolValue(true); + _trigger_node = fgGetNode("/systems/submodel/trigger", true); + _trigger_node->setBoolValue(false); + _amount_node = fgGetNode("/systems/submodel/amount", true); + _amount_node->setIntValue(60); + + _user_lat_node = fgGetNode("/position/latitude-deg", true); + _user_lon_node = fgGetNode("/position/longitude-deg", true); + _user_alt_node = fgGetNode("/position/altitude-ft", true); + + _user_heading_node = fgGetNode("/orientation/heading-deg", true); + _user_pitch_node = fgGetNode("/orientation/pitch-deg", true); + _user_roll_node = fgGetNode("/orientation/roll-deg", true); + _user_yaw_node = fgGetNode("/orientation/yaw-deg", true); + + _user_speed_node = fgGetNode("/velocities/uBody-fps", true); + + elapsed_time = 0.0; + initial_velocity = 2750.0; // feet per second, .50 caliber + + ai = (FGAIManager*)globals->get_subsystem("ai_model"); +} + +void +SubmodelSystem::bind () +{ +} + +void +SubmodelSystem::unbind () +{ +} + +void +SubmodelSystem::update (double dt) +{ + if (_trigger_node->getBoolValue()) { + if (_serviceable_node->getBoolValue()) { + if (_amount_node->getIntValue() > 0) { + firing = true; + release(dt); + } + } + } else { + if (firing){ + firing = false; + elapsed_time = 0.0; + } + } +} + +bool +SubmodelSystem::release (double dt) +{ + // releases a submodel every 0.25 seconds + elapsed_time += dt; + if (elapsed_time < 0.25) return false; + elapsed_time = 0.0; + + int rval = ai->createBallistic( "Models/Geometry/tracer.ac", + _user_lat_node->getDoubleValue(), + _user_lon_node->getDoubleValue(), + _user_alt_node->getDoubleValue() + z_offset, + _user_heading_node->getDoubleValue() + yaw_offset, + _user_pitch_node->getDoubleValue() + pitch_offset, + _user_speed_node->getDoubleValue() + initial_velocity ); + + _amount_node->setIntValue( _amount_node->getIntValue() - 1); + return true; +} + +// end of submodel.cxx diff --git a/src/Systems/submodel.hxx b/src/Systems/submodel.hxx new file mode 100644 index 000000000..3b96ec02e --- /dev/null +++ b/src/Systems/submodel.hxx @@ -0,0 +1,57 @@ +// submodel.hxx - models a releasable submodel. +// Written by Dave Culp, started Aug 2004 +// +// This file is in the Public Domain and comes with no warranty. + + +#ifndef __SYSTEMS_SUBMODEL_HXX +#define __SYSTEMS_SUBMODEL_HXX 1 + +#ifndef __cplusplus +# error This library requires C++ +#endif + +#include +#include +#include + + +class SubmodelSystem : public SGSubsystem +{ + +public: + + SubmodelSystem (); + ~SubmodelSystem (); + + void init (); + void bind (); + void unbind (); + void update (double dt); + bool release (double dt); + +private: + + double x_offset, y_offset, z_offset; + double pitch_offset, yaw_offset; + + SGPropertyNode_ptr _serviceable_node; + SGPropertyNode_ptr _trigger_node; + SGPropertyNode_ptr _amount_node; + + SGPropertyNode_ptr _user_lat_node; + SGPropertyNode_ptr _user_lon_node; + SGPropertyNode_ptr _user_heading_node; + SGPropertyNode_ptr _user_alt_node; + SGPropertyNode_ptr _user_pitch_node; + SGPropertyNode_ptr _user_roll_node; + SGPropertyNode_ptr _user_yaw_node; + SGPropertyNode_ptr _user_speed_node; + + double elapsed_time; + FGAIManager* ai; + double initial_velocity; + bool firing; +}; + +#endif // __SYSTEMS_SUBMODEL_HXX diff --git a/src/Systems/system_mgr.cxx b/src/Systems/system_mgr.cxx index bdf525f14..07639af1e 100644 --- a/src/Systems/system_mgr.cxx +++ b/src/Systems/system_mgr.cxx @@ -9,6 +9,7 @@ #include "pitot.hxx" #include "static.hxx" #include "vacuum.hxx" +#include "submodel.hxx" FGSystemMgr::FGSystemMgr () @@ -18,6 +19,7 @@ FGSystemMgr::FGSystemMgr () set_subsystem( "static", new StaticSystem ); set_subsystem( "vacuum-l", new VacuumSystem(0) ); set_subsystem( "vacuum-r", new VacuumSystem(1) ); + // set_subsystem( "submodel", new SubmodelSystem() ); } FGSystemMgr::~FGSystemMgr ()