]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIBallistic.hxx
739f766714b699254eab76f2cfb3a03f5ae1ad82
[flightgear.git] / src / AIModel / AIBallistic.hxx
1 // FGAIBallistic.hxx - AIBase derived class creates an AI ballistic object
2 //
3 // Written by David Culp, started November 2003.
4 // - davidculp2@comcast.net
5 //
6 // With major additions by Vivian Meazza, Feb 2008
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License 
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
22 #ifndef _FG_AIBALLISTIC_HXX
23 #define _FG_AIBALLISTIC_HXX
24
25 #include <math.h>
26 #include <vector>
27 #include <simgear/structure/SGSharedPtr.hxx>
28 #include <simgear/scene/material/mat.hxx>
29
30
31 #include "AIManager.hxx"
32 #include "AIBase.hxx"
33
34 using std::vector;
35 using std::list;
36
37 class FGAIBallistic : public FGAIBase {
38
39 public:
40
41     FGAIBallistic(object_type ot = otBallistic);
42     ~FGAIBallistic();
43
44     void readFromScenario(SGPropertyNode* scFileNode);
45
46     bool init(bool search_in_AI_path=false);
47
48     virtual void bind();
49     virtual void unbind();
50
51     void update(double dt);
52
53     FGAIBallistic *ballistic;
54
55     void Run(double dt);
56
57     void setAzimuth( double az );
58     void setElevation( double el );
59     void setRoll( double rl );
60     void setStabilisation( bool val );
61     void setDragArea( double a );
62     void setLife( double seconds );
63     void setBuoyancy( double fpss );
64     void setWind_from_east( double fps );
65     void setWind_from_north( double fps );
66     void setWind( bool val );
67     void setCd( double c );
68     void setMass( double m );
69     void setWeight( double w );
70     void setNoRoll( bool nr );
71     void setRandom( bool r );
72     void setRandomness( double r );
73 //    void setName(const string&);
74     void setCollision(bool c);
75     void setExpiry(bool e);
76     void setImpact(bool i);
77     void setImpactReportNode(const string&);
78     void setContentsNode(const SGPropertyNode_ptr);
79     void setFuseRange(double f);
80     void setSMPath(const string&);
81     void setSubID(int i);
82     void setSubmodel(const string&);
83     void setExternalForce( bool f );
84     void setForcePath(const string&);
85     void setContentsPath(const string&);
86     void setForceStabilisation( bool val );
87     void setGroundOffset(double g);
88     void setLoadOffset(double l);
89     void setSlaved(bool s);
90     void setSlavedLoad(bool s);
91     void setPch (double e, double dt, double c);
92     int setHdg (double az, double dt, double c);
93     void setBnk(double r, double dt, double c);
94     void setHt(double h, double dt, double c);
95     void setSpd(double s, double dt, double c);
96     void setParentNodes(const SGPropertyNode_ptr);
97     void setParentPos();
98     void setOffsetPos(SGGeod pos, double heading, double pitch, double roll);
99     void setOffsetVelocity(double dt, SGGeod pos);
100
101
102     double _getTime() const;
103     double getRelBrgHitchToUser() const;
104     double getElevHitchToUser() const;
105     double getLoadOffset() const;
106     double getContents();
107     double getDistanceToHitch() const;
108     double getElevToHitch() const;
109     double getBearingToHitch() const;
110
111     SGVec3d getCartHitchPos() const;
112
113     bool getHtAGL(double start);
114     bool getSlaved() const;
115 //    bool getFormate() const;
116     bool getSlavedLoad() const;
117
118     virtual const char* getTypeString(void) const { return "ballistic"; }
119     static const double slugs_to_kgs; //conversion factor
120     static const double slugs_to_lbs; //conversion factor
121
122     SGPropertyNode_ptr _force_node;
123     SGPropertyNode_ptr _force_azimuth_node;
124     SGPropertyNode_ptr _force_elevation_node;
125
126     SGPropertyNode_ptr _pnode; // node for parent model
127     SGPropertyNode_ptr _p_pos_node; // nodes for parent parameters
128     SGPropertyNode_ptr _p_lat_node;
129     SGPropertyNode_ptr _p_lon_node;
130     SGPropertyNode_ptr _p_alt_node;
131     SGPropertyNode_ptr _p_agl_node;
132     SGPropertyNode_ptr _p_ori_node;
133     SGPropertyNode_ptr _p_pch_node;
134     SGPropertyNode_ptr _p_rll_node;
135     SGPropertyNode_ptr _p_hdg_node;
136     SGPropertyNode_ptr _p_vel_node;
137     SGPropertyNode_ptr _p_spd_node;
138
139     double _height;
140     double _speed;
141     double _ht_agl_ft;       // height above ground level
142     double _azimuth;         // degrees true
143     double _elevation;       // degrees
144     double _rotation;        // degrees
145     double _speed_north_fps;
146     double _speed_east_fps;
147     double _wind_from_east;  // fps
148     double _wind_from_north; // fps
149
150     double hs;
151
152
153     void setTgtXOffset(double x);
154     void setTgtYOffset(double y);
155     void setTgtZOffset(double z);
156     void setTgtOffsets(double dt, double c);
157
158     double getTgtXOffset() const;
159     double getTgtYOffset() const;
160     double getTgtZOffset() const;
161
162     double _tgt_x_offset;
163     double _tgt_y_offset;
164     double _tgt_z_offset;
165     double _elapsed_time;
166
167     SGGeod _parentpos;
168     SGGeod _oldpos;
169     SGGeod _offsetpos;
170     SGGeod _oldoffsetpos;
171
172 private:
173
174     virtual void reinit() { init(); }
175
176     bool   _aero_stabilised; // if true, object will align with trajectory
177     double _drag_area;       // equivalent drag area in ft2
178     double _life_timer;      // seconds
179     double _gravity;         // fps^2
180     double _buoyancy;        // fps^2
181     bool   _wind;            // if true, local wind will be applied to object
182     double _Cd;              // drag coefficient
183     double _mass;            // slugs
184     bool   _random;          // modifier for Cd, life, az
185     double _randomness;          // dimension for _random, only applies to life at present
186     double _load_resistance; // ground load resistanc N/m^2
187     double _frictionFactor;  // dimensionless modifier for Coefficient of Friction
188     bool   _solid;           // if true ground is solid for FDMs
189     double _elevation_m;     // ground elevation in meters
190     bool   _force_stabilised;// if true, object will align to external force
191     bool   _slave_to_ac;     // if true, object will be slaved to the parent ac pos and orientation
192     bool   _slave_load_to_ac;// if true, object will be slaved to the parent ac pos
193     double _contents_lb;     // contents of the object
194     double _weight_lb;       // weight of the object (no contents if appropriate) (lbs)
195     string _mat_name;
196
197     bool   _report_collision;       // if true a collision point with AI Objects is calculated
198     bool   _report_impact;          // if true an impact point on the terrain is calculated
199     bool   _external_force;         // if true then apply external force
200     bool   _report_expiry;
201
202     SGPropertyNode_ptr _impact_report_node;  // report node for impact and collision
203     SGPropertyNode_ptr _contents_node;  // node for droptank etc. contents
204     //SGPropertyNode_ptr _pnode; // node for parent model
205     //SGPropertyNode_ptr _p_pos_node; // nodes for parent parameters
206     //SGPropertyNode_ptr _p_lat_node;
207     //SGPropertyNode_ptr _p_lon_node;
208     //SGPropertyNode_ptr _p_alt_node;
209     //SGPropertyNode_ptr _p_agl_node;
210     //SGPropertyNode_ptr _p_ori_node;
211     //SGPropertyNode_ptr _p_pch_node;
212     //SGPropertyNode_ptr _p_rll_node;
213     //SGPropertyNode_ptr _p_hdg_node;
214     //SGPropertyNode_ptr _p_vel_node;
215     //SGPropertyNode_ptr _p_spd_node;
216
217     double _fuse_range;
218     double _distance;
219     double _dt_count;
220     double _next_run;
221
222     string _submodel;
223     string _force_path;
224     string _contents_path;
225
226     const SGMaterial* _material;
227
228     void handle_collision();
229     void handle_expiry();
230     void handle_impact();
231     void report_impact(double elevation, const FGAIBase *target = 0);
232     void slaveToAC(double dt);
233     void setContents(double c);
234     void calcVSHS();
235     void calcNE();
236     //void setOffsetPos(SGGeod pos, double heading, double pitch, double roll);
237     //void setOffsetVelocity(double dt, SGGeod pos);
238
239     SGVec3d getCartUserPos() const;
240     SGVec3d getCartOffsetPos(SGGeod pos, double heading, double pitch, double roll) const;
241
242     //double getDistanceLoadToHitch() const;
243     //double getElevLoadToHitch() const;
244     //double getBearingLoadToHitch() const;
245     double getRecip(double az);
246     double getMass() const;
247
248     double _ground_offset;
249     double _load_offset;
250     double _old_height;
251
252     SGVec3d _oldcartoffsetPos;
253     SGVec3d _oldcartPos;
254
255     //SGGeod _parentpos;
256     //SGGeod _oldpos;
257     //SGGeod _offsetpos;
258     //SGGeod _oldoffsetpos;
259
260 };
261
262 #endif  // _FG_AIBALLISTIC_HXX