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