]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/Airplane.hpp
- Added "SG" prefix to sound classes that recently moved to SimGear.
[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 "Vector.hpp"
8
9 namespace yasim {
10
11 class Gear;
12 class Thruster;
13
14 class Airplane {
15 public:
16     Airplane();
17     ~Airplane();
18
19     void iterate(float dt);
20     void consumeFuel(float dt);
21
22     ControlMap* getControlMap();
23     Model* getModel();
24
25     void setPilotPos(float* pos);
26     void getPilotPos(float* out);
27
28     void getPilotAccel(float* out);
29
30     void setWeight(float weight);
31
32     void setWing(Wing* wing);
33     void setTail(Wing* tail);
34     void addVStab(Wing* vstab);
35
36     void addFuselage(float* front, float* back, float width,
37                      float taper=1, float mid=0.5);
38     int addTank(float* pos, float cap, float fuelDensity);
39     void addGear(Gear* g);
40     void addThruster(Thruster* t, float mass, float* cg);
41     void addBallast(float* pos, float mass);
42
43     int addWeight(float* pos, float size);
44     void setWeight(int handle, float mass);
45
46     void setApproach(float speed, float altitude);
47     void setApproach(float speed, float altitude, float aoa); 
48     void setCruise(float speed, float altitude);
49
50     void setElevatorControl(int control);
51     void addApproachControl(int control, float val);
52     void addCruiseControl(int control, float val);
53
54     int numGear();
55     Gear* getGear(int g);
56
57     int numTanks();
58     void setFuelFraction(float frac); // 0-1, total amount of fuel
59     float getFuel(int tank); // in kg!
60     float getFuelDensity(int tank); // kg/m^3
61     float getTankCapacity(int tank);
62
63     void compile(); // generate point masses & such, then solve
64     void initEngines();
65     void stabilizeThrust();
66
67     // Solution output values
68     int getSolutionIterations();
69     float getDragCoefficient();
70     float getLiftRatio();
71     float getCruiseAoA();
72     float getTailIncidence();
73     float getApproachElevator() { return _approachElevator.val; }
74     char* getFailureMsg();
75
76 private:
77     struct Tank { float pos[3]; float cap; float fill;
78                   float density; int handle; };
79     struct Fuselage { float front[3], back[3], width, taper, mid; };
80     struct GearRec { Gear* gear; Surface* surf; float wgt; };
81     struct ThrustRec { Thruster* thruster;
82                        int handle; float cg[3]; float mass; };
83     struct Control { int control; float val; };
84     struct WeightRec { int handle; Surface* surf; };
85
86     void runCruise();
87     void runApproach();
88     void setupState(float aoa, float speed, State* s);
89     void solveGear();
90     void solve();
91     float compileWing(Wing* w);
92     float compileFuselage(Fuselage* f);
93     void compileGear(GearRec* gr);
94     void applyDragFactor(float factor);
95     void applyLiftRatio(float factor);
96     float clamp(float val, float min, float max);
97     void addContactPoint(float* pos);
98     void compileContactPoints();
99     float normFactor(float f);
100     void updateGearState();
101
102     Model _model;
103     ControlMap _controls;
104
105     float _emptyWeight;
106     float _pilotPos[3];
107
108     Wing* _wing;
109     Wing* _tail;
110
111     Vector _fuselages;
112     Vector _vstabs;
113     Vector _tanks;
114     Vector _thrusters;
115     float _ballast;
116
117     Vector _gears;
118     Vector _contacts; // non-gear ground contact points
119     Vector _weights;
120     Vector _surfs; // NON-wing Surfaces
121
122     Vector _cruiseControls;
123     State _cruiseState;
124     float _cruiseP;
125     float _cruiseT;
126     float _cruiseSpeed;
127     float _cruiseWeight;
128
129     Vector _approachControls;
130     State _approachState;
131     float _approachP;
132     float _approachT;
133     float _approachSpeed;
134     float _approachAoA;
135     float _approachWeight;
136
137     int _solutionIterations;
138     float _dragFactor;
139     float _liftRatio;
140     float _cruiseAoA;
141     float _tailIncidence;
142     Control _approachElevator;
143     char* _failureMsg;
144 };
145
146 }; // namespace yasim
147 #endif // _AIRPLANE_HPP