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