1
0
Fork 0

YASim declared get methods as const. (correction to previous commit)

This commit is contained in:
Henning Stahlke 2017-04-18 19:12:23 +02:00
parent 503907be34
commit 73de375249
9 changed files with 83 additions and 84 deletions

View file

@ -117,7 +117,7 @@ void Airplane::calcFuelWeights()
} }
} }
const void Airplane::getPilotAccel(float* out) void Airplane::getPilotAccel(float* out)
{ {
State* s = _model.getState(); State* s = _model.getState();
@ -1116,7 +1116,7 @@ void Airplane::solveHelicopter()
} }
const float Airplane::getCGMAC() float Airplane::getCGMAC()
{ {
float cg[3]; float cg[3];
_model.getBody()->getCG(cg); _model.getBody()->getCG(cg);

View file

@ -33,7 +33,7 @@ public:
void setPilotPos(float* pos) { Math::set3(pos, _pilotPos); } void setPilotPos(float* pos) { Math::set3(pos, _pilotPos); }
void getPilotPos(float* out) { Math::set3(_pilotPos, out); } void getPilotPos(float* out) { Math::set3(_pilotPos, out); }
const void getPilotAccel(float* out); void getPilotAccel(float* out);
void setEmptyWeight(float weight) { _emptyWeight = weight; } void setEmptyWeight(float weight) { _emptyWeight = weight; }
@ -65,52 +65,52 @@ public:
void addSolutionWeight(bool approach, int idx, float wgt); void addSolutionWeight(bool approach, int idx, float wgt);
const int numGear() { return _gears.size(); } int numGear() const { return _gears.size(); }
Gear* getGear(int g) { return ((GearRec*)_gears.get(g))->gear; } Gear* getGear(int g) { return ((GearRec*)_gears.get(g))->gear; }
Hook* getHook() { return _model.getHook(); } Hook* getHook() const { return _model.getHook(); }
const int numHitches() { return _hitches.size(); } int numHitches() const { return _hitches.size(); }
Hitch* getHitch(int h); Hitch* getHitch(int h);
Rotorgear* getRotorgear() { return _model.getRotorgear(); } Rotorgear* getRotorgear() { return _model.getRotorgear(); }
Launchbar* getLaunchbar() { return _model.getLaunchbar(); } Launchbar* getLaunchbar() const { return _model.getLaunchbar(); }
const int numThrusters() { return _thrusters.size(); } int numThrusters() const { return _thrusters.size(); }
Thruster* getThruster(int n) { Thruster* getThruster(int n) {
return ((ThrustRec*)_thrusters.get(n))->thruster; } return ((ThrustRec*)_thrusters.get(n))->thruster; }
const int numTanks() { return _tanks.size(); } int numTanks() const { return _tanks.size(); }
void setFuelFraction(float frac); // 0-1, total amount of fuel void setFuelFraction(float frac); // 0-1, total amount of fuel
// get fuel in kg // get fuel in kg
const float getFuel(int tank) { return ((Tank*)_tanks.get(tank))->fill; } float getFuel(int tank) const { return ((Tank*)_tanks.get(tank))->fill; }
// set fuel in kg // set fuel in kg
float setFuel(int tank, float fuel) { return ((Tank*)_tanks.get(tank))->fill = fuel; } float setFuel(int tank, float fuel) { return ((Tank*)_tanks.get(tank))->fill = fuel; }
// get fuel density in kg/m^3 // get fuel density in kg/m^3
const float getFuelDensity(int tank) { return ((Tank*)_tanks.get(tank))->density; } float getFuelDensity(int tank) const { return ((Tank*)_tanks.get(tank))->density; }
const float getTankCapacity(int tank) { return ((Tank*)_tanks.get(tank))->cap; } float getTankCapacity(int tank) const { return ((Tank*)_tanks.get(tank))->cap; }
void compile(); // generate point masses & such, then solve void compile(); // generate point masses & such, then solve
void initEngines(); void initEngines();
void stabilizeThrust(); void stabilizeThrust();
// Solution output values // Solution output values
const int getSolutionIterations() { return _solutionIterations; } int getSolutionIterations() const { return _solutionIterations; }
const float getDragCoefficient() { return _dragFactor; } float getDragCoefficient() const { return _dragFactor; }
const float getLiftRatio() { return _liftRatio; } float getLiftRatio() const { return _liftRatio; }
const float getCruiseAoA() { return _cruiseAoA; } float getCruiseAoA() const { return _cruiseAoA; }
const float getTailIncidence() { return _tailIncidence; } float getTailIncidence() const { return _tailIncidence; }
const float getApproachElevator() { return _approachElevator.val; } float getApproachElevator() const { return _approachElevator.val; }
const char* getFailureMsg() { return _failureMsg; } const char* getFailureMsg() const { return _failureMsg; }
static void setupState(const float aoa, const float speed, const float gla, yasim::State* s); // utility static void setupState(const float aoa, const float speed, const float gla, yasim::State* s); // utility
void loadApproachControls() { loadControls(_approachControls); } void loadApproachControls() { loadControls(_approachControls); }
void loadCruiseControls() { loadControls(_cruiseControls); } void loadCruiseControls() { loadControls(_cruiseControls); }
const float getCGHardLimitXMin() { return _cgMin; } // get min x-coordinate for c.g (from main gear) float getCGHardLimitXMin() const { return _cgMin; } // get min x-coordinate for c.g (from main gear)
const float getCGHardLimitXMax() { return _cgMax; } // get max x-coordinate for c.g (from nose gear) float getCGHardLimitXMax() const { return _cgMax; } // get max x-coordinate for c.g (from nose gear)
const float getCGMAC(); // return c.g. x as fraction of MAC float getCGMAC(); // return c.g. x as fraction of MAC
// set desired range for C.G. in % of MAC, 0% = leading edge, 100% trailing edge // set desired range for C.G. in % of MAC, 0% = leading edge, 100% trailing edge
void setDesiredCGRangeInPercentOfMAC(float MACPercentMin, float MACPercentMax) { _cgDesiredMin = MACPercentMin; _cgDesiredMax = MACPercentMax; } void setDesiredCGRangeInPercentOfMAC(float MACPercentMin, float MACPercentMax) { _cgDesiredMin = MACPercentMin; _cgDesiredMax = MACPercentMax; }
const float getCGSoftLimitXMin() { return _cgDesiredAft; } // get x-coordinate limit calculated from MAC and setCGRange values float getCGSoftLimitXMin() const { return _cgDesiredAft; } // get x-coordinate limit calculated from MAC and setCGRange values
const float getCGSoftLimitXMax() { return _cgDesiredFront; } // get x-coordinate limit calculated from MAC and setCGRange values float getCGSoftLimitXMax() const { return _cgDesiredFront; } // get x-coordinate limit calculated from MAC and setCGRange values
void setAutoBallast(bool allowed) { _autoBallast = allowed; } void setAutoBallast(bool allowed) { _autoBallast = allowed; }
private: private:

View file

@ -94,7 +94,7 @@ Model::~Model()
} }
void Model::getThrust(float* out) void Model::getThrust(float* out) const
{ {
float tmp[3]; float tmp[3];
out[0] = out[1] = out[2] = 0; out[0] = out[1] = out[2] = 0;
@ -196,21 +196,21 @@ void Model::setGroundCallback(Ground* ground_cb)
_ground_cb = ground_cb; _ground_cb = ground_cb;
} }
void Model::setGroundEffect(const float* pos, const float span, const float mul) void Model::setGroundEffect(const float* pos, float span, float mul)
{ {
Math::set3(pos, _geRefPoint); Math::set3(pos, _geRefPoint);
_wingSpan = span; _wingSpan = span;
_groundEffect = mul; _groundEffect = mul;
} }
void Model::setAir(const float pressure, const float temp, const float density) void Model::setAir(float pressure, float temp, float density)
{ {
_pressure = pressure; _pressure = pressure;
_temp = temp; _temp = temp;
_rho = density; _rho = density;
} }
void Model::setAirFromStandardAtmosphere(const float altitude) void Model::setAirFromStandardAtmosphere(float altitude)
{ {
_pressure = Atmosphere::getStdPressure(altitude); _pressure = Atmosphere::getStdPressure(altitude);
_temp = Atmosphere::getStdTemperature(altitude); _temp = Atmosphere::getStdTemperature(altitude);

View file

@ -32,12 +32,12 @@ public:
void setTurbulence(Turbulence* turb) { _turb = turb; } void setTurbulence(Turbulence* turb) { _turb = turb; }
State* getState() { return _s; } State* getState() const { return _s; }
void setState(State* s); void setState(State* s);
bool isCrashed() { return _crashed; } bool isCrashed() const { return _crashed; }
void setCrashed(bool crashed) { _crashed = crashed; } void setCrashed(bool crashed) { _crashed = crashed; }
float getAGL() { return _agl; } float getAGL() const { return _agl; }
void iterate(); void iterate();
@ -47,19 +47,18 @@ public:
int addGear(Gear* gear) { return _gears.add(gear); } int addGear(Gear* gear) { return _gears.add(gear); }
void addHook(Hook* hook) { _hook = hook; } void addHook(Hook* hook) { _hook = hook; }
void addLaunchbar(Launchbar* launchbar) { _launchbar = launchbar; } void addLaunchbar(Launchbar* launchbar) { _launchbar = launchbar; }
Surface* getSurface(int handle) { return (Surface*)_surfaces.get(handle); } Surface* getSurface(int handle) const { return (Surface*)_surfaces.get(handle); }
Rotorgear* getRotorgear(void) { return &_rotorgear; } Rotorgear* getRotorgear(void) { return &_rotorgear; }
Gear* getGear(int handle); Hook* getHook(void) const { return _hook; }
Hook* getHook(void) { return _hook; }
int addHitch(Hitch* hitch) { return _hitches.add(hitch); } int addHitch(Hitch* hitch) { return _hitches.add(hitch); }
Launchbar* getLaunchbar(void) { return _launchbar; } Launchbar* getLaunchbar(void) const { return _launchbar; }
// Semi-private methods for use by the Airplane solver. // Semi-private methods for use by the Airplane solver.
int numThrusters() { return _thrusters.size(); } int numThrusters() const { return _thrusters.size(); }
Thruster* getThruster(int handle) { return (Thruster*)_thrusters.get(handle); } Thruster* getThruster(int handle) { return (Thruster*)_thrusters.get(handle); }
void setThruster(int handle, Thruster* t) { _thrusters.set(handle, t); } void setThruster(int handle, Thruster* t) { _thrusters.set(handle, t); }
void initIteration(); void initIteration();
void getThrust(float* out); void getThrust(float* out) const;
void setGroundCallback(Ground* ground_cb); void setGroundCallback(Ground* ground_cb);
Ground* getGroundCallback(void) { return _ground_cb; } Ground* getGroundCallback(void) { return _ground_cb; }
@ -67,10 +66,10 @@ public:
// //
// Per-iteration settables // Per-iteration settables
// //
void setGroundEffect(const float* pos, const float span, const float mul); void setGroundEffect(const float* pos, float span, float mul);
void setWind(float* wind) { Math::set3(wind, _wind); } void setWind(float* wind) { Math::set3(wind, _wind); }
void setAir(const float pressure, const float temp, const float density); void setAir(float pressure, float temp, float density);
void setAirFromStandardAtmosphere(const float altitude); void setAirFromStandardAtmosphere(float altitude);
void updateGround(State* s); void updateGround(State* s);

View file

@ -67,7 +67,7 @@ void RigidBody::setMass(int handle, float mass, const float* pos, bool isStatic)
} }
} }
void RigidBody::getMassPosition(int handle, float* out) void RigidBody::getMassPosition(int handle, float* out) const
{ {
out[0] = _masses[handle].p[0]; out[0] = _masses[handle].p[0];
out[1] = _masses[handle].p[1]; out[1] = _masses[handle].p[1];
@ -217,7 +217,7 @@ void RigidBody::addForce(const float* pos, const float* force)
addTorque(t); addTorque(t);
} }
void RigidBody::getAccel(float* pos, float* accelOut) void RigidBody::getAccel(float* pos, float* accelOut) const
{ {
getAccel(accelOut); getAccel(accelOut);
@ -241,7 +241,7 @@ void RigidBody::getAccel(float* pos, float* accelOut)
Math::add3(v, accelOut, accelOut); Math::add3(v, accelOut, accelOut);
} }
void RigidBody::getAngularAccel(float* accelOut) void RigidBody::getAngularAccel(float* accelOut) const
{ {
// Compute "tau" as the externally applied torque, plus the // Compute "tau" as the externally applied torque, plus the
// counter-torque due to the internal gyro. // counter-torque due to the internal gyro.
@ -258,7 +258,7 @@ void RigidBody::getAngularAccel(float* accelOut)
Math::vmul33(_invI, v, v); // v = invI*(tau + (omega X I*omega)) Math::vmul33(_invI, v, v); // v = invI*(tau + (omega X I*omega))
} }
void RigidBody::getInertiaMatrix(float* inertiaOut) void RigidBody::getInertiaMatrix(float* inertiaOut) const
{ {
// valid only after a call to RigidBody::recalc() // valid only after a call to RigidBody::recalc()
// See comment at top of RigidBody.hpp on units. // See comment at top of RigidBody.hpp on units.

View file

@ -37,10 +37,10 @@ public:
void setMass(int handle, float mass); void setMass(int handle, float mass);
void setMass(int handle, float mass, const float* pos, bool isStatic = false); void setMass(int handle, float mass, const float* pos, bool isStatic = false);
int numMasses() { return _nMasses; } int numMasses() const { return _nMasses; }
float getMass(int handle) { return _masses[handle].m; } float getMass(int handle) const { return _masses[handle].m; }
void getMassPosition(int handle, float* out); void getMassPosition(int handle, float* out) const;
float getTotalMass() { return _totalMass; } float getTotalMass() const { return _totalMass; }
// The velocity, in local coordinates, of the specified point on a // The velocity, in local coordinates, of the specified point on a
// body rotating about its c.g. with velocity rot. // body rotating about its c.g. with velocity rot.
@ -83,24 +83,24 @@ public:
// Returns the center of gravity of the masses, in the body // Returns the center of gravity of the masses, in the body
// coordinate system. valid only after recalc() // coordinate system. valid only after recalc()
void getCG(float* cgOut) { Math::set3(_cg, cgOut); } void getCG(float* cgOut) const { Math::set3(_cg, cgOut); }
// Returns the acceleration of the body's c.g. relative to the // Returns the acceleration of the body's c.g. relative to the
// rest of the world, specified in local coordinates. // rest of the world, specified in local coordinates.
void getAccel(float* accelOut) { Math::mul3(1/_totalMass, _force, accelOut); } void getAccel(float* accelOut) const { Math::mul3(1/_totalMass, _force, accelOut); }
// Returns the acceleration of a specific location in local // Returns the acceleration of a specific location in local
// coordinates. If the body is rotating, this will be different // coordinates. If the body is rotating, this will be different
// from the c.g. acceleration due to the centripetal accelerations // from the c.g. acceleration due to the centripetal accelerations
// of points not on the rotation axis. // of points not on the rotation axis.
void getAccel(float* pos, float* accelOut); void getAccel(float* pos, float* accelOut) const;
// Returns the instantaneous rate of change of the angular // Returns the instantaneous rate of change of the angular
// velocity, as a vector in local coordinates. // velocity, as a vector in local coordinates.
void getAngularAccel(float* accelOut); void getAngularAccel(float* accelOut) const;
// Returns the intertia tensor in a float[9] allocated by caller. // Returns the intertia tensor in a float[9] allocated by caller.
void getInertiaMatrix(float* inertiaOut); void getInertiaMatrix(float* inertiaOut) const;
private: private:
/** /**

View file

@ -18,12 +18,12 @@ class Surface
public: public:
Surface( Version * version ); Surface( Version * version );
int getID() { return _id; }; int getID() const { return _id; };
static void resetIDgen() { s_idGenerator = 0; }; static void resetIDgen() { s_idGenerator = 0; };
// Position of this surface in local coords // Position of this surface in local coords
void setPosition(const float* p); void setPosition(const float* p);
void getPosition(float* out) { Math::set3(_pos, out); } void getPosition(float* out) const { Math::set3(_pos, out); }
// Distance scale along the X axis // Distance scale along the X axis
void setChord(float chord) { _chord = chord; } void setChord(float chord) { _chord = chord; }
@ -46,7 +46,7 @@ public:
// Modifier for flap lift coefficient, useful for simulating flap blowing etc. // Modifier for flap lift coefficient, useful for simulating flap blowing etc.
void setFlapEffectiveness(float effectiveness) { _flapEffectiveness = effectiveness; } void setFlapEffectiveness(float effectiveness) { _flapEffectiveness = effectiveness; }
double getFlapEffectiveness() { return _flapEffectiveness; } double getFlapEffectiveness() const { return _flapEffectiveness; }
// local -> Surface coords // local -> Surface coords
void setOrientation(const float* o); void setOrientation(const float* o);
@ -60,12 +60,12 @@ public:
void setTwist(float angle) { _twist = angle; } void setTwist(float angle) { _twist = angle; }
void setTotalDrag(float c0) { _c0 = c0; } void setTotalDrag(float c0) { _c0 = c0; }
float getTotalDrag() { return _c0; } float getTotalDrag() const { return _c0; }
void setXDrag(float cx) { _cx = cx; } void setXDrag(float cx) { _cx = cx; }
void setYDrag(float cy) { _cy = cy; } void setYDrag(float cy) { _cy = cy; }
void setZDrag(float cz) { _cz = cz; } void setZDrag(float cz) { _cz = cz; }
float getXDrag() { return _cx; } float getXDrag() const { return _cx; }
// zero-alpha Z drag ("camber") specified as a fraction of cz // zero-alpha Z drag ("camber") specified as a fraction of cz
void setBaseZDrag(float cz0) { _cz0 = cz0; } void setBaseZDrag(float cz0) { _cz0 = cz0; }
@ -82,8 +82,8 @@ public:
void calcForce(const float* v, const float rho, float* out, float* torque); void calcForce(const float* v, const float rho, float* out, float* torque);
float getAlpha() { return _alpha; }; float getAlpha() const { return _alpha; };
float getStallAlpha() { return _stallAlpha; }; float getStallAlpha() const { return _stallAlpha; };
private: private:
SGPropertyNode_ptr _surfN; SGPropertyNode_ptr _surfN;

View file

@ -12,10 +12,10 @@ public:
Vector(); Vector();
~Vector(); ~Vector();
int add(void* p); int add(void* p);
void* get(int i); void* get(int i) const;
void set(int i, void* p); void set(int i, void* p);
int size(); int size() const;
bool empty(); bool empty() const;
private: private:
void realloc(); void realloc();
@ -44,7 +44,7 @@ inline int Vector::add(void* p)
return _sz++; return _sz++;
} }
inline void* Vector::get(int i) inline void* Vector::get(int i) const
{ {
return _array[i]; return _array[i];
} }
@ -54,12 +54,12 @@ inline void Vector::set(int i, void* p)
_array[i] = p; _array[i] = p;
} }
inline int Vector::size() inline int Vector::size() const
{ {
return _sz; return _sz;
} }
inline bool Vector::empty() inline bool Vector::empty() const
{ {
return _sz == 0; return _sz == 0;
} }

View file

@ -23,22 +23,22 @@ public:
// base point of wing // base point of wing
void setBase(const float* base) { Math::set3(base, _base); } void setBase(const float* base) { Math::set3(base, _base); }
const void getBase(float* base) { Math::set3(_base, base); }; void getBase(float* base) const { Math::set3(_base, base); };
// dist. ALONG wing (not span!) // dist. ALONG wing (not span!)
void setLength(float length) { _length = length; } void setLength(float length) { _length = length; }
const float getLength() { return _length; }; float getLength() const { return _length; };
// at base, measured along X axis // at base, measured along X axis
void setChord(float chord) { _chord = chord; } void setChord(float chord) { _chord = chord; }
const float getChord() { return _chord; }; float getChord() const { return _chord; };
// fraction of chord at wing tip, 0..1 // fraction of chord at wing tip, 0..1
void setTaper(float taper) { _taper = taper; } void setTaper(float taper) { _taper = taper; }
const float getTaper() { return _taper; }; float getTaper() const { return _taper; };
// radians // radians
void setSweep(float sweep) { _sweep = sweep; } void setSweep(float sweep) { _sweep = sweep; }
const float getSweep() { return _sweep; }; float getSweep() const { return _sweep; };
// radians, positive is "up" // radians, positive is "up"
void setDihedral(float dihedral) { _dihedral = dihedral; } void setDihedral(float dihedral) { _dihedral = dihedral; }
const float getDihedral() { return _dihedral; }; float getDihedral() const { return _dihedral; };
void setIncidence(float incidence); void setIncidence(float incidence);
void setTwist(float angle) { _twist = angle; } void setTwist(float angle) { _twist = angle; }
@ -67,31 +67,31 @@ public:
// Compile the thing into a bunch of Surface objects // Compile the thing into a bunch of Surface objects
void compile(); void compile();
const void getTip(float* tip) { Math::set3(_tip, tip);}; void getTip(float* tip) const { Math::set3(_tip, tip);};
// valid only after Wing::compile() was called // valid only after Wing::compile() was called
const float getSpan() { return _wingspan; }; float getSpan() const { return _wingspan; };
const float getArea() { return _wingspan*_meanChord; }; float getArea() const { return _wingspan*_meanChord; };
const float getAspectRatio() { return _aspectRatio; }; float getAspectRatio() const { return _aspectRatio; };
const float getSMC() { return _meanChord; }; float getSMC() const { return _meanChord; };
const float getMAC() { return _mac; }; // get length of MAC float getMAC() const { return _mac; }; // get length of MAC
const float getMACx() { return _macX; }; // get x-coord of MAC leading edge float getMACx() const { return _macX; }; // get x-coord of MAC leading edge
const float getMACy() { return _base[1]+_macRootDistance; }; // get y-coord of MAC leading edge float getMACy() const { return _base[1]+_macRootDistance; }; // get y-coord of MAC leading edge
const int numSurfaces() { return _surfs.size(); } int numSurfaces() const { return _surfs.size(); }
Surface* getSurface(int n) { return ((SurfRec*)_surfs.get(n))->surface; } Surface* getSurface(int n) { return ((SurfRec*)_surfs.get(n))->surface; }
const float getSurfaceWeight(int n) { return ((SurfRec*)_surfs.get(n))->weight; } float getSurfaceWeight(int n) const { return ((SurfRec*)_surfs.get(n))->weight; }
// The overall drag coefficient for the wing as a whole. Units are // The overall drag coefficient for the wing as a whole. Units are
// arbitrary. // arbitrary.
void setDragScale(float scale); void setDragScale(float scale);
const float getDragScale() { return _dragScale; } float getDragScale() const { return _dragScale; }
// The ratio of force along the Z (lift) direction of each wing // The ratio of force along the Z (lift) direction of each wing
// segment to that along the X (drag) direction. // segment to that along the X (drag) direction.
void setLiftRatio(float ratio); void setLiftRatio(float ratio);
const float getLiftRatio() { return _liftRatio; } float getLiftRatio() const { return _liftRatio; }
private: private:
void interp(const float* v1, const float* v2, const float frac, float* out); void interp(const float* v1, const float* v2, const float frac, float* out);