1
0
Fork 0

YASIM refactoring class Surface

and export more properties to proptree
This commit is contained in:
Henning Stahlke 2017-12-06 20:26:41 +01:00
parent 408e645bb2
commit f7c5d2b1f9
4 changed files with 109 additions and 92 deletions

View file

@ -254,9 +254,7 @@ int Airplane::addWeight(float* pos, float size)
WeightRec* wr = new WeightRec();
wr->handle = _model.getBody()->addMass(0, pos);
wr->surf = new Surface(this);
wr->surf->setPosition(pos);
wr->surf->setDragCoefficient(size*size);
wr->surf = new Surface(this, pos, size*size);
_model.addSurface(wr->surf);
_surfs.add(wr->surf);
@ -355,7 +353,6 @@ float Airplane::compileFuselage(Fuselage* f)
int j;
for(j=0; j<segs; j++) {
float frac = (j+0.5f) / segs;
float scale = 1;
if(frac < f->mid)
scale = f->taper+(1-f->taper) * (frac / f->mid);
@ -379,9 +376,6 @@ float Airplane::compileFuselage(Fuselage* f)
_model.getBody()->addMass(mass, pos, true);
wgt += mass;
// Make a Surface too
Surface* s = new Surface(this);
s->setPosition(pos);
// The following is the original YASim value for sideDrag.
// Originally YASim calculated the fuselage's lateral drag
@ -406,17 +400,18 @@ float Airplane::compileFuselage(Fuselage* f)
// XML parameters: "cy" for the sides, "cz" for top and bottom.
sideDrag = 0.5;
}
float dragCoefficient = scale*segWgt*f->_cx;
if( isVersionOrNewer( YASIM_VERSION_32 ) ) {
dragCoefficient = scale*segWgt;
}
// Make a Surface too
Surface* s = new Surface(this, pos, dragCoefficient);
if( isVersionOrNewer( YASIM_VERSION_32 ) ) {
s->setXDrag(f->_cx);
}
s->setYDrag(sideDrag*f->_cy);
s->setZDrag(sideDrag*f->_cz);
if( isVersionOrNewer( YASIM_VERSION_32 ) ) {
s->setDragCoefficient(scale*segWgt);
} else {
s->setDragCoefficient(scale*segWgt*f->_cx);
}
s->setInducedDrag(f->_idrag);
// FIXME: fails for fuselages aligned along the Y axis
@ -441,9 +436,6 @@ void Airplane::compileGear(GearRec* gr)
{
Gear* g = gr->gear;
// Make a Surface object for the aerodynamic behavior
Surface* s = new Surface(this);
gr->surf = s;
// Put the surface at the half-way point on the gear strut, give
// it a drag coefficient equal to a square of the same dimension
@ -456,8 +448,9 @@ void Airplane::compileGear(GearRec* gr)
Math::mul3(0.5, cmp, cmp);
Math::add3(pos, cmp, pos);
s->setPosition(pos);
s->setDragCoefficient(length*length);
// Make a Surface object for the aerodynamic behavior
Surface* s = new Surface(this, pos, length*length);
gr->surf = s;
_model.addGear(g);
_model.addSurface(s);
@ -812,17 +805,17 @@ void Airplane::applyDragFactor(float factor)
} else {
// Originally YASim applied the drag factor to all axes
// for Fuselage Surfaces.
s->setDragCoefficient(s->getDragCoefficient() * applied);
s->mulDragCoefficient(applied);
}
}
}
for(i=0; i<_weights.size(); i++) {
WeightRec* wr = (WeightRec*)_weights.get(i);
wr->surf->setDragCoefficient(wr->surf->getDragCoefficient() * applied);
wr->surf->mulDragCoefficient(applied);
}
for(i=0; i<_gears.size(); i++) {
GearRec* gr = (GearRec*)_gears.get(i);
gr->surf->setDragCoefficient(gr->surf->getDragCoefficient() * applied);
gr->surf->mulDragCoefficient(applied);
}
}

View file

