| 1 | #ifndef _THRUSTER_HPP |
| 2 | #define _THRUSTER_HPP |
| 3 | |
| 4 | #include "Atmosphere.hpp" |
| 5 | #include "Math.hpp" |
| 6 | |
| 7 | namespace yasim { |
| 8 | |
| 9 | class Jet; |
| 10 | class PropEngine; |
| 11 | class Propeller; |
| 12 | class Engine; |
| 13 | |
| 14 | class Thruster { |
| 15 | public: |
| 16 | Thruster() {}; |
| 17 | virtual ~Thruster() {}; |
| 18 | |
| 19 | // Typing info, these are the possible sub-type (or sub-parts) |
| 20 | // that a thruster might have. Any might return null. A little |
| 21 | // clumsy, but much simpler than an RTTI-based implementation. |
| 22 | virtual Jet* getJet() { return 0; } |
| 23 | virtual PropEngine* getPropEngine() { return 0; } |
| 24 | virtual Propeller* getPropeller() { return 0; } |
| 25 | virtual Engine* getEngine() { return 0; } |
| 26 | |
| 27 | // Static data |
| 28 | void getPosition(float* out) const { Math::set3(_pos, out); } |
| 29 | void setPosition(const float* pos) { Math::set3(pos, _pos); } |
| 30 | void getDirection(float* out) const { Math::set3(_dir, out); } |
| 31 | void setDirection(const float* dir) { Math::unit3(dir, _dir); } |
| 32 | |
| 33 | // Controls |
| 34 | void setThrottle(float throttle) { _throttle = Math::clamp(throttle, -1, 1); } |
| 35 | void setMixture(float mixture) { _mixture = Math::clamp(mixture, 0, 1); } |
| 36 | void setStarter(bool starter) { _starter = starter; } |
| 37 | void setFuelState(bool hasFuel) { _fuel = hasFuel; } |
| 38 | |
| 39 | // Dynamic output |
| 40 | virtual bool isRunning()=0; |
| 41 | virtual bool isCranking()=0; |
| 42 | virtual void getThrust(float* out)=0; |
| 43 | virtual void getTorque(float* out)=0; |
| 44 | virtual void getGyro(float* out)=0; |
| 45 | virtual float getFuelFlow()=0; // in kg/s |
| 46 | |
| 47 | // Runtime instructions |
| 48 | void setWind(const float* wind) { Math::set3(wind, _wind); }; |
| 49 | void setAtmosphere(Atmosphere a) { _atmo = a; }; |
| 50 | void setStandardAtmosphere(float altitude) { _atmo.setStandard(altitude); }; |
| 51 | virtual void init() {} |
| 52 | virtual void integrate(float dt)=0; |
| 53 | virtual void stabilize()=0; |
| 54 | |
| 55 | protected: |
| 56 | float _pos[3] {0, 0, 0}; |
| 57 | float _dir[3] {1, 0, 0}; |
| 58 | float _throttle = 0; |
| 59 | float _mixture = 0; |
| 60 | bool _starter = false; // true=engaged, false=disengaged |
| 61 | bool _fuel; // true=available, false=out |
| 62 | |
| 63 | float _wind[3] {0, 0, 0}; |
| 64 | Atmosphere _atmo; |
| 65 | }; |
| 66 | |
| 67 | }; // namespace yasim |
| 68 | #endif // _THRUSTER_HPP |