]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIBallistic.hxx
Merge commit 'refs/merge-requests/1552' of git@gitorious.org:fg/flightgear into next
[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     virtual void bind();
48     virtual void unbind();
49
50     void update(double dt);
51
52     FGAIBallistic *ballistic;
53
54     void Run(double dt);
55
56     void setAzimuth( double az );
57     void setElevation( double el );
58     void setRoll( double rl );
59     void setStabilisation( bool val );
60     void setDragArea( double a );
61     void setLife( double seconds );
62     void setBuoyancy( double fpss );
63     void setWind_from_east( double fps );
64     void setWind_from_north( double fps );
65     void setWind( bool val );
66     void setCd( double c );
67     void setMass( double m );
68     void setWeight( double w );
69     void setNoRoll( bool nr );
70     void setRandom( bool r );
71     void setRandomness( double r );
72     void setName(const string&);
73     void setCollision(bool c);
74     void setExpiry(bool e);
75     void setImpact(bool i);
76     void setImpactReportNode(const string&);
77     void setContentsNode(const SGPropertyNode_ptr);
78     void setFuseRange(double f);
79     void setSMPath(const string&);
80     void setSubID(int i);
81     void setSubmodel(const string&);
82     void setExternalForce( bool f );
83     void setForcePath(const string&);
84     void setContentsPath(const string&);
85     void setForceStabilisation( bool val );
86     void setGroundOffset(double g);
87     void setLoadOffset(double l);
88     void setSlaved(bool s);
89     void setSlavedLoad(bool s);
90     void setPch (double e, double dt, double c);
91     void setHdg (double az, double dt, double c);
92     void setBnk(double r, double dt, double c);
93     void setHt(double h, double dt, double c);
94     void setFormate(bool f);
95     void setParentNode(const SGPropertyNode_ptr);
96     void setParentPos();
97
98     double _getTime() const;
99     double getRelBrgHitchToUser() const;
100     double getElevHitchToUser() const;
101     double getLoadOffset() const;
102     double getContents();
103
104     SGVec3d getCartHitchPos() const;
105
106     bool getHtAGL(double start);
107     bool getSlaved() const;
108     bool getFormate() const;
109     bool getSlavedLoad() const;
110
111     virtual const char* getTypeString(void) const { return "ballistic"; }
112     static const double slugs_to_kgs; //conversion factor
113     static const double slugs_to_lbs; //conversion factor
114
115     SGPropertyNode_ptr _force_node;
116     SGPropertyNode_ptr _force_azimuth_node;
117     SGPropertyNode_ptr _force_elevation_node;
118
119     double _height;
120     double _ht_agl_ft;       // height above ground level
121     double _azimuth;         // degrees true
122     double _elevation;       // degrees
123     double _rotation;        // degrees
124     double _speed_north_fps;
125     double _speed_east_fps;
126
127     bool   _formate_to_ac;
128
129     void setTgtXOffset(double x);
130     void setTgtYOffset(double y);
131     void setTgtZOffset(double z);
132     void setTgtOffsets(double dt, double c);
133
134     double getTgtXOffset() const;
135     double getTgtYOffset() const;
136     double getTgtZOffset() const;
137
138     double _tgt_x_offset;
139     double _tgt_y_offset;
140     double _tgt_z_offset;
141     double _elapsed_time;
142
143 private:
144
145     virtual void reinit() { init(); }
146
147     bool   _aero_stabilised; // if true, object will align with trajectory
148     double _drag_area;       // equivalent drag area in ft2
149     double _life_timer;      // seconds
150     double _gravity;         // fps^2
151     double _buoyancy;        // fps^2
152     double _wind_from_east;  // fps
153     double _wind_from_north; // fps
154     bool   _wind;            // if true, local wind will be applied to object
155     double _Cd;              // drag coefficient
156     double _mass;            // slugs
157     bool   _random;          // modifier for Cd, life, az
158     double _randomness;          // dimension for _random, only applies to life at present
159     double _load_resistance; // ground load resistanc N/m^2
160     double _frictionFactor;  // dimensionless modifier for Coefficient of Friction
161     bool   _solid;           // if true ground is solid for FDMs
162     double _elevation_m;     // ground elevation in meters
163     bool   _force_stabilised;// if true, object will align to external force
164     bool   _slave_to_ac;     // if true, object will be slaved to the parent ac pos and orientation
165     bool   _slave_load_to_ac;// if true, object will be slaved to the parent ac pos
166     double _contents_lb;     // contents of the object
167     double _weight_lb;       // weight of the object (no contents if appropriate) (lbs)
168     string _mat_name;
169
170     bool   _report_collision;       // if true a collision point with AI Objects is calculated
171     bool   _report_impact;          // if true an impact point on the terrain is calculated
172     bool   _external_force;         // if true then apply external force
173     bool   _report_expiry;
174
175     SGPropertyNode_ptr _impact_report_node;  // report node for impact and collision
176     SGPropertyNode_ptr _contents_node;  // node for droptank etc. contents
177     SGPropertyNode_ptr _pnode; // node for parent model
178     SGPropertyNode_ptr _p_pos_node; // nodes for parent parameters 
179     SGPropertyNode_ptr _p_lat_node;
180     SGPropertyNode_ptr _p_lon_node;
181     SGPropertyNode_ptr _p_alt_node;
182     SGPropertyNode_ptr _p_ori_node;
183     SGPropertyNode_ptr _p_pch_node;
184     SGPropertyNode_ptr _p_rll_node;
185     SGPropertyNode_ptr _p_hdg_node;
186     SGPropertyNode_ptr _p_vel_node;
187     SGPropertyNode_ptr _p_spd_node;
188
189     double _fuse_range;
190     double _distance;
191     double _dt_count;
192     double _next_run;
193
194     string _submodel;
195     string _force_path;
196     string _contents_path;
197
198     const SGMaterial* _material;
199
200     void handle_collision();
201     void handle_expiry();
202     void handle_impact();
203     void report_impact(double elevation, const FGAIBase *target = 0);
204     void slaveToAC(double dt);
205     void setContents(double c);
206     void formateToAC(double dt);
207     void calcVSHS();
208     void calcNE();
209     void setOffsetPos(SGGeod pos, double heading, double pitch, double roll);
210     void setOffsetVelocity(double dt, SGGeod pos);
211
212     SGVec3d getCartUserPos() const;
213     SGVec3d getCartOffsetPos(SGGeod pos, double heading, double pitch, double roll) const;
214
215     double getDistanceLoadToHitch() const;
216     double getElevLoadToHitch() const;
217     double getBearingLoadToHitch() const;
218     double getRecip(double az);
219     double getMass() const;
220
221     double hs;
222     double _ground_offset;
223     double _load_offset;
224     double _old_height;
225
226     SGVec3d _oldcartoffsetPos;
227     SGVec3d _oldcartPos;
228
229     SGGeod _parentpos;
230     SGGeod _oldpos;
231     SGGeod _offsetpos;
232     SGGeod _oldoffsetpos;
233
234 };
235
236 #endif  // _FG_AIBALLISTIC_HXX