]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIBallistic.hxx
assign a unique module name to ai/mp embedded nasal (again): __model%u
[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     virtual osg::Node* load3DModel(const string &path,
47                            SGPropertyNode *prop_root);
48     bool init(bool search_in_AI_path=false);
49     virtual void bind();
50     virtual void unbind();
51
52     void update(double dt);
53
54     FGAIBallistic *ballistic;
55
56     void Run(double dt);
57
58     void setAzimuth( double az );
59     void setElevation( double el );
60     void setRoll( double rl );
61     void setStabilisation( bool val );
62     void setDragArea( double a );
63     void setLife( double seconds );
64     void setBuoyancy( double fpss );
65     void setWind_from_east( double fps );
66     void setWind_from_north( double fps );
67     void setWind( bool val );
68     void setCd( double c );
69     void setMass( double m );
70     void setWeight( double w );
71     void setNoRoll( bool nr );
72     void setRandom( bool r );
73     void setName(const string&);
74     void setCollision(bool c);
75     void setImpact(bool i);
76     void setImpactReportNode(const string&);
77     void setContentsNode(const string&);
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 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 setHitchPos();
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 setHitchVelocity(double dt);
95     void setFormate(bool f);
96
97     double _getTime() const;
98     double getRelBrgHitchToUser() const;
99     double getElevHitchToUser() const;
100     double getLoadOffset() const;
101     double getContents();
102
103     SGVec3d getCartHitchPos() const;
104
105     bool getHtAGL();
106     bool getSlaved() const;
107     bool getSlavedLoad() const;
108
109     virtual const char* getTypeString(void) const { return "ballistic"; }
110     static const double slugs_to_kgs; //conversion factor
111     static const double slugs_to_lbs; //conversion factor
112
113     SGPropertyNode_ptr _force_node;
114     SGPropertyNode_ptr _force_azimuth_node;
115     SGPropertyNode_ptr _force_elevation_node;
116
117     SGGeod hitchpos;
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
125     bool   _formate_to_ac;
126
127     void setTgtXOffset(double x);
128     void setTgtYOffset(double y);
129     void setTgtZOffset(double z);
130     void setTgtOffsets(double dt, double c);
131
132     double getTgtXOffset() const;
133     double getTgtYOffset() const;
134     double getTgtZOffset() const;
135
136     double _tgt_x_offset;
137     double _tgt_y_offset;
138     double _tgt_z_offset;
139     double _elapsed_time;
140
141 private:
142
143     virtual void reinit() { init(); }
144
145     bool   _aero_stabilised; // if true, object will align with trajectory
146     double _drag_area;       // equivalent drag area in ft2
147     double _life_timer;      // seconds
148     double _gravity;         // fps^2
149     double _buoyancy;        // fps^2
150     double _wind_from_east;  // fps
151     double _wind_from_north; // fps
152     bool   _wind;            // if true, local wind will be applied to object
153     double _Cd;              // drag coefficient
154     double _mass;            // slugs
155     bool   _random;          // modifier for Cd
156     double _load_resistance; // ground load resistanc N/m^2
157     double _frictionFactor;  // dimensionless modifier for Coefficient of Friction
158     bool   _solid;           // if true ground is solid for FDMs
159     double _elevation_m;     // ground elevation in meters
160     bool   _force_stabilised;// if true, object will align to external force
161     bool   _slave_to_ac;     // if true, object will be slaved to the parent ac pos and orientation
162     bool   _slave_load_to_ac;// if true, object will be slaved to the parent ac pos
163     double _contents_lb;     // contents of the object
164     double _weight_lb;       // weight of the object (no contents if appropriate) (lbs)
165
166     bool   _report_collision;       // if true a collision point with AI Objects is calculated
167     bool   _report_impact;          // if true an impact point on the terrain is calculated
168     bool   _external_force;         // if true then apply external force
169
170     SGPropertyNode_ptr _impact_report_node;  // report node for impact and collision
171     SGPropertyNode_ptr _contents_node;  // report node for impact and collision
172
173     double _fuse_range;
174     double _distance;
175     double _dt_count;
176     double _next_run;
177
178     string _name;
179     string _path;
180     string _submodel;
181     string _force_path;
182
183     const SGMaterial* _material;
184
185     void handle_collision();
186     void handle_impact();
187     void report_impact(double elevation, const FGAIBase *target = 0);
188     void slaveToAC(double dt);
189     void setContents(double c);
190     void formateToAC(double dt);
191
192     SGVec3d getCartUserPos() const;
193
194     double getDistanceLoadToHitch() const;
195     double getElevLoadToHitch() const;
196     double getBearingLoadToHitch() const;
197     double getRecip(double az);
198     double getMass() const;
199
200     double hs;
201     double _ground_offset;
202     double _load_offset;
203     double _force;
204     double _old_height;
205
206     SGVec3d _oldcarthitchPos;
207
208     SGGeod oldhitchpos;
209
210 };
211
212 #endif  // _FG_AIBALLISTIC_HXX