From 161912ea4ccf632029b8b6937ce561ecace0ef9f Mon Sep 17 00:00:00 2001 From: ehofman Date: Sun, 22 Aug 2004 16:22:18 +0000 Subject: [PATCH] David Culp: Right now the code is not very configurable, and there is only one submodel per airplane possible. It is implemented as an SGSubSystem, just like the electrics, vacuum, etc. systems. To make it work you need to make a release binding like this (for my joystick trigger): Then, each airplane that uses the system should have something like this added to its *-set.xml file (note that this does *not* go within the tags): true 70 Future improvements will include: 1) more configurability, so the user can create multiple submodels, and can assign them different locations, and pitch and yaw adjustments, and nitial velocity. 2) sound? 3) a more accurate calculation of the submodels location at any pitch/roll/yaw. 4) a way to pre-load the model, so the AI code doesn't have to parse the model every time it creates an instance. I think that's all of it. --- src/Systems/Makefile.am | 3 +- src/Systems/submodel.cxx | 100 +++++++++++++++++++++++++++++++++++++ src/Systems/submodel.hxx | 57 +++++++++++++++++++++ src/Systems/system_mgr.cxx | 2 + 4 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 src/Systems/submodel.cxx create mode 100644 src/Systems/submodel.hxx 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 ()