1
0
Fork 0
flightgear/src/AIModel/submodel.hxx

141 lines
3.2 KiB
C++
Raw Normal View History

// 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/AIBase.hxx>
2004-08-26 08:38:43 +00:00
#include <vector>
#include <string>
SG_USING_STD(vector);
SG_USING_STD(string);
class FGSubmodelMgr : public SGSubsystem
{
public:
2004-08-26 08:38:43 +00:00
typedef struct {
SGPropertyNode* trigger;
SGPropertyNode* prop;
SGPropertyNode* contents_node;
2004-08-26 08:38:43 +00:00
string name;
string model;
double speed;
bool slaved;
bool repeat;
double delay;
double timer;
int count;
double x_offset;
double y_offset;
double z_offset;
double yaw_offset;
double pitch_offset;
David Culp: Silly me. I was starting the timer at zero, so the first tracer didn't fly until 0.25 seconds after pulling the trigger. Now the timer starts at the same value as "delay", so the first round comes out immediately. Also, I've added an optional configuration attribute that allows you to change the ballistics of the submodel. This allows parachutes, or anything else that has ballistics different from a bullet. The attribute is called "eda", which is the equivalent drag area. Default value is 0.007, which gives the same ballistics as the current tracers. Increasing this value gives more drag. A value of 2.0 looks good for a parachute. math stuff ######################################################################## The deceleration of the ballictic object is now given by: [ (rho) (Cd) ] / [ (1/2) (m) ] * A * (V * V) where rho is sea-level air density, and Cd and m are fixed, bullet-like values. So the calculation is: 0.0116918 * A * (V * V) The value "A" is what I'm calling the "eda" (equivalent drag area). ######################################################################## A parachute model will have to be built so that the parachutist's feet are in the forward x-direction. Here is the submodel.xml config I use for "parachutes": <submodel> <name>flares</name> <model>Models/Geometry/flare.ac</model> <trigger>systems/submodels/submodel[0]/trigger</trigger> <speed>0.0</speed> <repeat>true</repeat> <delay>0.85</delay> <count>4</count> <x-offset>0.0</x-offset> <y-offset>0.0</y-offset> <z-offset>-4.0</z-offset> <yaw-offset>0.0</yaw-offset> <pitch-offset>0.0</pitch-offset> <eda>2.0</eda> </submodel>
2004-08-26 16:25:54 +00:00
double drag_area;
double life;
2004-09-01 21:05:04 +00:00
double buoyancy;
bool wind;
bool first_time;
double cd;
double weight;
double contents;
2004-08-26 08:38:43 +00:00
} submodel;
typedef struct {
double lat;
double lon;
double alt;
double roll;
2004-08-26 08:38:43 +00:00
double azimuth;
double elevation;
double speed;
double wind_from_east;
double wind_from_north;
double speed_down_fps;
double speed_east_fps;
double speed_north_fps;
double total_speed_down;
double total_speed_east;
double total_speed_north;
double mass;
2004-08-26 08:38:43 +00:00
} IC_struct;
FGSubmodelMgr ();
~FGSubmodelMgr ();
2004-08-26 08:38:43 +00:00
void load ();
void init ();
void bind ();
void unbind ();
void update (double dt);
2004-08-26 08:38:43 +00:00
bool release (submodel* sm, double dt);
void transform (submodel* sm);
void updatelat( double lat );
private:
2004-08-26 08:38:43 +00:00
typedef vector <submodel*> submodel_vector_type;
typedef submodel_vector_type::iterator submodel_vector_iterator;
submodel_vector_type submodels;
submodel_vector_iterator submodel_iterator;
float trans[3][3];
float in[3];
float out[3];
double Rx, Ry, Rz;
double Sx, Sy, Sz;
double Tx, Ty, Tz;
float cosRx, sinRx;
float cosRy, sinRy;
float cosRz, sinRz;
double ft_per_deg_longitude;
double ft_per_deg_latitude;
2004-08-26 08:38:43 +00:00
double x_offset, y_offset, z_offset;
double pitch_offset, yaw_offset;
static const double lbs_to_slugs; //conversion factor
SGPropertyNode* _serviceable_node;
SGPropertyNode* _user_lat_node;
SGPropertyNode* _user_lon_node;
SGPropertyNode* _user_heading_node;
SGPropertyNode* _user_alt_node;
SGPropertyNode* _user_pitch_node;
SGPropertyNode* _user_roll_node;
SGPropertyNode* _user_yaw_node;
SGPropertyNode* _user_alpha_node;
SGPropertyNode* _user_speed_node;
SGPropertyNode* _user_wind_from_east_node;
SGPropertyNode* _user_wind_from_north_node;
SGPropertyNode* _user_speed_down_fps_node;
SGPropertyNode* _user_speed_east_fps_node;
SGPropertyNode* _user_speed_north_fps_node;
FGAIManager* ai;
2004-08-26 08:38:43 +00:00
IC_struct IC;
};
#endif // __SYSTEMS_SUBMODEL_HXX