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.
2004-08-22 16:22:18 +00:00
|
|
|
// 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;
|
|
|
|
|
2004-08-22 17:04:37 +00:00
|
|
|
int rval = ai->createBallistic( "Models/Geometry/tracer.xml",
|
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.
2004-08-22 16:22:18 +00:00
|
|
|
_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
|