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