1 // FGAIBallistic.hxx - AIBase derived class creates an AI ballistic object
3 // Written by David Culp, started November 2003.
4 // - davidculp2@comcast.net
6 // With major additions by Vivian Meazza, Feb 2008
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.
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.
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.
22 #ifndef _FG_AIBALLISTIC_HXX
23 #define _FG_AIBALLISTIC_HXX
27 #include <simgear/structure/SGSharedPtr.hxx>
28 #include <simgear/scene/material/mat.hxx>
31 #include "AIManager.hxx"
34 class FGAIBallistic : public FGAIBase {
38 FGAIBallistic(object_type ot = otBallistic);
41 void readFromScenario(SGPropertyNode* scFileNode);
43 bool init(bool search_in_AI_path=false);
45 virtual void reinit();
46 virtual void update(double dt);
48 virtual const char* getTypeString(void) const { return "ballistic"; }
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 c );
63 void setMass( double m );
64 void setWeight( double w );
65 void setNoRoll( bool nr );
66 void setRandom( bool r );
67 void setRandomness( double r );
68 // void setName(const string&);
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&);
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);
93 void setOffsetPos(SGGeod pos, double heading, double pitch, double roll);
94 void setOffsetVelocity(double dt, SGGeod pos);
95 void setTime(double sec);
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;
106 SGVec3d getCartHitchPos() const;
108 bool getHtAGL(double start);
109 bool getSlaved() const;
110 // bool getFormate() const;
111 bool getSlavedLoad() const;
113 FGAIBallistic *ballistic;
115 static const double slugs_to_kgs; //conversion factor
116 static const double slugs_to_lbs; //conversion factor
118 SGPropertyNode_ptr _force_node;
119 SGPropertyNode_ptr _force_azimuth_node;
120 SGPropertyNode_ptr _force_elevation_node;
122 SGPropertyNode_ptr _pnode; // node for parent model
123 SGPropertyNode_ptr _p_pos_node; // nodes for parent parameters
124 SGPropertyNode_ptr _p_lat_node;
125 SGPropertyNode_ptr _p_lon_node;
126 SGPropertyNode_ptr _p_alt_node;
127 SGPropertyNode_ptr _p_agl_node;
128 SGPropertyNode_ptr _p_ori_node;
129 SGPropertyNode_ptr _p_pch_node;
130 SGPropertyNode_ptr _p_rll_node;
131 SGPropertyNode_ptr _p_hdg_node;
132 SGPropertyNode_ptr _p_vel_node;
133 SGPropertyNode_ptr _p_spd_node;
137 double _ht_agl_ft; // height above ground level
138 double _azimuth; // degrees true
139 double _elevation; // degrees
140 double _rotation; // degrees
141 double _speed_north_fps;
142 double _speed_east_fps;
143 double _wind_from_east; // fps
144 double _wind_from_north; // fps
149 void setTgtXOffset(double x);
150 void setTgtYOffset(double y);
151 void setTgtZOffset(double z);
152 void setTgtOffsets(double dt, double c);
154 double getTgtXOffset() const;
155 double getTgtYOffset() const;
156 double getTgtZOffset() const;
158 double _tgt_x_offset;
159 double _tgt_y_offset;
160 double _tgt_z_offset;
161 double _elapsed_time;
166 SGGeod _oldoffsetpos;
170 bool _aero_stabilised; // if true, object will align with trajectory
171 double _drag_area; // equivalent drag area in ft2
172 double _life_timer; // seconds
173 double _buoyancy; // fps^2
174 bool _wind; // if true, local wind will be applied to object
175 double _Cd; // drag coefficient
176 double _mass; // slugs
177 bool _random; // modifier for Cd, life, az
178 double _randomness; // dimension for _random, only applies to life at present
179 double _load_resistance; // ground load resistanc N/m^2
180 double _frictionFactor; // dimensionless modifier for Coefficient of Friction
181 bool _solid; // if true ground is solid for FDMs
182 double _elevation_m; // ground elevation in meters
183 bool _force_stabilised;// if true, object will align to external force
184 bool _slave_to_ac; // if true, object will be slaved to the parent ac pos and orientation
185 bool _slave_load_to_ac;// if true, object will be slaved to the parent ac pos
186 double _contents_lb; // contents of the object
187 double _weight_lb; // weight of the object (no contents if appropriate) (lbs)
188 std::string _mat_name;
190 bool _report_collision; // if true a collision point with AI Objects is calculated
191 bool _report_impact; // if true an impact point on the terrain is calculated
192 bool _external_force; // if true then apply external force
195 SGPropertyNode_ptr _impact_report_node; // report node for impact and collision
196 SGPropertyNode_ptr _contents_node; // node for droptank etc. contents
197 //SGPropertyNode_ptr _pnode; // node for parent model
198 //SGPropertyNode_ptr _p_pos_node; // nodes for parent parameters
199 //SGPropertyNode_ptr _p_lat_node;
200 //SGPropertyNode_ptr _p_lon_node;
201 //SGPropertyNode_ptr _p_alt_node;
202 //SGPropertyNode_ptr _p_agl_node;
203 //SGPropertyNode_ptr _p_ori_node;
204 //SGPropertyNode_ptr _p_pch_node;
205 //SGPropertyNode_ptr _p_rll_node;
206 //SGPropertyNode_ptr _p_hdg_node;
207 //SGPropertyNode_ptr _p_vel_node;
208 //SGPropertyNode_ptr _p_spd_node;
212 std::string _submodel;
213 std::string _force_path;
214 std::string _contents_path;
216 void handle_collision();
217 void handle_expiry();
218 void handle_impact();
219 void report_impact(double elevation, const FGAIBase *target = 0);
220 void slaveToAC(double dt);
221 void setContents(double c);
224 //void setOffsetPos(SGGeod pos, double heading, double pitch, double roll);
225 //void setOffsetVelocity(double dt, SGGeod pos);
227 SGVec3d getCartOffsetPos(SGGeod pos, double heading, double pitch, double roll) const;
229 //double getDistanceLoadToHitch() const;
230 //double getElevLoadToHitch() const;
231 //double getBearingLoadToHitch() const;
232 double getRecip(double az);
233 double getMass() const;
235 double _ground_offset;
238 SGVec3d _oldcartoffsetPos;
244 //SGGeod _oldoffsetpos;
248 #endif // _FG_AIBALLISTIC_HXX