1
0
Fork 0

YASIM refactoring Wing class (flaps)

This commit is contained in:
Henning Stahlke 2017-11-11 15:06:08 +01:00
parent 95ee37c9b9
commit 77a9cca6d5
3 changed files with 43 additions and 67 deletions

View file

@ -219,12 +219,12 @@ void ControlMap::applyControls(float dt)
case LEXTEND: ((Launchbar*)obj)->setExtension(lval); break; case LEXTEND: ((Launchbar*)obj)->setExtension(lval); break;
case LACCEL: ((Launchbar*)obj)->setAcceleration(lval); break; case LACCEL: ((Launchbar*)obj)->setAcceleration(lval); break;
case CASTERING:((Gear*)obj)->setCastering(lval != 0); break; case CASTERING:((Gear*)obj)->setCastering(lval != 0); break;
case SLAT: ((Wing*)obj)->setSlatPos(lval); break; case SLAT: ((Wing*)obj)->setFlapPos(WING_SLAT,lval); break;
case FLAP0: ((Wing*)obj)->setFlap0Pos(lval, rval); break; case FLAP0: ((Wing*)obj)->setFlapPos(WING_FLAP0, lval, rval); break;
case FLAP0EFFECTIVENESS: ((Wing*)obj)->setFlap0Effectiveness(lval); break; case FLAP0EFFECTIVENESS: ((Wing*)obj)->setFlapEffectiveness(WING_FLAP0,lval); break;
case FLAP1: ((Wing*)obj)->setFlap1Pos(lval, rval); break; case FLAP1: ((Wing*)obj)->setFlapPos(WING_FLAP1,lval, rval); break;
case FLAP1EFFECTIVENESS: ((Wing*)obj)->setFlap1Effectiveness(lval); break; case FLAP1EFFECTIVENESS: ((Wing*)obj)->setFlapEffectiveness(WING_FLAP1,lval); break;
case SPOILER: ((Wing*)obj)->setSpoilerPos(lval, rval); break; case SPOILER: ((Wing*)obj)->setFlapPos(WING_SPOILER, lval, rval); break;
case COLLECTIVE: ((Rotor*)obj)->setCollective(lval); break; case COLLECTIVE: ((Rotor*)obj)->setCollective(lval); break;
case CYCLICAIL: ((Rotor*)obj)->setCyclicail(lval,rval); break; case CYCLICAIL: ((Rotor*)obj)->setCyclicail(lval,rval); break;
case CYCLICELE: ((Rotor*)obj)->setCyclicele(lval,rval); break; case CYCLICELE: ((Rotor*)obj)->setCyclicele(lval,rval); break;

View file

