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