delete (Surface*)_surfs.get(i);
for(i=0; i<_contacts.size(); i++)
delete[] (float*)_contacts.get(i);
+ for(i=0; i<_solveWeights.size(); i++)
+ delete[] (SolveWeight*)_solveWeights.get(i);
}
void Airplane::iterate(float dt)
_cruiseControls.add(c);
}
+void Airplane::addSolutionWeight(bool approach, int idx, float wgt)
+{
+ SolveWeight* w = new SolveWeight();
+ w->approach = approach;
+ w->idx = idx;
+ w->wgt = wgt;
+ _solveWeights.add(w);
+}
+
int Airplane::numTanks()
{
return _tanks.size();
_model.getThruster(i)->stabilize();
}
+void Airplane::setupWeights(bool isApproach)
+{
+ int i;
+ for(i=0; i<_weights.size(); i++)
+ setWeight(i, 0);
+ for(i=0; i<_solveWeights.size(); i++) {
+ SolveWeight* w = (SolveWeight*)_solveWeights.get(i);
+ if(w->approach == isApproach)
+ setWeight(w->idx, w->wgt);
+ }
+}
+
void Airplane::runCruise()
{
setupState(_cruiseAoA, _cruiseSpeed, &_cruiseState);
Math::vmul33(_cruiseState.orient, wind, wind);
setFuelFraction(_cruiseFuel);
+ setupWeights(false);
// Set up the thruster parameters and iterate until the thrust
// stabilizes.
Math::mul3(-1, _approachState.v, wind);
Math::vmul33(_approachState.orient, wind, wind);
- // Approach is by convention at 20% tank capacity
setFuelFraction(_approachFuel);
+ setupWeights(true);
+
// Run the thrusters until they get to a stable setting. FIXME:
// this is lots of wasted work.
for(i=0; i<_thrusters.size(); i++) {
void addApproachControl(int control, float val);
void addCruiseControl(int control, float val);
+ void addSolutionWeight(bool approach, int idx, float wgt);
+
int numGear();
Gear* getGear(int g);
int handle; float cg[3]; float mass; };
struct Control { int control; float val; };
struct WeightRec { int handle; Surface* surf; };
+ struct SolveWeight { bool approach; int idx; float wgt; };
void runCruise();
void runApproach();
void compileContactPoints();
float normFactor(float f);
void updateGearState();
+ void setupWeights(bool isApproach);
Model _model;
ControlMap _controls;
Vector _rotors;
+ Vector _solveWeights;
+
Vector _cruiseControls;
State _cruiseState;
float _cruiseP;
float alt = attrf(a, "alt") * FT2M;
_airplane.setCruise(spd, alt, attrf(a, "fuel", 0.5));
_cruiseCurr = true;
+ } else if(eq(name, "solve-weight")) {
+ int idx = attri(a, "idx");
+ float wgt = attrf(a, "weight") * LBS2KG;
+ _airplane.addSolutionWeight(!_cruiseCurr, idx, wgt);
} else if(eq(name, "cockpit")) {
v[0] = attrf(a, "x");
v[1] = attrf(a, "y");