@ -44,59 +44,40 @@ void Wing::setFlapParams(WingFlaps i, FlapParams fp)
_flapParams[i] = fp; _flapParams[i] = fp;
} }
void Wing::setFlap0Pos(float lval, float rval) void Wing::setFlapPos(WingFlaps f,float lval, float rval)
{ {
lval = Math::clamp(lval, -1, 1); float min {-1};
rval = Math::clamp(rval, -1, 1); if (f == WING_SPOILER || f == WING_SLAT) {
for(int i=0; i<_flap0Surfs.size(); i++) { min = 0;
((Surface*)_flap0Surfs.get(i))->setFlapPos(lval); }
if(_mirror) ((Surface*)_flap0Surfs.get(++i))->setFlapPos(rval); lval = Math::clamp(lval, min, 1);
rval = Math::clamp(rval, min, 1);
for(int i=0; i<_flapSurfs[f].size(); i++) {
switch (f) {
case WING_FLAP0:
case WING_FLAP1:
((Surface*)_flapSurfs[f].get(i))->setFlapPos(lval);
if(_mirror) ((Surface*)_flapSurfs[f].get(++i))->setFlapPos(rval);
break;
case WING_SLAT:
((Surface*)_flapSurfs[f].get(i))->setSlatPos(lval);
break;
case WING_SPOILER:
((Surface*)_flapSurfs[f].get(i))->setSpoilerPos(lval);
if(_mirror) ((Surface*)_flapSurfs[f].get(++i))->setSpoilerPos(rval);
break;
}
} }
} }
void Wing::setFlap0Effectiveness(float lval) void Wing::setFlapEffectiveness(WingFlaps f, float lval)
{ {
lval = Math::clamp(lval, 1, 10); lval = Math::clamp(lval, 1, 10);
for(int i=0; i<_flap0Surfs.size(); i++) { for(int i=0; i<_flapSurfs[f].size(); i++) {
((Surface*)_flap0Surfs.get(i))->setFlapEffectiveness(lval); ((Surface*)_flapSurfs[f].get(i))->setFlapEffectiveness(lval);
} }
} }
void Wing::setFlap1Pos(float lval, float rval)
{
lval = Math::clamp(lval, -1, 1);
rval = Math::clamp(rval, -1, 1);
for(int i=0; i<_flap1Surfs.size(); i++) {
((Surface*)_flap1Surfs.get(i))->setFlapPos(lval);
if(_mirror) ((Surface*)_flap1Surfs.get(++i))->setFlapPos(rval);
}
}
void Wing::setFlap1Effectiveness(float lval)
{
lval = Math::clamp(lval, 1, 10);
for(int i=0; i<_flap1Surfs.size(); i++) {
((Surface*)_flap1Surfs.get(i))->setFlapEffectiveness(lval);
}
}
void Wing::setSpoilerPos(float lval, float rval)
{
lval = Math::clamp(lval, 0, 1);
rval = Math::clamp(rval, 0, 1);
for(int i=0; i<_spoilerSurfs.size(); i++) {
((Surface*)_spoilerSurfs.get(i))->setSpoilerPos(lval);
if(_mirror) ((Surface*)_spoilerSurfs.get(++i))->setSpoilerPos(rval);
}
}
void Wing::setSlatPos(float val)
{
val = Math::clamp(val, 0, 1);
for(int i=0; i<_slatSurfs.size(); i++)
((Surface*)_slatSurfs.get(i))->setSlatPos(val);
}
void Wing::calculateWingCoordinateSystem() { void Wing::calculateWingCoordinateSystem() {
// prepare wing coordinate system, ignoring incidence and twist for now // prepare wing coordinate system, ignoring incidence and twist for now
// (tail incidence is varied by the solver) // (tail incidence is varied by the solver)
@ -335,10 +316,10 @@ Surface* Wing::newSurface(float* pos, float* orient, float chord,
if(hasSlat) s->setSlatParams(_flapParams[WING_SLAT].aoa, _flapParams[WING_SLAT].drag); if(hasSlat) s->setSlatParams(_flapParams[WING_SLAT].aoa, _flapParams[WING_SLAT].drag);
if(hasSpoiler) s->setSpoilerParams(_flapParams[WING_SPOILER].lift, _flapParams[WING_SPOILER].drag); if(hasSpoiler) s->setSpoilerParams(_flapParams[WING_SPOILER].lift, _flapParams[WING_SPOILER].drag);
if(hasFlap0) _flap0Surfs.add(s); if(hasFlap0) _flapSurfs[WING_FLAP0].add(s);
if(hasFlap1) _flap1Surfs.add(s); if(hasFlap1) _flapSurfs[WING_FLAP1].add(s);
if(hasSlat) _slatSurfs.add(s); if(hasSlat) _flapSurfs[WING_SLAT].add(s);
if(hasSpoiler) _spoilerSurfs.add(s); if(hasSpoiler) _flapSurfs[WING_SPOILER].add(s);
s->setInducedDrag(_inducedDrag); s->setInducedDrag(_inducedDrag);

View file

@ -20,8 +20,8 @@ struct FlapParams {
enum WingFlaps { enum WingFlaps {
WING_FLAP0, WING_FLAP0,
WING_FLAP1, WING_FLAP1,
WING_SPOILER,
WING_SLAT, WING_SLAT,
WING_SPOILER
}; };
// FIXME: need to handle "inverted" controls for mirrored wings. // FIXME: need to handle "inverted" controls for mirrored wings.
@ -65,13 +65,9 @@ public:
void setFlapParams(WingFlaps i, FlapParams fp); void setFlapParams(WingFlaps i, FlapParams fp);
// Set the control axes for the sub-surfaces // propergate the control axes value for the sub-surfaces
void setFlap0Pos(float lval, float rval); void setFlapPos(WingFlaps i, float lval, float rval = 0);
void setFlap1Pos(float lval, float rval); void setFlapEffectiveness(WingFlaps f, float lval);
void setSpoilerPos(float lval, float rval);
void setSlatPos(float val);
void setFlap0Effectiveness(float lval);
void setFlap1Effectiveness(float lval);
// Compile the thing into a bunch of Surface objects // Compile the thing into a bunch of Surface objects
void compile(); void compile();
@ -116,11 +112,10 @@ private:
struct SurfRec { Surface * surface; float weight; }; struct SurfRec { Surface * surface; float weight; };
Vector _surfs; // all surfaces of this wing
Vector _flap0Surfs; Vector _surfs;
Vector _flap1Surfs; // surfaces having a certain type of flap (flap, slat, spoiler)
Vector _slatSurfs; Vector _flapSurfs[sizeof(WingFlaps)];
Vector _spoilerSurfs;
Version * _version; Version * _version;
bool _mirror {false}; bool _mirror {false};