2004-09-27 14:24:20 +00:00
|
|
|
// FGAIBallistic.hxx - AIBase derived class creates an AI ballistic object
|
2003-11-28 15:48:05 +00:00
|
|
|
//
|
|
|
|
// Written by David Culp, started November 2003.
|
|
|
|
// - davidculp2@comcast.net
|
|
|
|
//
|
2008-02-15 11:06:27 +00:00
|
|
|
// With major additions by Vivian Meazza, Feb 2008
|
|
|
|
//
|
2003-11-28 15:48:05 +00:00
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
2010-08-28 23:08:50 +00:00
|
|
|
// You should have received a copy of the GNU General Public License
|
2003-11-28 15:48:05 +00:00
|
|
|
// along with this program; if not, write to the Free Software
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-11-28 15:48:05 +00:00
|
|
|
|
|
|
|
#ifndef _FG_AIBALLISTIC_HXX
|
|
|
|
#define _FG_AIBALLISTIC_HXX
|
|
|
|
|
2015-03-24 16:11:42 +00:00
|
|
|
#include <cmath>
|
2007-06-07 16:30:26 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <simgear/structure/SGSharedPtr.hxx>
|
2008-01-04 22:31:18 +00:00
|
|
|
#include <simgear/scene/material/mat.hxx>
|
2007-06-07 16:30:26 +00:00
|
|
|
|
|
|
|
|
2003-11-28 15:48:05 +00:00
|
|
|
#include "AIManager.hxx"
|
|
|
|
#include "AIBase.hxx"
|
|
|
|
|
|
|
|
class FGAIBallistic : public FGAIBase {
|
2004-09-22 08:47:05 +00:00
|
|
|
|
2003-11-28 15:48:05 +00:00
|
|
|
public:
|
2004-09-22 08:47:05 +00:00
|
|
|
|
2008-02-15 11:06:27 +00:00
|
|
|
FGAIBallistic(object_type ot = otBallistic);
|
2003-11-28 15:48:05 +00:00
|
|
|
~FGAIBallistic();
|
2004-09-22 08:47:05 +00:00
|
|
|
|
2021-02-22 05:18:15 +00:00
|
|
|
void readFromScenario(SGPropertyNode* scFileNode) override;
|
2006-02-11 13:16:56 +00:00
|
|
|
|
2018-05-23 08:46:05 +00:00
|
|
|
bool init(ModelSearchOrder searchOrder) override;
|
2021-02-22 05:18:15 +00:00
|
|
|
void bind() override;
|
|
|
|
void reinit() override;
|
|
|
|
void update(double dt) override;
|
2007-03-30 22:51:52 +00:00
|
|
|
|
2021-02-22 05:18:15 +00:00
|
|
|
const char* getTypeString(void) const override { return "ballistic"; }
|
2008-02-15 11:06:27 +00:00
|
|
|
|
|
|
|
void Run(double dt);
|
|
|
|
|
2003-11-28 15:48:05 +00:00
|
|
|
void setAzimuth( double az );
|
|
|
|
void setElevation( double el );
|
2015-05-21 20:45:15 +00:00
|
|
|
void setAzimuthRandomError(double error);
|
|
|
|
void setElevationRandomError(double error);
|
2004-09-22 08:47:05 +00:00
|
|
|
void setRoll( double rl );
|
2004-10-28 08:29:15 +00:00
|
|
|
void setStabilisation( bool val );
|
2004-08-26 16:25:54 +00:00
|
|
|
void setDragArea( double a );
|
2004-08-30 09:11:59 +00:00
|
|
|
void setLife( double seconds );
|
2004-09-05 09:45:34 +00:00
|
|
|
void setBuoyancy( double fpss );
|
2004-09-08 14:02:25 +00:00
|
|
|
void setWind_from_east( double fps );
|
|
|
|
void setWind_from_north( double fps );
|
|
|
|
void setWind( bool val );
|
2015-05-20 22:23:33 +00:00
|
|
|
void setCd(double cd);
|
|
|
|
void setCdRandomness(double randomness);
|
2004-09-27 14:24:20 +00:00
|
|
|
void setMass( double m );
|
2008-02-15 11:06:27 +00:00
|
|
|
void setWeight( double w );
|
2007-03-30 22:51:52 +00:00
|
|
|
void setNoRoll( bool nr );
|
|
|
|
void setRandom( bool r );
|
2015-05-20 22:23:33 +00:00
|
|
|
void setLifeRandomness(double randomness);
|
2007-06-07 16:30:26 +00:00
|
|
|
void setCollision(bool c);
|
2010-08-28 23:00:09 +00:00
|
|
|
void setExpiry(bool e);
|
2007-05-15 16:19:11 +00:00
|
|
|
void setImpact(bool i);
|
2013-03-28 16:49:52 +00:00
|
|
|
void setImpactReportNode(const std::string&);
|
2010-08-28 23:00:09 +00:00
|
|
|
void setContentsNode(const SGPropertyNode_ptr);
|
2007-06-07 16:30:26 +00:00
|
|
|
void setFuseRange(double f);
|
2013-03-28 16:49:52 +00:00
|
|
|
void setSMPath(const std::string&);
|
2007-06-07 16:30:26 +00:00
|
|
|
void setSubID(int i);
|
2013-03-28 16:49:52 +00:00
|
|
|
void setSubmodel(const std::string&);
|
2007-12-21 23:37:05 +00:00
|
|
|
void setExternalForce( bool f );
|
2013-03-28 16:49:52 +00:00
|
|
|
void setForcePath(const std::string&);
|
|
|
|
void setContentsPath(const std::string&);
|
2008-01-04 22:31:18 +00:00
|
|
|
void setForceStabilisation( bool val );
|
2008-02-15 11:06:27 +00:00
|
|
|
void setGroundOffset(double g);
|
|
|
|
void setLoadOffset(double l);
|
|
|
|
void setSlaved(bool s);
|
|
|
|
void setSlavedLoad(bool s);
|
|
|
|
void setPch (double e, double dt, double c);
|
2010-09-27 22:50:44 +00:00
|
|
|
int setHdg (double az, double dt, double c);
|
2008-02-15 11:06:27 +00:00
|
|
|
void setBnk(double r, double dt, double c);
|
|
|
|
void setHt(double h, double dt, double c);
|
2010-09-27 22:50:44 +00:00
|
|
|
void setSpd(double s, double dt, double c);
|
2010-09-08 16:34:17 +00:00
|
|
|
void setParentNodes(const SGPropertyNode_ptr);
|
2010-08-28 23:00:09 +00:00
|
|
|
void setParentPos();
|
2010-09-27 22:50:44 +00:00
|
|
|
void setOffsetPos(SGGeod pos, double heading, double pitch, double roll);
|
|
|
|
void setOffsetVelocity(double dt, SGGeod pos);
|
2011-05-21 16:08:36 +00:00
|
|
|
void setTime(double sec);
|
2010-09-27 22:50:44 +00:00
|
|
|
|
2011-05-21 16:08:36 +00:00
|
|
|
double _getTime()const;
|
2008-02-15 11:06:27 +00:00
|
|
|
double getRelBrgHitchToUser() const;
|
|
|
|
double getElevHitchToUser() const;
|
|
|
|
double getLoadOffset() const;
|
|
|
|
double getContents();
|
2010-09-27 22:50:44 +00:00
|
|
|
double getDistanceToHitch() const;
|
|
|
|
double getElevToHitch() const;
|
|
|
|
double getBearingToHitch() const;
|
2008-02-15 11:06:27 +00:00
|
|
|
|
|
|
|
SGVec3d getCartHitchPos() const;
|
2008-01-04 22:31:18 +00:00
|
|
|
|
2010-08-28 23:00:09 +00:00
|
|
|
bool getHtAGL(double start);
|
2008-02-15 11:06:27 +00:00
|
|
|
bool getSlaved() const;
|
|
|
|
bool getSlavedLoad() const;
|
2004-09-22 08:47:05 +00:00
|
|
|
|
2011-12-09 16:06:19 +00:00
|
|
|
FGAIBallistic *ballistic;
|
|
|
|
|
2007-05-15 16:19:11 +00:00
|
|
|
static const double slugs_to_kgs; //conversion factor
|
2008-01-04 22:31:18 +00:00
|
|
|
static const double slugs_to_lbs; //conversion factor
|
2006-02-11 13:16:56 +00:00
|
|
|
|
2007-12-21 23:37:05 +00:00
|
|
|
SGPropertyNode_ptr _force_node;
|
|
|
|
SGPropertyNode_ptr _force_azimuth_node;
|
|
|
|
SGPropertyNode_ptr _force_elevation_node;
|
|
|
|
|
2015-05-20 22:23:33 +00:00
|
|
|
// Node for parent model
|
|
|
|
SGPropertyNode_ptr _pnode;
|
|
|
|
|
|
|
|
// Nodes for parent parameters
|
|
|
|
SGPropertyNode_ptr _p_pos_node;
|
2010-09-27 22:50:44 +00:00
|
|
|
SGPropertyNode_ptr _p_lat_node;
|
|
|
|
SGPropertyNode_ptr _p_lon_node;
|
|
|
|
SGPropertyNode_ptr _p_alt_node;
|
|
|
|
SGPropertyNode_ptr _p_agl_node;
|
|
|
|
SGPropertyNode_ptr _p_ori_node;
|
|
|
|
SGPropertyNode_ptr _p_pch_node;
|
|
|
|
SGPropertyNode_ptr _p_rll_node;
|
|
|
|
SGPropertyNode_ptr _p_hdg_node;
|
|
|
|
SGPropertyNode_ptr _p_vel_node;
|
|
|
|
SGPropertyNode_ptr _p_spd_node;
|
|
|
|
|
2008-02-15 11:06:27 +00:00
|
|
|
double _height;
|
2010-09-27 22:50:44 +00:00
|
|
|
double _speed;
|
2008-02-15 11:06:27 +00:00
|
|
|
double _ht_agl_ft; // height above ground level
|
2007-05-15 17:22:49 +00:00
|
|
|
double _azimuth; // degrees true
|
|
|
|
double _elevation; // degrees
|
|
|
|
double _rotation; // degrees
|
2010-08-28 23:00:09 +00:00
|
|
|
double _speed_north_fps;
|
|
|
|
double _speed_east_fps;
|
2010-09-27 22:50:44 +00:00
|
|
|
double _wind_from_east; // fps
|
|
|
|
double _wind_from_north; // fps
|
|
|
|
|
|
|
|
double hs;
|
2008-02-15 11:06:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
void setTgtXOffset(double x);
|
|
|
|
void setTgtYOffset(double y);
|
|
|
|
void setTgtZOffset(double z);
|
|
|
|
void setTgtOffsets(double dt, double c);
|
|
|
|
|
|
|
|
double getTgtXOffset() const;
|
|
|
|
double getTgtYOffset() const;
|
|
|
|
double getTgtZOffset() const;
|
|
|
|
|
|
|
|
double _tgt_x_offset;
|
|
|
|
double _tgt_y_offset;
|
|
|
|
double _tgt_z_offset;
|
|
|
|
double _elapsed_time;
|
|
|
|
|
2010-09-27 22:50:44 +00:00
|
|
|
SGGeod _parentpos;
|
|
|
|
SGGeod _oldpos;
|
|
|
|
SGGeod _offsetpos;
|
|
|
|
SGGeod _oldoffsetpos;
|
|
|
|
|
2008-02-15 11:06:27 +00:00
|
|
|
private:
|
|
|
|
|
2015-05-21 20:45:15 +00:00
|
|
|
double _az_random_error; // maximum azimuth error in degrees
|
|
|
|
double _el_random_error; // maximum elevation error in degrees
|
2007-05-15 17:22:49 +00:00
|
|
|
bool _aero_stabilised; // if true, object will align with trajectory
|
|
|
|
double _drag_area; // equivalent drag area in ft2
|
2015-05-21 20:45:15 +00:00
|
|
|
double _cd; // current drag coefficient
|
|
|
|
double _init_cd; // initial drag coefficient
|
2015-05-20 22:23:33 +00:00
|
|
|
double _cd_randomness; // randomness of Cd. 1.0 means +- 100%, 0.0 means no randomness
|
2015-05-28 22:32:57 +00:00
|
|
|
double _buoyancy; // fps^2
|
2015-05-20 22:23:33 +00:00
|
|
|
double _life_timer; // seconds
|
2015-05-22 03:09:02 +00:00
|
|
|
bool _wind; // if true, local wind will be applied to object
|
2007-05-15 17:22:49 +00:00
|
|
|
double _mass; // slugs
|
2010-07-28 21:20:50 +00:00
|
|
|
bool _random; // modifier for Cd, life, az
|
2015-05-20 22:23:33 +00:00
|
|
|
double _life_randomness; // dimension for _random, only applies to life at present
|
2007-05-15 17:22:49 +00:00
|
|
|
double _load_resistance; // ground load resistanc N/m^2
|
2008-01-04 22:31:18 +00:00
|
|
|
double _frictionFactor; // dimensionless modifier for Coefficient of Friction
|
2007-05-15 17:22:49 +00:00
|
|
|
bool _solid; // if true ground is solid for FDMs
|
2008-01-04 22:31:18 +00:00
|
|
|
double _elevation_m; // ground elevation in meters
|
|
|
|
bool _force_stabilised;// if true, object will align to external force
|
2008-02-15 11:06:27 +00:00
|
|
|
bool _slave_to_ac; // if true, object will be slaved to the parent ac pos and orientation
|
|
|
|
bool _slave_load_to_ac;// if true, object will be slaved to the parent ac pos
|
|
|
|
double _contents_lb; // contents of the object
|
|
|
|
double _weight_lb; // weight of the object (no contents if appropriate) (lbs)
|
2013-03-28 16:49:52 +00:00
|
|
|
std::string _mat_name;
|
2007-06-07 16:30:26 +00:00
|
|
|
|
|
|
|
bool _report_collision; // if true a collision point with AI Objects is calculated
|
|
|
|
bool _report_impact; // if true an impact point on the terrain is calculated
|
2007-12-21 23:37:05 +00:00
|
|
|
bool _external_force; // if true then apply external force
|
2010-08-28 23:00:09 +00:00
|
|
|
bool _report_expiry;
|
2007-06-07 16:30:26 +00:00
|
|
|
|
|
|
|
SGPropertyNode_ptr _impact_report_node; // report node for impact and collision
|
2010-08-28 23:00:09 +00:00
|
|
|
SGPropertyNode_ptr _contents_node; // node for droptank etc. contents
|
2007-06-07 16:30:26 +00:00
|
|
|
|
|
|
|
double _fuse_range;
|
2007-05-15 19:45:41 +00:00
|
|
|
|
2013-03-28 16:49:52 +00:00
|
|
|
std::string _submodel;
|
|
|
|
std::string _force_path;
|
|
|
|
std::string _contents_path;
|
2004-09-22 08:47:05 +00:00
|
|
|
|
2015-05-20 22:23:33 +00:00
|
|
|
void handleEndOfLife(double);
|
2007-06-07 16:30:26 +00:00
|
|
|
void handle_collision();
|
2010-08-28 23:00:09 +00:00
|
|
|
void handle_expiry();
|
2007-05-15 16:19:11 +00:00
|
|
|
void handle_impact();
|
2007-06-07 16:30:26 +00:00
|
|
|
void report_impact(double elevation, const FGAIBase *target = 0);
|
2008-02-15 11:06:27 +00:00
|
|
|
void slaveToAC(double dt);
|
|
|
|
void setContents(double c);
|
2010-08-28 23:00:09 +00:00
|
|
|
void calcVSHS();
|
|
|
|
void calcNE();
|
2008-02-15 11:06:27 +00:00
|
|
|
|
2010-08-28 23:00:09 +00:00
|
|
|
SGVec3d getCartOffsetPos(SGGeod pos, double heading, double pitch, double roll) const;
|
2007-06-07 16:30:26 +00:00
|
|
|
|
2008-01-04 22:31:18 +00:00
|
|
|
double getRecip(double az);
|
2008-02-15 11:06:27 +00:00
|
|
|
double getMass() const;
|
|
|
|
|
|
|
|
double _ground_offset;
|
|
|
|
double _load_offset;
|
|
|
|
|
2010-08-28 23:00:09 +00:00
|
|
|
SGVec3d _oldcartoffsetPos;
|
|
|
|
SGVec3d _oldcartPos;
|
2003-11-28 15:48:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _FG_AIBALLISTIC_HXX
|