delete (Tank*)_tanks.get(i);
for(i=0; i<_thrusters.size(); i++)
delete (ThrustRec*)_thrusters.get(i);
- for(i=0; i<_gears.size(); i++)
- delete (GearRec*)_gears.get(i);
+ for(i=0; i<_gears.size(); i++) {
+ GearRec* g = (GearRec*)_gears.get(i);
+ delete g->gear;
+ delete g;
+ }
for(i=0; i<_surfs.size(); i++)
delete (Surface*)_surfs.get(i);
- for(i=0; i<_contacts.size(); i++)
- delete[] (float*)_contacts.get(i);
+ for(i=0; i<_contacts.size(); i++) {
+ ContactRec* c = (ContactRec*)_contacts.get(i);
+ delete c->gear;
+ delete c;
+ }
+ for(i=0; i<_solveWeights.size(); i++)
+ delete (SolveWeight*)_solveWeights.get(i);
+ for(i=0; i<_cruiseControls.size(); i++)
+ delete (Control*)_cruiseControls.get(i);
+ for(i=0; i<_approachControls.size(); i++) {
+ Control* c = (Control*)_approachControls.get(i);
+ if(c != &_approachElevator)
+ delete c;
+ }
+ delete _wing;
+ delete _tail;
+ for(i=0; i<_vstabs.size(); i++)
+ delete (Wing*)_vstabs.get(i);
+ for(i=0; i<_weights.size(); i++)
+ delete (WeightRec*)_weights.get(i);
+ for(i=0; i<_rotors.size(); i++)
+ delete (Rotor*)_rotors.get(i);
}
void Airplane::iterate(float dt)
_model.iterate();
}
-void Airplane::consumeFuel(float dt)
+void Airplane::calcFuelWeights()
{
- // This is a really simple implementation that assumes all engines
- // draw equally from all tanks in proportion to the amount of fuel
- // stored there. Needs to be fixed, but that has to wait for a
- // decision as to what the property interface will look like.
- int i, outOfFuel = 0;
- float fuelFlow = 0, totalFuel = 0.00001; // <-- overflow protection
- for(i=0; i<_thrusters.size(); i++)
- fuelFlow += ((ThrustRec*)_thrusters.get(i))->thruster->getFuelFlow();
- for(i=0; i<_tanks.size(); i++)
- totalFuel += ((Tank*)_tanks.get(i))->fill;
- for(i=0; i<_tanks.size(); i++) {
- Tank* t = (Tank*)_tanks.get(i);
- t->fill -= dt * fuelFlow * (t->fill/totalFuel);
- if(t->fill <= 0) {
- t->fill = 0;
- outOfFuel = 1;
- }
- }
- if(outOfFuel)
- for(int i=0; i<_thrusters.size(); i++)
- ((ThrustRec*)_thrusters.get(i))->thruster->setFuelState(false);
-
- // Set the tank masses on the RigidBody
- for(i=0; i<_tanks.size(); i++) {
+ for(int i=0; i<_tanks.size(); i++) {
Tank* t = (Tank*)_tanks.get(i);
_model.getBody()->setMass(t->handle, t->fill);
}
return ((GearRec*)_gears.get(g))->gear;
}
+Hook* Airplane::getHook()
+{
+ return _model.getHook();
+}
+
+Launchbar* Airplane::getLaunchbar()
+{
+ return _model.getLaunchbar();
+}
+
void Airplane::updateGearState()
{
for(int i=0; i<_gears.size(); i++) {
}
}
-void Airplane::setApproach(float speed, float altitude)
-{
- // The zero AoA will become a calculated stall AoA in compile()
- setApproach(speed, altitude, 0);
-}
-
-void Airplane::setApproach(float speed, float altitude, float aoa)
+void Airplane::setApproach(float speed, float altitude, float aoa, float fuel)
{
_approachSpeed = speed;
_approachP = Atmosphere::getStdPressure(altitude);
_approachT = Atmosphere::getStdTemperature(altitude);
_approachAoA = aoa;
+ _approachFuel = fuel;
}
-void Airplane::setCruise(float speed, float altitude)
+void Airplane::setCruise(float speed, float altitude, float fuel)
{
_cruiseSpeed = speed;
_cruiseP = Atmosphere::getStdPressure(altitude);
_cruiseT = Atmosphere::getStdTemperature(altitude);
_cruiseAoA = 0;
_tailIncidence = 0;
+ _cruiseFuel = fuel;
}
void Airplane::setElevatorControl(int control)
_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();
return ((Tank*)_tanks.get(tank))->fill;
}
+float Airplane::setFuel(int tank, float fuel)
+{
+ return ((Tank*)_tanks.get(tank))->fill = fuel;
+}
+
float Airplane::getFuelDensity(int tank)
{
return ((Tank*)_tanks.get(tank))->density;
_gears.add(g);
}
+void Airplane::addHook(Hook* hook)
+{
+ _model.addHook(hook);
+}
+
+void Airplane::addLaunchbar(Launchbar* launchbar)
+{
+ _model.addLaunchbar(launchbar);
+}
+
void Airplane::addThruster(Thruster* thruster, float mass, float* cg)
{
ThrustRec* t = new ThrustRec();
void Airplane::addContactPoint(float* pos)
{
- float* cp = new float[3];
- cp[0] = pos[0];
- cp[1] = pos[1];
- cp[2] = pos[2];
- _contacts.add(cp);
+ ContactRec* c = new ContactRec;
+ c->gear = 0;
+ c->p[0] = pos[0];
+ c->p[1] = pos[1];
+ c->p[2] = pos[2];
+ _contacts.add(c);
}
float Airplane::compileWing(Wing* w)
int i;
for(i=0; i<_contacts.size(); i++) {
- float *cp = (float*)_contacts.get(i);
+ ContactRec* c = (ContactRec*)_contacts.get(i);
Gear* g = new Gear();
- g->setPosition(cp);
+ c->gear = g;
+ g->setPosition(c->p);
g->setCompression(comp);
g->setSpring(spring);
void Airplane::compile()
{
- double ground[3];
- ground[0] = 0; ground[1] = 0; ground[2] = 1;
- _model.setGroundPlane(ground, -100000);
-
RigidBody* body = _model.getBody();
int firstMass = body->numMasses();
}
// Ground effect
- float gepos[3];
- float gespan = 0;
- if(_wing)
- gespan = _wing->getGroundEffect(gepos);
- _model.setGroundEffect(gepos, gespan, 0.15f);
+ if(_wing) {
+ float gepos[3];
+ float gespan = 0;
+ gespan = _wing->getGroundEffect(gepos);
+ _model.setGroundEffect(gepos, gespan, 0.15f);
+ }
solveGear();
if(_wing && _tail) solve();
_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::mul3(-1, _cruiseState.v, wind);
Math::vmul33(_cruiseState.orient, wind, wind);
- // Cruise is by convention at 50% tank capacity
- setFuelFraction(0.5);
+ 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(0.2f);
+ setFuelFraction(_approachFuel);
+
+ setupWeights(true);
// Run the thrusters until they get to a stable setting. FIXME:
// this is lots of wasted work.