YASim bugfix: ground effect did not calculate wingspan correctly;
Variable name clarification; Add Wing::getWingArea, separate Wing::getWingSpan and Wing::getBase.
This commit is contained in:
parent
559dcf4e32
commit
d322ded552
5 changed files with 58 additions and 60 deletions
|
@ -471,25 +471,33 @@ void Airplane::addContactPoint(float* pos)
|
|||
|
||||
float Airplane::compileWing(Wing* w)
|
||||
{
|
||||
// Make sure it's initialized. The surfaces will pop out with
|
||||
// total drag coefficients equal to their areas, which is what we
|
||||
// want.
|
||||
w->compile();
|
||||
|
||||
// The tip of the wing is a contact point
|
||||
float tip[3];
|
||||
// need compile() before getTip()!
|
||||
w->getTip(tip);
|
||||
addContactPoint(tip);
|
||||
if(w->isMirrored()) {
|
||||
tip[1] *= -1;
|
||||
addContactPoint(tip);
|
||||
tip[1] *= -1; //undo mirror
|
||||
}
|
||||
if (_wingsN != 0) {
|
||||
_wingsN->getNode("tip-x", true)->setFloatValue(tip[0]);
|
||||
_wingsN->getNode("tip-y", true)->setFloatValue(tip[1]);
|
||||
_wingsN->getNode("tip-z", true)->setFloatValue(tip[2]);
|
||||
w->getBase(tip);
|
||||
_wingsN->getNode("base-x", true)->setFloatValue(tip[0]);
|
||||
_wingsN->getNode("base-y", true)->setFloatValue(tip[1]);
|
||||
_wingsN->getNode("base-z", true)->setFloatValue(tip[2]);
|
||||
_wingsN->getNode("wingspan", true)->setFloatValue(w->getWingSpan());
|
||||
_wingsN->getNode("wingarea", true)->setFloatValue(w->getWingArea());
|
||||
}
|
||||
|
||||
// Make sure it's initialized. The surfaces will pop out with
|
||||
// total drag coefficients equal to their areas, which is what we
|
||||
// want.
|
||||
w->compile();
|
||||
|
||||
float wgt = 0;
|
||||
float dragSum = 0;
|
||||
for(int i=0; i<w->numSurfaces(); i++) {
|
||||
|
@ -764,7 +772,9 @@ void Airplane::compile()
|
|||
if(_wing) {
|
||||
float gepos[3];
|
||||
float gespan = 0;
|
||||
gespan = _wing->getGroundEffect(gepos);
|
||||
gespan = _wing->getWingSpan();
|
||||
_wing->getBase(gepos);
|
||||
// where does the hard coded factor 0.15 come from?
|
||||
_model.setGroundEffect(gepos, gespan, 0.15f);
|
||||
}
|
||||
|
||||
|
|
|
@ -66,9 +66,9 @@ Model::Model()
|
|||
_hook = 0;
|
||||
_launchbar = 0;
|
||||
|
||||
_groundEffectSpan = 0;
|
||||
_wingSpan = 0;
|
||||
_groundEffect = 0;
|
||||
for(i=0; i<3; i++) _wingCenter[i] = 0;
|
||||
for(i=0; i<3; i++) _geRefPoint[i] = 0;
|
||||
|
||||
_global_ground[0] = 0; _global_ground[1] = 0; _global_ground[2] = 1;
|
||||
_global_ground[3] = -100000;
|
||||
|
@ -289,8 +289,8 @@ Ground* Model::getGroundCallback(void)
|
|||
|
||||
void Model::setGroundEffect(float* pos, float span, float mul)
|
||||
{
|
||||
Math::set3(pos, _wingCenter);
|
||||
_groundEffectSpan = span;
|
||||
Math::set3(pos, _geRefPoint);
|
||||
_wingSpan = span;
|
||||
_groundEffect = mul;
|
||||
}
|
||||
|
||||
|
@ -470,16 +470,19 @@ void Model::calcForces(State* s)
|
|||
// Account for ground effect by multiplying the vertical force
|
||||
// component by an amount linear with the fraction of the wingspan
|
||||
// above the ground.
|
||||
if ((_groundEffectSpan != 0) && (_groundEffect != 0 ))
|
||||
if ((_wingSpan != 0) && (_groundEffect != 0 ))
|
||||
{
|
||||
float dist = ground[3] - Math::dot3(ground, _wingCenter);
|
||||
if(dist > 0 && dist < _groundEffectSpan) {
|
||||
float fz = Math::dot3(faero, ground);
|
||||
fz *= (_groundEffectSpan - dist) / _groundEffectSpan;
|
||||
fz *= _groundEffect;
|
||||
Math::mul3(fz, ground, faero);
|
||||
_body.addForce(faero);
|
||||
}
|
||||
// distance between ground and wing ref. point
|
||||
float dist = ground[3] - Math::dot3(ground, _geRefPoint);
|
||||
float fz = 0;
|
||||
float geForce[3];
|
||||
if(dist > 0 && dist < _wingSpan) {
|
||||
fz = Math::dot3(faero, ground);
|
||||
fz *= (_wingSpan - dist) / _wingSpan;
|
||||
fz *= _groundEffect;
|
||||
Math::mul3(fz, ground, geForce);
|
||||
_body.addForce(geForce);
|
||||
}
|
||||
}
|
||||
|
||||
// Convert the velocity and rotation vectors to local coordinates
|
||||
|
|
|
@ -96,9 +96,9 @@ private:
|
|||
Launchbar* _launchbar;
|
||||
Vector _hitches;
|
||||
|
||||
float _groundEffectSpan;
|
||||
float _wingSpan;
|
||||
float _groundEffect;
|
||||
float _wingCenter[3];
|
||||
float _geRefPoint[3];
|
||||
|
||||
Ground* _ground_cb;
|
||||
double _global_ground[4];
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#include "Math.hpp"
|
||||
#include "Surface.hpp"
|
||||
#include "Wing.hpp"
|
||||
|
||||
|
@ -228,30 +227,6 @@ void Wing::setSlatPos(float val)
|
|||
((Surface*)_slatSurfs.get(i))->setSlatPos(val);
|
||||
}
|
||||
|
||||
float Wing::getGroundEffect(float* posOut)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<3; i++) posOut[i] = _base[i];
|
||||
float span = _length * Math::cos(_sweep) * Math::cos(_dihedral);
|
||||
span = 2*(span + Math::abs(_base[2]));
|
||||
return span;
|
||||
}
|
||||
|
||||
void Wing::getTip(float* tip)
|
||||
{
|
||||
tip[0] = -Math::tan(_sweep);
|
||||
tip[1] = Math::cos(_dihedral);
|
||||
tip[2] = Math::sin(_dihedral);
|
||||
Math::unit3(tip, tip);
|
||||
Math::mul3(_length, tip, tip);
|
||||
Math::add3(_base, tip, tip);
|
||||
}
|
||||
|
||||
bool Wing::isMirrored()
|
||||
{
|
||||
return _mirror;
|
||||
}
|
||||
|
||||
void Wing::compile()
|
||||
{
|
||||
// Have we already been compiled?
|
||||
|
@ -306,11 +281,12 @@ void Wing::compile()
|
|||
Math::unit3(left, left);
|
||||
|
||||
// Calculate coordinates for the root and tip of the wing
|
||||
float root[3], tip[3];
|
||||
float root[3];
|
||||
Math::set3(_base, root);
|
||||
Math::set3(left, tip);
|
||||
Math::mul3(_length, tip, tip);
|
||||
Math::add3(root, tip, tip);
|
||||
Math::set3(left, _tip);
|
||||
Math::mul3(_length, _tip, _tip);
|
||||
Math::add3(root, _tip, _tip);
|
||||
_wingspan = Math::abs(2*_tip[1]);
|
||||
|
||||
// The wing's Y axis will be the "left" vector. The Z axis will
|
||||
// be perpendicular to this and the local (!) X axis, because we
|
||||
|
@ -363,7 +339,7 @@ void Wing::compile()
|
|||
for(j=0; j<nSegs; j++) {
|
||||
float frac = start + (j+0.5f) * (end-start)/nSegs;
|
||||
float pos[3];
|
||||
interp(root, tip, frac, pos);
|
||||
interp(root, _tip, frac, pos);
|
||||
|
||||
float chord = _chord * (1 - (1-_taper)*frac);
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "Vector.hpp"
|
||||
#include "Version.hpp"
|
||||
#include "Math.hpp"
|
||||
|
||||
namespace yasim {
|
||||
|
||||
|
@ -24,6 +25,12 @@ public:
|
|||
void setTaper(float taper); // fraction, 0-1
|
||||
void setSweep(float sweep); // radians
|
||||
void setDihedral(float dihedral); // radians, positive is "up"
|
||||
void getBase(float* base) { Math::set3(_base, base); };
|
||||
float getLength() { return _length; };
|
||||
float getChord() { return _chord; };
|
||||
float getTaper() { return _taper; };
|
||||
float getSweep() { return _sweep; };
|
||||
float getDihedral() { return _dihedral; };
|
||||
|
||||
void setStall(float aoa);
|
||||
void setStallWidth(float angle);
|
||||
|
@ -48,13 +55,11 @@ public:
|
|||
|
||||
// Compile the thing into a bunch of Surface objects
|
||||
void compile();
|
||||
|
||||
void getTip(float* tip);
|
||||
|
||||
bool isMirrored();
|
||||
|
||||
// Ground effect information
|
||||
float getGroundEffect(float* posOut);
|
||||
void getTip(float* tip) { Math::set3(_tip, tip);};
|
||||
bool isMirrored() { return _mirror; };
|
||||
// Used for ground effect
|
||||
float getWingSpan() { return _wingspan; };
|
||||
float getWingArea() {return 0.5f*_wingspan*_chord*(1+_taper); };
|
||||
|
||||
// Query the list of Surface objects
|
||||
int numSurfaces();
|
||||
|
@ -93,6 +98,10 @@ private:
|
|||
float _sweep;
|
||||
float _dihedral;
|
||||
|
||||
// calculated from above
|
||||
float _tip[3];
|
||||
float _wingspan;
|
||||
|
||||
float _stall;
|
||||
float _stallWidth;
|
||||
float _stallPeak;
|
||||
|
|
Loading…
Reference in a new issue