1
0
Fork 0

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):

 <button n="0">
  <desc>Trigger</desc>
  <binding>
   <command>property-assign</command>
   <property>/systems/submodel/trigger</property>
   <value type="bool">true</value>
  </binding>
  <mod-up>
   <binding>
    <command>property-assign</command>
    <property>/systems/submodel/trigger</property>
    <value type="bool">false</value>
   </binding>
  </mod-up>
 </button>

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 <sim></sim> tags):

 <systems>
   <submodel>
    <serviceable type="bool">true</serviceable>
    <amount type="int">70</amount>
   </submodel>
 </systems>


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.
This commit is contained in:
ehofman 2004-08-22 16:22:18 +00:00
parent 72b201d96c
commit 161912ea4c
4 changed files with 161 additions and 1 deletions

View file

@ -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

100
src/Systems/submodel.cxx Normal file
View file

@ -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 <Main/fg_props.hxx>
#include <Main/util.hxx>
#include <AIModel/AIManager.hxx>
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

57
src/Systems/submodel.hxx Normal file
View file

@ -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 <simgear/props/props.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
#include <AIModel/AIManager.hxx>
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

View file

@ -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 ()