]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/Airplane.hpp
GUI ‘restore defaults’ support.
[flightgear.git] / src / FDM / YASim / Airplane.hpp
1 #ifndef _AIRPLANE_HPP
2 #define _AIRPLANE_HPP
3
4 #include "ControlMap.hpp"
5 #include "Model.hpp"
6 #include "Wing.hpp"
7 #include "Rotor.hpp"
8 #include "Vector.hpp"
9 #include "Version.hpp"
10
11 namespace yasim {
12
13 class Gear;
14 class Hook;
15 class Launchbar;
16 class Thruster;
17 class Hitch;
18
19 class Airplane : public Version {
20 public:
21     Airplane();
22     ~Airplane();
23
24     void iterate(float dt);
25     void calcFuelWeights();
26
27     ControlMap* getControlMap();
28     Model* getModel();
29
30     void setPilotPos(float* pos);
31     void getPilotPos(float* out);
32
33     void getPilotAccel(float* out);
34
35     void setWeight(float weight);
36
37     void setWing(Wing* wing);
38     void setTail(Wing* tail);
39     void addVStab(Wing* vstab);
40
41     void addFuselage(float* front, float* back, float width,
42                      float taper=1, float mid=0.5,
43                      float cx=1, float cy=1, float cz=1, float idrag=1);
44     int addTank(float* pos, float cap, float fuelDensity);
45     void addGear(Gear* g);
46     void addHook(Hook* h);
47     void addLaunchbar(Launchbar* l);
48     void addThruster(Thruster* t, float mass, float* cg);
49     void addBallast(float* pos, float mass);
50     void addHitch(Hitch* h);
51
52     int addWeight(float* pos, float size);
53     void setWeight(int handle, float mass);
54
55     void setApproach(float speed, float altitude, float aoa, float fuel, float gla);
56     void setCruise(float speed, float altitude, float fuel, float gla);
57
58     void setElevatorControl(int control);
59     void addApproachControl(int control, float val);
60     void addCruiseControl(int control, float val);
61
62     void addSolutionWeight(bool approach, int idx, float wgt);
63
64     int numGear();
65     Gear* getGear(int g);
66     Hook* getHook();
67     int numHitches() { return _hitches.size(); }
68     Hitch* getHitch(int h);
69     Rotorgear* getRotorgear();
70     Launchbar* getLaunchbar();
71
72     int numThrusters() { return _thrusters.size(); }
73     Thruster* getThruster(int n) {
74         return ((ThrustRec*)_thrusters.get(n))->thruster; }
75     
76     int numTanks();
77     void setFuelFraction(float frac); // 0-1, total amount of fuel
78     float getFuel(int tank); // in kg!
79     float setFuel(int tank, float fuel); // in kg!
80     float getFuelDensity(int tank); // kg/m^3
81     float getTankCapacity(int tank);
82
83     void compile(); // generate point masses & such, then solve
84     void initEngines();
85     void stabilizeThrust();
86
87     // Solution output values
88     int getSolutionIterations();
89     float getDragCoefficient();
90     float getLiftRatio();
91     float getCruiseAoA();
92     float getTailIncidence();
93     float getApproachElevator() { return _approachElevator.val; }
94     const char* getFailureMsg();
95
96     static void setupState(float aoa, float speed, float gla, State* s); // utility
97
98 private:
99     struct Tank { float pos[3]; float cap; float fill;
100                   float density; int handle; };
101     struct Fuselage { float front[3], back[3], width, taper, mid, _cx, _cy, _cz, _idrag;
102                       Vector surfs; };
103     struct GearRec { Gear* gear; Surface* surf; float wgt; };
104     struct ThrustRec { Thruster* thruster;
105                        int handle; float cg[3]; float mass; };
106     struct Control { int control; float val; };
107     struct WeightRec { int handle; Surface* surf; };
108     struct SolveWeight { bool approach; int idx; float wgt; };
109     struct ContactRec { Gear* gear; float p[3]; };
110
111     void runCruise();
112     void runApproach();
113     void solveGear();
114     void solve();
115     void solveHelicopter();
116     float compileWing(Wing* w);
117     void compileRotorgear();
118     float compileFuselage(Fuselage* f);
119     void compileGear(GearRec* gr);
120     void applyDragFactor(float factor);
121     void applyLiftRatio(float factor);
122     float clamp(float val, float min, float max);
123     void addContactPoint(float* pos);
124     void compileContactPoints();
125     float normFactor(float f);
126     void updateGearState();
127     void setupWeights(bool isApproach);
128
129     Model _model;
130     ControlMap _controls;
131
132     float _emptyWeight;
133     float _pilotPos[3];
134
135     Wing* _wing;
136     Wing* _tail;
137
138     Vector _fuselages;
139     Vector _vstabs;
140     Vector _tanks;
141     Vector _thrusters;
142     float _ballast;
143
144     Vector _gears;
145     Vector _contacts; // non-gear ground contact points
146     Vector _weights;
147     Vector _surfs; // NON-wing Surfaces
148     Vector _hitches; //for airtow and winch
149
150     Vector _solveWeights;
151
152     Vector _cruiseControls;
153     State _cruiseState;
154     float _cruiseP;
155     float _cruiseT;
156     float _cruiseSpeed;
157     float _cruiseWeight;
158     float _cruiseFuel;
159     float _cruiseGlideAngle;
160
161     Vector _approachControls;
162     State _approachState;
163     float _approachP;
164     float _approachT;
165     float _approachSpeed;
166     float _approachAoA;
167     float _approachWeight;
168     float _approachFuel;
169     float _approachGlideAngle;
170
171     int _solutionIterations;
172     float _dragFactor;
173     float _liftRatio;
174     float _cruiseAoA;
175     float _tailIncidence;
176     Control _approachElevator;
177     const char* _failureMsg;
178 };
179
180 }; // namespace yasim
181 #endif // _AIRPLANE_HPP