]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIBallistic.hxx
Merge branches 'jmt/xmlauto', 'luff/kln89' and 'curt/radial'
[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 setName(const string&);
72     void setCollision(bool c);
73     void setImpact(bool i);
74     void setImpactReportNode(const string&);
75     void setContentsNode(const string&);
76     void setFuseRange(double f);
77     void setSMPath(const string&);
78     void setSubID(int i);
79     void setSubmodel(const string&);
80     void setExternalForce( bool f );
81     void setForcePath(const string&);
82     void setForceStabilisation( bool val );
83     void setGroundOffset(double g);
84     void setLoadOffset(double l);
85     void setSlaved(bool s);
86     void setSlavedLoad(bool s);
87     void setHitchPos();
88     void setPch (double e, double dt, double c);
89     void 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 setHitchVelocity(double dt);
93     void setFormate(bool f);
94
95     double _getTime() const;
96     double getRelBrgHitchToUser() const;
97     double getElevHitchToUser() const;
98     double getLoadOffset() const;
99     double getContents();
100
101     SGVec3d getCartHitchPos() const;
102
103     bool getHtAGL();
104     bool getSlaved() const;
105     bool getSlavedLoad() const;
106
107     virtual const char* getTypeString(void) const { return "ballistic"; }
108     static const double slugs_to_kgs; //conversion factor
109     static const double slugs_to_lbs; //conversion factor
110
111     SGPropertyNode_ptr _force_node;
112     SGPropertyNode_ptr _force_azimuth_node;
113     SGPropertyNode_ptr _force_elevation_node;
114
115     SGGeod hitchpos;
116
117     double _height;
118     double _ht_agl_ft;       // height above ground level
119     double _azimuth;         // degrees true
120     double _elevation;       // degrees
121     double _rotation;        // degrees
122
123     bool   _formate_to_ac;
124
125     void setTgtXOffset(double x);
126     void setTgtYOffset(double y);
127     void setTgtZOffset(double z);
128     void setTgtOffsets(double dt, double c);
129
130     double getTgtXOffset() const;
131     double getTgtYOffset() const;
132     double getTgtZOffset() const;
133
134     double _tgt_x_offset;
135     double _tgt_y_offset;
136     double _tgt_z_offset;
137     double _elapsed_time;
138
139 private:
140
141     virtual void reinit() { init(); }
142
143     bool   _aero_stabilised; // if true, object will align with trajectory
144     double _drag_area;       // equivalent drag area in ft2
145     double _life_timer;      // seconds
146     double _gravity;         // fps^2
147     double _buoyancy;        // fps^2
148     double _wind_from_east;  // fps
149     double _wind_from_north; // fps
150     bool   _wind;            // if true, local wind will be applied to object
151     double _Cd;              // drag coefficient
152     double _mass;            // slugs
153     bool   _random;          // modifier for Cd
154     double _load_resistance; // ground load resistanc N/m^2
155     double _frictionFactor;  // dimensionless modifier for Coefficient of Friction
156     bool   _solid;           // if true ground is solid for FDMs
157     double _elevation_m;     // ground elevation in meters
158     bool   _force_stabilised;// if true, object will align to external force
159     bool   _slave_to_ac;     // if true, object will be slaved to the parent ac pos and orientation
160     bool   _slave_load_to_ac;// if true, object will be slaved to the parent ac pos
161     double _contents_lb;     // contents of the object
162     double _weight_lb;       // weight of the object (no contents if appropriate) (lbs)
163
164     bool   _report_collision;       // if true a collision point with AI Objects is calculated
165     bool   _report_impact;          // if true an impact point on the terrain is calculated
166     bool   _external_force;         // if true then apply external force
167
168     SGPropertyNode_ptr _impact_report_node;  // report node for impact and collision
169     SGPropertyNode_ptr _contents_node;  // report node for impact and collision
170
171     double _fuse_range;
172     double _distance;
173     double _dt_count;
174     double _next_run;
175
176     string _name;
177     string _path;
178     string _submodel;
179     string _force_path;
180
181     const SGMaterial* _material;
182
183     void handle_collision();
184     void handle_impact();
185     void report_impact(double elevation, const FGAIBase *target = 0);
186     void slaveToAC(double dt);
187     void setContents(double c);
188     void formateToAC(double dt);
189
190     SGVec3d getCartUserPos() const;
191
192     double getDistanceLoadToHitch() const;
193     double getElevLoadToHitch() const;
194     double getBearingLoadToHitch() const;
195     double getRecip(double az);
196     double getMass() const;
197
198     double hs;
199     double _ground_offset;
200     double _load_offset;
201     double _force;
202     double _old_height;
203
204     SGVec3d _oldcarthitchPos;
205
206     SGGeod oldhitchpos;
207
208 };
209
210 #endif  // _FG_AIBALLISTIC_HXX