]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIBallistic.hxx
bvh: Adapt to upstream bvh changes in simgear.
[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 reinit();
49     virtual void update(double dt);
50
51     virtual const char* getTypeString(void) const { return "ballistic"; }
52
53     void Run(double dt);
54
55     void setAzimuth( double az );
56     void setElevation( double el );
57     void setRoll( double rl );
58     void setStabilisation( bool val );
59     void setDragArea( double a );
60     void setLife( double seconds );
61     void setBuoyancy( double fpss );
62     void setWind_from_east( double fps );
63     void setWind_from_north( double fps );
64     void setWind( bool val );
65     void setCd( double c );
66     void setMass( double m );
67     void setWeight( double w );
68     void setNoRoll( bool nr );
69     void setRandom( bool r );
70     void setRandomness( double r );
71 //    void setName(const string&);
72     void setCollision(bool c);
73     void setExpiry(bool e);
74     void setImpact(bool i);
75     void setImpactReportNode(const string&);
76     void setContentsNode(const SGPropertyNode_ptr);
77     void setFuseRange(double f);
78     void setSMPath(const string&);
79     void setSubID(int i);
80     void setSubmodel(const string&);
81     void setExternalForce( bool f );
82     void setForcePath(const string&);
83     void setContentsPath(const string&);
84     void setForceStabilisation( bool val );
85     void setGroundOffset(double g);
86     void setLoadOffset(double l);
87     void setSlaved(bool s);
88     void setSlavedLoad(bool s);
89     void setPch (double e, double dt, double c);
90     int setHdg (double az, double dt, double c);
91     void setBnk(double r, double dt, double c);
92     void setHt(double h, double dt, double c);
93     void setSpd(double s, double dt, double c);
94     void setParentNodes(const SGPropertyNode_ptr);
95     void setParentPos();
96     void setOffsetPos(SGGeod pos, double heading, double pitch, double roll);
97     void setOffsetVelocity(double dt, SGGeod pos);
98     void setTime(double sec);
99
100     double _getTime()const;
101     double getRelBrgHitchToUser() const;
102     double getElevHitchToUser() const;
103     double getLoadOffset() const;
104     double getContents();
105     double getDistanceToHitch() const;
106     double getElevToHitch() const;
107     double getBearingToHitch() const;
108
109     SGVec3d getCartHitchPos() const;
110
111     bool getHtAGL(double start);
112     bool getSlaved() const;
113 //    bool getFormate() const;
114     bool getSlavedLoad() const;
115
116     FGAIBallistic *ballistic;
117
118     static const double slugs_to_kgs; //conversion factor
119     static const double slugs_to_lbs; //conversion factor
120
121     SGPropertyNode_ptr _force_node;
122     SGPropertyNode_ptr _force_azimuth_node;
123     SGPropertyNode_ptr _force_elevation_node;
124
125     SGPropertyNode_ptr _pnode; // node for parent model
126     SGPropertyNode_ptr _p_pos_node; // nodes for parent parameters
127     SGPropertyNode_ptr _p_lat_node;
128     SGPropertyNode_ptr _p_lon_node;
129     SGPropertyNode_ptr _p_alt_node;
130     SGPropertyNode_ptr _p_agl_node;
131     SGPropertyNode_ptr _p_ori_node;
132     SGPropertyNode_ptr _p_pch_node;
133     SGPropertyNode_ptr _p_rll_node;
134     SGPropertyNode_ptr _p_hdg_node;
135     SGPropertyNode_ptr _p_vel_node;
136     SGPropertyNode_ptr _p_spd_node;
137
138     double _height;
139     double _speed;
140     double _ht_agl_ft;       // height above ground level
141     double _azimuth;         // degrees true
142     double _elevation;       // degrees
143     double _rotation;        // degrees
144     double _speed_north_fps;
145     double _speed_east_fps;
146     double _wind_from_east;  // fps
147     double _wind_from_north; // fps
148
149     double hs;
150
151
152     void setTgtXOffset(double x);
153     void setTgtYOffset(double y);
154     void setTgtZOffset(double z);
155     void setTgtOffsets(double dt, double c);
156
157     double getTgtXOffset() const;
158     double getTgtYOffset() const;
159     double getTgtZOffset() const;
160
161     double _tgt_x_offset;
162     double _tgt_y_offset;
163     double _tgt_z_offset;
164     double _elapsed_time;
165
166     SGGeod _parentpos;
167     SGGeod _oldpos;
168     SGGeod _offsetpos;
169     SGGeod _oldoffsetpos;
170
171 private:
172
173     bool   _aero_stabilised; // if true, object will align with trajectory
174     double _drag_area;       // equivalent drag area in ft2
175     double _life_timer;      // seconds
176     double _buoyancy;        // fps^2
177     bool   _wind;            // if true, local wind will be applied to object
178     double _Cd;              // drag coefficient
179     double _mass;            // slugs
180     bool   _random;          // modifier for Cd, life, az
181     double _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     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     //SGPropertyNode_ptr _pnode; // node for parent model
201     //SGPropertyNode_ptr _p_pos_node; // nodes for parent parameters
202     //SGPropertyNode_ptr _p_lat_node;
203     //SGPropertyNode_ptr _p_lon_node;
204     //SGPropertyNode_ptr _p_alt_node;
205     //SGPropertyNode_ptr _p_agl_node;
206     //SGPropertyNode_ptr _p_ori_node;
207     //SGPropertyNode_ptr _p_pch_node;
208     //SGPropertyNode_ptr _p_rll_node;
209     //SGPropertyNode_ptr _p_hdg_node;
210     //SGPropertyNode_ptr _p_vel_node;
211     //SGPropertyNode_ptr _p_spd_node;
212
213     double _fuse_range;
214     double _distance;
215     double _dt_count;
216     double _next_run;
217
218     string _submodel;
219     string _force_path;
220     string _contents_path;
221
222     void handle_collision();
223     void handle_expiry();
224     void handle_impact();
225     void report_impact(double elevation, const FGAIBase *target = 0);
226     void slaveToAC(double dt);
227     void setContents(double c);
228     void calcVSHS();
229     void calcNE();
230     //void setOffsetPos(SGGeod pos, double heading, double pitch, double roll);
231     //void setOffsetVelocity(double dt, SGGeod pos);
232
233     SGVec3d getCartUserPos() const;
234     SGVec3d getCartOffsetPos(SGGeod pos, double heading, double pitch, double roll) const;
235
236     //double getDistanceLoadToHitch() const;
237     //double getElevLoadToHitch() const;
238     //double getBearingLoadToHitch() const;
239     double getRecip(double az);
240     double getMass() const;
241
242     double _ground_offset;
243     double _load_offset;
244     double _old_height;
245
246     SGVec3d _oldcartoffsetPos;
247     SGVec3d _oldcartPos;
248
249     //SGGeod _parentpos;
250     //SGGeod _oldpos;
251     //SGGeod _offsetpos;
252     //SGGeod _oldoffsetpos;
253
254 };
255
256 #endif  // _FG_AIBALLISTIC_HXX