]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/submodel.hxx
submodel: Use quaternions instead of trigonometry
[flightgear.git] / src / AIModel / submodel.hxx
1 // submodel.hxx - models a releasable submodel.
2 // Written by Dave Culp, started Aug 2004
3 //
4 // This file is in the Public Domain and comes with no warranty.
5
6
7 #ifndef __SYSTEMS_SUBMODEL_HXX
8 #define __SYSTEMS_SUBMODEL_HXX 1
9
10 #ifndef __cplusplus
11 # error This library requires C++
12 #endif
13
14 #include <simgear/props/props.hxx>
15 #include <simgear/structure/subsystem_mgr.hxx>
16 #include <simgear/math/SGMath.hxx>
17
18 #include <Autopilot/inputvalue.hxx>
19
20 #include <vector>
21 #include <string>
22
23 class FGAIBase;
24 class FGAIManager;
25
26 class FGSubmodelMgr : public SGSubsystem, public SGPropertyChangeListener
27 {
28
29 public:
30
31     typedef struct {
32         SGPropertyNode_ptr trigger_node;
33         SGPropertyNode_ptr prop;
34         SGPropertyNode_ptr contents_node;
35         SGPropertyNode_ptr submodel_node;
36         SGPropertyNode_ptr speed_node;
37
38         std::string        name;
39         std::string        model;
40         double             speed;
41         bool               slaved;
42         bool               repeat;
43         double             delay;
44         double             timer;
45         int                count;
46         double             x_offset;
47         double             y_offset;
48         double             z_offset;
49         FGXMLAutopilot::InputValue_ptr yaw_offset;
50         FGXMLAutopilot::InputValue_ptr pitch_offset;
51         double             drag_area;
52         double             life;
53         double             buoyancy;
54         FGXMLAutopilot::InputValue_ptr azimuth_error;
55         FGXMLAutopilot::InputValue_ptr elevation_error;
56         FGXMLAutopilot::InputValue_ptr cd_randomness;
57         FGXMLAutopilot::InputValue_ptr life_randomness;
58         bool               wind;
59         bool               first_time;
60         double             cd;
61         double             weight;
62         double             mass;
63         double             contents;
64         bool               aero_stabilised;
65         int                id;
66         bool               no_roll;
67         bool               serviceable;
68         bool               random;
69         bool               collision;
70         bool               expiry;
71         bool               impact;
72         std::string        impact_report;
73         double             fuse_range;
74         std::string        submodel;
75         int                sub_id;
76         bool               force_stabilised;
77         bool               ext_force;
78         std::string        force_path;
79     }   submodel;
80
81     typedef struct {
82         double     lat;
83         double     lon;
84         double     alt;
85         double     roll;
86         double     azimuth;
87         double     elevation;
88         double     speed;
89         double     wind_from_east;
90         double     wind_from_north;
91         double     speed_down_fps;
92         double     speed_east_fps;
93         double     speed_north_fps;
94         double     mass;
95         int        id;
96         bool       no_roll;
97         int        parent_id;
98     }   IC_struct;
99
100     FGSubmodelMgr();
101     ~FGSubmodelMgr();
102
103     void load();
104     void init();
105     void postinit();
106     void bind();
107     void unbind();
108     void update(double dt);
109     void updatelat(double lat);
110
111 private:
112
113     typedef std::vector <submodel*> submodel_vector_type;
114     typedef submodel_vector_type::iterator submodel_vector_iterator;
115
116     submodel_vector_type       submodels;
117     submodel_vector_type       subsubmodels;
118     submodel_vector_iterator   submodel_iterator, subsubmodel_iterator;
119
120     int index;
121
122     double ft_per_deg_longitude;
123     double ft_per_deg_latitude;
124
125     double x_offset, y_offset, z_offset;
126     double pitch_offset, yaw_offset;
127
128     double _parent_lat;
129     double _parent_lon;
130     double _parent_elev;
131     double _parent_hdg;
132     double _parent_pitch;
133     double _parent_roll;
134     double _parent_speed;
135
136     double _x_offset;
137     double _y_offset;
138     double _z_offset;
139
140     // Conversion factor
141     static const double lbs_to_slugs;
142
143     double contrail_altitude;
144
145     bool _impact;
146     bool _hit;
147     bool _expiry;
148     bool _found_sub;
149
150     SGPropertyNode_ptr _serviceable_node;
151     SGPropertyNode_ptr _user_lat_node;
152     SGPropertyNode_ptr _user_lon_node;
153     SGPropertyNode_ptr _user_heading_node;
154     SGPropertyNode_ptr _user_alt_node;
155     SGPropertyNode_ptr _user_pitch_node;
156     SGPropertyNode_ptr _user_roll_node;
157     SGPropertyNode_ptr _user_yaw_node;
158     SGPropertyNode_ptr _user_alpha_node;
159     SGPropertyNode_ptr _user_speed_node;
160     SGPropertyNode_ptr _user_wind_from_east_node;
161     SGPropertyNode_ptr _user_wind_from_north_node;
162     SGPropertyNode_ptr _user_speed_down_fps_node;
163     SGPropertyNode_ptr _user_speed_east_fps_node;
164     SGPropertyNode_ptr _user_speed_north_fps_node;
165     SGPropertyNode_ptr _contrail_altitude_node;
166     SGPropertyNode_ptr _contrail_trigger;
167     SGPropertyNode_ptr _count_node;
168     SGPropertyNode_ptr _trigger_node;
169     SGPropertyNode_ptr props;
170     SGPropertyNode_ptr _model_added_node;
171     SGPropertyNode_ptr _path_node;
172     SGPropertyNode_ptr _selected_ac;
173
174     IC_struct  IC;
175
176     // Helper to retrieve the AI manager, if it currently exists
177     FGAIManager* aiManager();
178
179     void loadAI();
180     void loadSubmodels();
181     void setData(int id, const std::string& path, bool serviceable, const std::string& property_path, submodel_vector_type& models);
182     void valueChanged (SGPropertyNode *);
183     void transform(submodel *);
184     void setParentNode(int parent_id);
185     bool release(submodel *, double dt);
186
187     int _count;
188
189     SGGeod userpos;
190     SGGeod offsetpos;
191     SGVec3d getCartOffsetPos() const;
192     void setOffsetPos();
193
194 };
195
196 #endif // __SYSTEMS_SUBMODEL_HXX