| 1 | #ifndef _MODEL_HPP |
| 2 | #define _MODEL_HPP |
| 3 | |
| 4 | #include "Integrator.hpp" |
| 5 | #include "RigidBody.hpp" |
| 6 | #include "BodyEnvironment.hpp" |
| 7 | #include "Vector.hpp" |
| 8 | #include "Turbulence.hpp" |
| 9 | #include "Rotor.hpp" |
| 10 | #include "Atmosphere.hpp" |
| 11 | #include <simgear/props/props.hxx> |
| 12 | |
| 13 | namespace yasim { |
| 14 | |
| 15 | // Declare the types whose pointers get passed around here |
| 16 | class Integrator; |
| 17 | class Thruster; |
| 18 | class Surface; |
| 19 | class Rotorpart; |
| 20 | class Gear; |
| 21 | class Ground; |
| 22 | class Hook; |
| 23 | class Launchbar; |
| 24 | class Hitch; |
| 25 | |
| 26 | class Model : public BodyEnvironment { |
| 27 | public: |
| 28 | Model(); |
| 29 | virtual ~Model(); |
| 30 | |
| 31 | RigidBody* getBody() { return &_body; } |
| 32 | void getCG(float* cg) const { return _body.getCG(cg); } |
| 33 | float getMass() const {return _body.getTotalMass(); } |
| 34 | Integrator* getIntegrator() { return &_integrator; } |
| 35 | |
| 36 | void setTurbulence(Turbulence* turb) { _turb = turb; } |
| 37 | |
| 38 | State* getState() const { return _s; } |
| 39 | void setState(State* s); |
| 40 | |
| 41 | bool isCrashed() const { return _crashed; } |
| 42 | void setCrashed(bool crashed) { _crashed = crashed; } |
| 43 | float getAGL() const { return _agl; } |
| 44 | |
| 45 | void iterate(); |
| 46 | |
| 47 | // Externally-managed subcomponents |
| 48 | int addThruster(Thruster* t) { return _thrusters.add(t); } |
| 49 | int addSurface(Surface* surf) { return _surfaces.add(surf); } |
| 50 | int addGear(Gear* gear) { return _gears.add(gear); } |
| 51 | void addHook(Hook* hook) { _hook = hook; } |
| 52 | void addLaunchbar(Launchbar* launchbar) { _launchbar = launchbar; } |
| 53 | Surface* getSurface(int handle) const { return (Surface*)_surfaces.get(handle); } |
| 54 | Rotorgear* getRotorgear(void) { return &_rotorgear; } |
| 55 | Hook* getHook(void) const { return _hook; } |
| 56 | int addHitch(Hitch* hitch) { return _hitches.add(hitch); } |
| 57 | Launchbar* getLaunchbar(void) const { return _launchbar; } |
| 58 | |
| 59 | // Semi-private methods for use by the Airplane solver. |
| 60 | int numThrusters() const { return _thrusters.size(); } |
| 61 | Thruster* getThruster(int handle) { return (Thruster*)_thrusters.get(handle); } |
| 62 | void setThruster(int handle, Thruster* t) { _thrusters.set(handle, t); } |
| 63 | void initIteration(); |
| 64 | void getThrust(float* out) const; |
| 65 | |
| 66 | void setGroundCallback(Ground* ground_cb); |
| 67 | Ground* getGroundCallback(void) { return _ground_cb; } |
| 68 | |
| 69 | // |
| 70 | // Per-iteration settables |
| 71 | // |
| 72 | void setGroundEffect(const float* pos, float span, float mul); |
| 73 | void setWind(float* wind) { Math::set3(wind, _wind); } |
| 74 | void setAtmosphere(Atmosphere a) { _atmo = a; }; |
| 75 | void setStandardAtmosphere(float altitude) { _atmo.setStandard(altitude); }; |
| 76 | |
| 77 | void updateGround(State* s); |
| 78 | |
| 79 | // BodyEnvironment callbacks |
| 80 | virtual void calcForces(State* s); |
| 81 | virtual void newState(State* s); |
| 82 | |
| 83 | private: |
| 84 | void initRotorIteration(); |
| 85 | void calcGearForce(Gear* g, float* v, float* rot, float* ground); |
| 86 | float gearFriction(float wgt, float v, Gear* g); |
| 87 | void localWind(const float* pos, const yasim::State* s, float* out, float alt, bool is_rotor = false); |
| 88 | |
| 89 | Integrator _integrator; |
| 90 | RigidBody _body; |
| 91 | |
| 92 | Turbulence* _turb {nullptr}; |
| 93 | |
| 94 | Vector _thrusters; |
| 95 | Vector _surfaces; |
| 96 | Rotorgear _rotorgear; |
| 97 | Vector _gears; |
| 98 | Hook* _hook {nullptr}; |
| 99 | Launchbar* _launchbar {nullptr}; |
| 100 | Vector _hitches; |
| 101 | |
| 102 | float _wingSpan {0}; |
| 103 | float _groundEffect {0}; |
| 104 | float _geRefPoint[3] {0,0,0}; |
| 105 | |
| 106 | Ground* _ground_cb; |
| 107 | double _global_ground[4] {0,0,1, -1e5}; |
| 108 | Atmosphere _atmo; |
| 109 | float _wind[3] {0,0,0}; |
| 110 | |
| 111 | |
| 112 | // Accumulators for the total internal gyro and engine torque |
| 113 | float _gyro[3] {0,0,0}; |
| 114 | float _torque[3] {0,0,0}; |
| 115 | |
| 116 | State* _s; |
| 117 | bool _crashed {false}; |
| 118 | float _agl {0}; |
| 119 | SGPropertyNode_ptr _modelN; |
| 120 | SGPropertyNode_ptr _fAeroXN; |
| 121 | SGPropertyNode_ptr _fAeroYN; |
| 122 | SGPropertyNode_ptr _fAeroZN; |
| 123 | SGPropertyNode_ptr _fSumXN; |
| 124 | SGPropertyNode_ptr _fSumYN; |
| 125 | SGPropertyNode_ptr _fSumZN; |
| 126 | SGPropertyNode_ptr _fGravXN; |
| 127 | SGPropertyNode_ptr _fGravYN; |
| 128 | SGPropertyNode_ptr _fGravZN; |
| 129 | SGPropertyNode_ptr _gefxN; |
| 130 | SGPropertyNode_ptr _gefyN; |
| 131 | SGPropertyNode_ptr _gefzN; |
| 132 | SGPropertyNode_ptr _wgdistN; |
| 133 | }; |
| 134 | |
| 135 | }; // namespace yasim |
| 136 | #endif // _MODEL_HPP |