]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/submodel.hxx
submodel: Fix incorrect yaw and pitch offsets
[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     total_speed_down;
95         double     total_speed_east;
96         double     total_speed_north;
97         double     mass;
98         int        id;
99         bool       no_roll;
100         int        parent_id;
101     }   IC_struct;
102
103     FGSubmodelMgr();
104     ~FGSubmodelMgr();
105
106     void load();
107     void init();
108     void postinit();
109     void bind();
110     void unbind();
111     void update(double dt);
112     void updatelat(double lat);
113
114 private:
115
116     typedef std::vector <submodel*> submodel_vector_type;
117     typedef submodel_vector_type::iterator submodel_vector_iterator;
118
119     submodel_vector_type       submodels;
120     submodel_vector_type       subsubmodels;
121     submodel_vector_iterator   submodel_iterator, subsubmodel_iterator;
122
123     int index;
124
125     double ft_per_deg_longitude;
126     double ft_per_deg_latitude;
127
128     double x_offset, y_offset, z_offset;
129     double pitch_offset, yaw_offset;
130
131     double _parent_lat;
132     double _parent_lon;
133     double _parent_elev;
134     double _parent_hdg;
135     double _parent_pitch;
136     double _parent_roll;
137     double _parent_speed;
138
139     double _x_offset;
140     double _y_offset;
141     double _z_offset;
142
143     // Conversion factor
144     static const double lbs_to_slugs;
145
146     double contrail_altitude;
147
148     bool _impact;
149     bool _hit;
150     bool _expiry;
151     bool _found_sub;
152
153     SGPropertyNode_ptr _serviceable_node;
154     SGPropertyNode_ptr _user_lat_node;
155     SGPropertyNode_ptr _user_lon_node;
156     SGPropertyNode_ptr _user_heading_node;
157     SGPropertyNode_ptr _user_alt_node;
158     SGPropertyNode_ptr _user_pitch_node;
159     SGPropertyNode_ptr _user_roll_node;
160     SGPropertyNode_ptr _user_yaw_node;
161     SGPropertyNode_ptr _user_alpha_node;
162     SGPropertyNode_ptr _user_speed_node;
163     SGPropertyNode_ptr _user_wind_from_east_node;
164     SGPropertyNode_ptr _user_wind_from_north_node;
165     SGPropertyNode_ptr _user_speed_down_fps_node;
166     SGPropertyNode_ptr _user_speed_east_fps_node;
167     SGPropertyNode_ptr _user_speed_north_fps_node;
168     SGPropertyNode_ptr _contrail_altitude_node;
169     SGPropertyNode_ptr _contrail_trigger;
170     SGPropertyNode_ptr _count_node;
171     SGPropertyNode_ptr _trigger_node;
172     SGPropertyNode_ptr props;
173     SGPropertyNode_ptr _model_added_node;
174     SGPropertyNode_ptr _path_node;
175     SGPropertyNode_ptr _selected_ac;
176
177     IC_struct  IC;
178
179     // Helper to retrieve the AI manager, if it currently exists
180     FGAIManager* aiManager();
181
182     void loadAI();
183     void loadSubmodels();
184     void setData(int id, const std::string& path, bool serviceable, const std::string& property_path, submodel_vector_type& models);
185     void valueChanged (SGPropertyNode *);
186     void transform(submodel *);
187     void setParentNode(int parent_id);
188     bool release(submodel *, double dt);
189
190     int _count;
191
192     SGGeod userpos;
193     SGGeod offsetpos;
194     SGVec3d getCartOffsetPos() const;
195     void setOffsetPos();
196
197 };
198
199 #endif // __SYSTEMS_SUBMODEL_HXX