@ -1,11 +1,13 @@
#include <Main/fg_props.hxx>
#include "Math.hpp"
#include "Surface.hpp"
namespace yasim {
int Surface::s_idGenerator = 0;
Surface::Surface( Version * version ) :
_version(version)
Surface::Surface(Version* version, float* pos, float dragCoefficient = 1 ) :
_version(version),
_c0(dragCoefficient)
{
_id = s_idGenerator++;
@ -13,6 +15,8 @@ Surface::Surface( Version * version ) :
_orient[3] = 0; _orient[4] = 1; _orient[5] = 0;
_orient[6] = 0; _orient[7] = 0; _orient[8] = 1;
Math::set3(pos, _pos);
_surfN = fgGetNode("/fdm/yasim/debug/surfaces", true);
if (_surfN != 0) {
_surfN = _surfN->getChild("surface", _id, true);
@ -25,24 +29,45 @@ Surface::Surface( Version * version ) :
_flapN = _surfN->getNode("flap-pos", true);
_slatN = _surfN->getNode("slat-pos", true);
_spoilerN = _surfN->getNode("spoiler-pos", true);
_surfN->getNode("pos-x", true)->setFloatValue(pos[0]);
_surfN->getNode("pos-y", true)->setFloatValue(pos[1]);
_surfN->getNode("pos-z", true)->setFloatValue(pos[2]);
_surfN->getNode("chord",true)->setFloatValue(0);
_surfN->getNode("axis-x", true)->setFloatValue(0);
_surfN->getNode("axis-y", true)->setFloatValue(0);
_surfN->getNode("axis-z", true)->setFloatValue(0);
}
}
void Surface::setPosition(const float* p)
void Surface::setPosition(const float* pos)
{
int i;
for(i=0; i<3; i++) _pos[i] = p[i];
Math::set3(pos, _pos);
if (_surfN != 0) {
_surfN->getNode("pos-x", true)->setFloatValue(p[0]);
_surfN->getNode("pos-y", true)->setFloatValue(p[1]);
_surfN->getNode("pos-z", true)->setFloatValue(p[2]);
_surfN->getNode("pos-x", true)->setFloatValue(pos[0]);
_surfN->getNode("pos-y", true)->setFloatValue(pos[1]);
_surfN->getNode("pos-z", true)->setFloatValue(pos[2]);
}
}
void Surface::setChord(float chord)
{
_chord = chord;
if (_surfN != 0) {
_surfN->getNode("chord",true)->setFloatValue(_chord);
}
}
void Surface::setOrientation(const float* o)
{
for(int i=0; i<9; i++) _orient[i] = o[i];
if (_surfN) {
float xaxis[3] {-1,0,0};
Math::tmul33(_orient,xaxis, xaxis);
_surfN->getNode("axis-x", true)->setFloatValue(xaxis[0]);
_surfN->getNode("axis-y", true)->setFloatValue(xaxis[1]);
_surfN->getNode("axis-z", true)->setFloatValue(xaxis[2]);
}
}

View file

@ -16,7 +16,7 @@ class Surface
int _id; //index for property tree
public:
Surface( Version * version );
Surface(Version * version, float* pos, float dragCoefficient);
int getID() const { return _id; };
static void resetIDgen() { s_idGenerator = 0; };
@ -25,8 +25,8 @@ public:
void setPosition(const float* p);
void getPosition(float* out) const { Math::set3(_pos, out); }
// Distance scale along the X axis
void setChord(float chord) { _chord = chord; }
// Distance scale along the X axis used for torque (pitch) calculation
void setChord(float chord);
// Slats act to move the stall peak by the specified angle, and
// increase drag by the multiplier specified.
@ -60,6 +60,7 @@ public:
void setTwist(float angle) { _twist = angle; }
void setDragCoefficient(float c0) { _c0 = c0; }
void mulDragCoefficient(float factor) { _c0 *= factor; }
float getDragCoefficient() const { return _c0; }
void setXDrag(float cx) { _cx = cx; }
@ -87,6 +88,7 @@ public:
private:
SGPropertyNode_ptr _surfN;
Version * _version;
float stallFunc(float* v);
float flapLift(float alpha);
@ -123,7 +125,6 @@ private:
float _stallAlpha {0};
float _alpha {0};
Version * _version;
SGPropertyNode* _fxN;
SGPropertyNode* _fyN;
SGPropertyNode* _fzN;

View file

@ -402,9 +402,8 @@ void Wing::WingSection::multiplyLiftRatio(float factor)
void Wing::WingSection::newSurface(Version* _version, float* pos, float* orient, float chord, bool hasFlap0, bool hasFlap1, bool hasSlat, bool hasSpoiler, float weight, float twist)
{
Surface* s = new Surface(_version);
Surface* s = new Surface(_version, pos, weight);
s->setPosition(pos);
s->setOrientation(orient);
s->setChord(chord);
@ -457,7 +456,6 @@ void Wing::WingSection::newSurface(Version* _version, float* pos, float* orient,
SurfRec *sr = new SurfRec();
sr->surface = s;
sr->weight = weight;
s->setDragCoefficient(sr->weight);
s->setTwist(twist);
_surfs.add(sr);
}