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"
37 class FGAIBallistic : public FGAIBase {
41 FGAIBallistic(object_type ot = otBallistic);
44 void readFromScenario(SGPropertyNode* scFileNode);
46 bool init(bool search_in_AI_path=false);
48 virtual void unbind();
50 void update(double dt);
52 FGAIBallistic *ballistic;
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 setRandomness( double r );
72 // void setName(const string&);
73 void setCollision(bool c);
74 void setExpiry(bool e);
75 void setImpact(bool i);
76 void setImpactReportNode(const string&);
77 void setContentsNode(const SGPropertyNode_ptr);
78 void setFuseRange(double f);
79 void setSMPath(const string&);
81 void setSubmodel(const string&);
82 void setExternalForce( bool f );
83 void setForcePath(const string&);
84 void setContentsPath(const string&);
85 void setForceStabilisation( bool val );
86 void setGroundOffset(double g);
87 void setLoadOffset(double l);
88 void setSlaved(bool s);
89 void setSlavedLoad(bool s);
90 void setPch (double e, double dt, double c);
91 int 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 setSpd(double s, double dt, double c);
95 void setParentNodes(const SGPropertyNode_ptr);
97 void setOffsetPos(SGGeod pos, double heading, double pitch, double roll);
98 void setOffsetVelocity(double dt, SGGeod pos);
101 double _getTime() const;
102 double getRelBrgHitchToUser() const;
103 double getElevHitchToUser() const;
104 double getLoadOffset() const;
105 double getContents();
106 double getDistanceToHitch() const;
107 double getElevToHitch() const;
108 double getBearingToHitch() const;
110 SGVec3d getCartHitchPos() const;
112 bool getHtAGL(double start);
113 bool getSlaved() const;
114 // bool getFormate() const;
115 bool getSlavedLoad() const;
117 virtual const char* getTypeString(void) const { return "ballistic"; }
118 static const double slugs_to_kgs; //conversion factor
119 static const double slugs_to_lbs; //conversion factor
121 SGPropertyNode_ptr _force_node;
122 SGPropertyNode_ptr _force_azimuth_node;
123 SGPropertyNode_ptr _force_elevation_node;
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;
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
152 void setTgtXOffset(double x);
153 void setTgtYOffset(double y);
154 void setTgtZOffset(double z);
155 void setTgtOffsets(double dt, double c);
157 double getTgtXOffset() const;
158 double getTgtYOffset() const;
159 double getTgtZOffset() const;
161 double _tgt_x_offset;
162 double _tgt_y_offset;
163 double _tgt_z_offset;
164 double _elapsed_time;
169 SGGeod _oldoffsetpos;
173 virtual void reinit() { init(); }
175 bool _aero_stabilised; // if true, object will align with trajectory
176 double _drag_area; // equivalent drag area in ft2
177 double _life_timer; // seconds
178 double _gravity; // fps^2
179 double _buoyancy; // fps^2
180 bool _wind; // if true, local wind will be applied to object
181 double _Cd; // drag coefficient
182 double _mass; // slugs
183 bool _random; // modifier for Cd, life, az
184 double _randomness; // dimension for _random, only applies to life at present
185 double _load_resistance; // ground load resistanc N/m^2
186 double _frictionFactor; // dimensionless modifier for Coefficient of Friction
187 bool _solid; // if true ground is solid for FDMs
188 double _elevation_m; // ground elevation in meters
189 bool _force_stabilised;// if true, object will align to external force
190 bool _slave_to_ac; // if true, object will be slaved to the parent ac pos and orientation
191 bool _slave_load_to_ac;// if true, object will be slaved to the parent ac pos
192 double _contents_lb; // contents of the object
193 double _weight_lb; // weight of the object (no contents if appropriate) (lbs)
196 bool _report_collision; // if true a collision point with AI Objects is calculated
197 bool _report_impact; // if true an impact point on the terrain is calculated
198 bool _external_force; // if true then apply external force
201 SGPropertyNode_ptr _impact_report_node; // report node for impact and collision
202 SGPropertyNode_ptr _contents_node; // node for droptank etc. contents
203 //SGPropertyNode_ptr _pnode; // node for parent model
204 //SGPropertyNode_ptr _p_pos_node; // nodes for parent parameters
205 //SGPropertyNode_ptr _p_lat_node;
206 //SGPropertyNode_ptr _p_lon_node;
207 //SGPropertyNode_ptr _p_alt_node;
208 //SGPropertyNode_ptr _p_agl_node;
209 //SGPropertyNode_ptr _p_ori_node;
210 //SGPropertyNode_ptr _p_pch_node;
211 //SGPropertyNode_ptr _p_rll_node;
212 //SGPropertyNode_ptr _p_hdg_node;
213 //SGPropertyNode_ptr _p_vel_node;
214 //SGPropertyNode_ptr _p_spd_node;
223 string _contents_path;
225 const SGMaterial* _material;
227 void handle_collision();
228 void handle_expiry();
229 void handle_impact();
230 void report_impact(double elevation, const FGAIBase *target = 0);
231 void slaveToAC(double dt);
232 void setContents(double c);
235 //void setOffsetPos(SGGeod pos, double heading, double pitch, double roll);
236 //void setOffsetVelocity(double dt, SGGeod pos);
238 SGVec3d getCartUserPos() const;
239 SGVec3d getCartOffsetPos(SGGeod pos, double heading, double pitch, double roll) const;
241 //double getDistanceLoadToHitch() const;
242 //double getElevLoadToHitch() const;
243 //double getBearingLoadToHitch() const;
244 double getRecip(double az);
245 double getMass() const;
247 double _ground_offset;
251 SGVec3d _oldcartoffsetPos;
257 //SGGeod _oldoffsetpos;
261 #endif // _FG_AIBALLISTIC_HXX