]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/Model.hpp
Cleanup and refactoring to better integrate the helicopter code into
[flightgear.git] / src / FDM / YASim / Model.hpp
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
9 namespace yasim {
10
11 // Declare the types whose pointers get passed around here
12 class Integrator;
13 class Thruster;
14 class Surface;
15 class Rotorpart;
16 class Rotorblade;
17 class Rotor;
18 class Gear;
19
20 class Model : public BodyEnvironment {
21 public:
22     Model();
23     virtual ~Model();
24
25     RigidBody* getBody();
26     Integrator* getIntegrator();
27
28     State* getState();
29     void setState(State* s);
30
31     bool isCrashed();
32     void setCrashed(bool crashed);
33     float getAGL();
34
35     void iterate();
36
37     // Externally-managed subcomponents
38     int addThruster(Thruster* t);
39     int addSurface(Surface* surf);
40     int addRotorpart(Rotorpart* rpart);
41     int addRotorblade(Rotorblade* rblade);
42     int addRotor(Rotor* rotor);
43     int addGear(Gear* gear);
44     Surface* getSurface(int handle);
45     Rotorpart* getRotorpart(int handle);
46     Rotorblade* getRotorblade(int handle);
47     Rotor* getRotor(int handle);
48     Gear* getGear(int handle);
49
50     // Semi-private methods for use by the Airplane solver.
51     int numThrusters();
52     Thruster* getThruster(int handle);
53     void setThruster(int handle, Thruster* t);
54     void initIteration();
55     void getThrust(float* out);
56
57     //
58     // Per-iteration settables
59     //
60     void setGroundPlane(double* planeNormal, double fromOrigin);
61     void setGroundEffect(float* pos, float span, float mul);
62     void setWind(float* wind);
63     void setAir(float pressure, float temp, float density);
64
65     // BodyEnvironment callbacks
66     virtual void calcForces(State* s);
67     virtual void newState(State* s);
68
69 private:
70     void initRotorIteration();
71     void calcGearForce(Gear* g, float* v, float* rot, float* ground);
72     float gearFriction(float wgt, float v, Gear* g);
73     float localGround(State* s, float* out);
74     void localWind(float* pos, State* s, float* out);
75
76     Integrator _integrator;
77     RigidBody _body;
78
79     Vector _thrusters;
80     Vector _surfaces;
81     Vector _rotorparts;
82     Vector _rotorblades;
83     Vector _rotors;
84     Vector _gears;
85
86     float _groundEffectSpan;
87     float _groundEffect;
88     float _wingCenter[3];
89
90     double _ground[4];
91     float _pressure;
92     float _temp;
93     float _rho;
94     float _wind[3];
95
96     // Accumulators for the total internal gyro and engine torque
97     float _gyro[3];
98     float _torque[3];
99
100     State* _s;
101     bool _crashed;
102     float _agl;
103 };
104
105 }; // namespace yasim
106 #endif // _MODEL_HPP