]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIBallistic.hxx
Interim windows build fix
[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 <cmath>
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 class FGAIBallistic : public FGAIBase {
35
36 public:
37
38     FGAIBallistic(object_type ot = otBallistic);
39     ~FGAIBallistic();
40
41     void readFromScenario(SGPropertyNode* scFileNode);
42
43     bool init(bool search_in_AI_path=false);
44     virtual void bind();
45     virtual void reinit();
46     virtual void update(double dt);
47
48     virtual const char* getTypeString(void) const { return "ballistic"; }
49
50     void Run(double dt);
51
52     void setAzimuth( double az );
53     void setElevation( double el );
54     void setAzimuthRandomError(double error);
55     void setElevationRandomError(double error);
56     void setRoll( double rl );
57     void setStabilisation( bool val );
58     void setDragArea( double a );
59     void setLife( double seconds );
60     void setBuoyancy( double fpss );
61     void setWind_from_east( double fps );
62     void setWind_from_north( double fps );
63     void setWind( bool val );
64     void setCd(double cd);
65     void setCdRandomness(double randomness);
66     void setMass( double m );
67     void setWeight( double w );
68     void setNoRoll( bool nr );
69     void setRandom( bool r );
70     void setLifeRandomness(double randomness);
71     void setCollision(bool c);
72     void setExpiry(bool e);
73     void setImpact(bool i);
74     void setImpactReportNode(const std::string&);
75     void setContentsNode(const SGPropertyNode_ptr);
76     void setFuseRange(double f);
77     void setSMPath(const std::string&);
78     void setSubID(int i);
79     void setSubmodel(const std::string&);
80     void setExternalForce( bool f );
81     void setForcePath(const std::string&);
82     void setContentsPath(const std::string&);
83     void setForceStabilisation( bool val );
84     void setGroundOffset(double g);
85     void setLoadOffset(double l);
86     void setSlaved(bool s);
87     void setSlavedLoad(bool s);
88     void setPch (double e, double dt, double c);
89     int setHdg (double az, double dt, double c);
90     void setBnk(double r, double dt, double c);
91     void setHt(double h, double dt, double c);
92     void setSpd(double s, double dt, double c);
93     void setParentNodes(const SGPropertyNode_ptr);
94     void setParentPos();
95     void setOffsetPos(SGGeod pos, double heading, double pitch, double roll);
96     void setOffsetVelocity(double dt, SGGeod pos);
97     void setTime(double sec);
98
99     double _getTime()const;
100     double getRelBrgHitchToUser() const;
101     double getElevHitchToUser() const;
102     double getLoadOffset() const;
103     double getContents();
104     double getDistanceToHitch() const;
105     double getElevToHitch() const;
106     double getBearingToHitch() const;
107
108     SGVec3d getCartHitchPos() const;
109
110     bool getHtAGL(double start);
111     bool getSlaved() const;
112     bool getSlavedLoad() const;
113
114     FGAIBallistic *ballistic;
115
116     static const double slugs_to_kgs; //conversion factor
117     static const double slugs_to_lbs; //conversion factor
118
119     SGPropertyNode_ptr _force_node;
120     SGPropertyNode_ptr _force_azimuth_node;
121     SGPropertyNode_ptr _force_elevation_node;
122
123     // Node for parent model
124     SGPropertyNode_ptr _pnode;
125
126     // Nodes for parent parameters
127     SGPropertyNode_ptr _p_pos_node;
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     double _az_random_error; // maximum azimuth error in degrees
175     double _el_random_error; // maximum elevation error in degrees
176     bool   _aero_stabilised; // if true, object will align with trajectory
177     double _drag_area;       // equivalent drag area in ft2
178     double _cd;              // current drag coefficient
179     double _init_cd;         // initial drag coefficient
180     double _cd_randomness;   // randomness of Cd. 1.0 means +- 100%, 0.0 means no randomness
181     double _buoyancy;        // fps^2
182     double _life_timer;      // seconds
183     bool   _wind;            // if true, local wind will be applied to object
184     double _mass;            // slugs
185     bool   _random;          // modifier for Cd, life, az
186     double _life_randomness; // dimension for _random, only applies to life at present
187     double _load_resistance; // ground load resistanc N/m^2
188     double _frictionFactor;  // dimensionless modifier for Coefficient of Friction
189     bool   _solid;           // if true ground is solid for FDMs
190     double _elevation_m;     // ground elevation in meters
191     bool   _force_stabilised;// if true, object will align to external force
192     bool   _slave_to_ac;     // if true, object will be slaved to the parent ac pos and orientation
193     bool   _slave_load_to_ac;// if true, object will be slaved to the parent ac pos
194     double _contents_lb;     // contents of the object
195     double _weight_lb;       // weight of the object (no contents if appropriate) (lbs)
196     std::string _mat_name;
197
198     bool   _report_collision;       // if true a collision point with AI Objects is calculated
199     bool   _report_impact;          // if true an impact point on the terrain is calculated
200     bool   _external_force;         // if true then apply external force
201     bool   _report_expiry;
202
203     SGPropertyNode_ptr _impact_report_node;  // report node for impact and collision
204     SGPropertyNode_ptr _contents_node;  // node for droptank etc. contents
205
206     double _fuse_range;
207
208     std::string _submodel;
209     std::string _force_path;
210     std::string _contents_path;
211
212     void handleEndOfLife(double);
213     void handle_collision();
214     void handle_expiry();
215     void handle_impact();
216     void report_impact(double elevation, const FGAIBase *target = 0);
217     void slaveToAC(double dt);
218     void setContents(double c);
219     void calcVSHS();
220     void calcNE();
221
222     SGVec3d getCartOffsetPos(SGGeod pos, double heading, double pitch, double roll) const;
223
224     double getRecip(double az);
225     double getMass() const;
226
227     double _ground_offset;
228     double _load_offset;
229
230     SGVec3d _oldcartoffsetPos;
231     SGVec3d _oldcartPos;
232 };
233
234 #endif  // _FG_AIBALLISTIC_HXX