David Culp:
The AIBase code was updated to fix an uninitialized pointer, and the AIBallistic code has an improved FDM.
This commit is contained in:
parent
4d9a30addc
commit
72b201d96c
2 changed files with 18 additions and 21 deletions
|
@ -39,8 +39,6 @@ FGAIBallistic::~FGAIBallistic() {
|
||||||
|
|
||||||
bool FGAIBallistic::init() {
|
bool FGAIBallistic::init() {
|
||||||
FGAIBase::init();
|
FGAIBase::init();
|
||||||
vs = sin( elevation * 0.017453293 ) * speed;
|
|
||||||
hs = cos( elevation * 0.017453293 ) * speed;
|
|
||||||
aero_stabilized = true;
|
aero_stabilized = true;
|
||||||
hdg = azimuth;
|
hdg = azimuth;
|
||||||
pitch = elevation;
|
pitch = elevation;
|
||||||
|
@ -48,11 +46,11 @@ bool FGAIBallistic::init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGAIBallistic::bind() {
|
void FGAIBallistic::bind() {
|
||||||
FGAIBase::bind();
|
// FGAIBase::bind();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGAIBallistic::unbind() {
|
void FGAIBallistic::unbind() {
|
||||||
FGAIBase::unbind();
|
// FGAIBase::unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGAIBallistic::update(double dt) {
|
void FGAIBallistic::update(double dt) {
|
||||||
|
@ -63,12 +61,12 @@ void FGAIBallistic::update(double dt) {
|
||||||
|
|
||||||
|
|
||||||
void FGAIBallistic::setAzimuth(double az) {
|
void FGAIBallistic::setAzimuth(double az) {
|
||||||
azimuth = az;
|
hdg = azimuth = az;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FGAIBallistic::setElevation(double el) {
|
void FGAIBallistic::setElevation(double el) {
|
||||||
elevation = el;
|
pitch = elevation = el;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -84,17 +82,12 @@ void FGAIBallistic::Run(double dt) {
|
||||||
|
|
||||||
// the two drag calculations below assume sea-level density,
|
// the two drag calculations below assume sea-level density,
|
||||||
// mass of 0.03 slugs, drag coeff of 0.295, frontal area of 0.007 ft2
|
// mass of 0.03 slugs, drag coeff of 0.295, frontal area of 0.007 ft2
|
||||||
// adjust horizontal speed due to drag
|
// adjust speed due to drag
|
||||||
hs -= 0.000082 * hs * hs * dt;
|
speed -= 0.000082 * speed * speed * dt;
|
||||||
if ( hs < 0.0 ) hs = 0.0;
|
if ( speed < 0.0 ) speed = 0.0;
|
||||||
|
vs = sin( pitch * SG_DEGREES_TO_RADIANS ) * speed;
|
||||||
|
hs = cos( pitch * SG_DEGREES_TO_RADIANS ) * speed;
|
||||||
|
|
||||||
// adjust vertical speed due to drag
|
|
||||||
if (vs > 0.0) {
|
|
||||||
vs -= 0.000082 * vs * vs * dt;
|
|
||||||
} else {
|
|
||||||
vs += 0.000082 * vs * vs * dt;
|
|
||||||
}
|
|
||||||
|
|
||||||
// convert horizontal speed (fps) to degrees per second
|
// convert horizontal speed (fps) to degrees per second
|
||||||
speed_north_deg_sec = cos(hdg / SG_RADIANS_TO_DEGREES) * hs / ft_per_deg_lat;
|
speed_north_deg_sec = cos(hdg / SG_RADIANS_TO_DEGREES) * hs / ft_per_deg_lat;
|
||||||
speed_east_deg_sec = sin(hdg / SG_RADIANS_TO_DEGREES) * hs / ft_per_deg_lon;
|
speed_east_deg_sec = sin(hdg / SG_RADIANS_TO_DEGREES) * hs / ft_per_deg_lon;
|
||||||
|
@ -103,16 +96,19 @@ void FGAIBallistic::Run(double dt) {
|
||||||
pos.setlat( pos.lat() + speed_north_deg_sec * dt);
|
pos.setlat( pos.lat() + speed_north_deg_sec * dt);
|
||||||
pos.setlon( pos.lon() + speed_east_deg_sec * dt);
|
pos.setlon( pos.lon() + speed_east_deg_sec * dt);
|
||||||
|
|
||||||
|
// adjust altitude (feet)
|
||||||
|
altitude += vs * dt;
|
||||||
|
pos.setelev(altitude * SG_FEET_TO_METER);
|
||||||
|
|
||||||
// adjust vertical speed for acceleration of gravity
|
// adjust vertical speed for acceleration of gravity
|
||||||
vs -= 32.17 * dt;
|
vs -= 32.17 * dt;
|
||||||
|
|
||||||
// adjust altitude (meters)
|
// recalculate pitch (velocity vector) if aerostabilized
|
||||||
altitude += vs * dt * SG_FEET_TO_METER;
|
|
||||||
pos.setelev(altitude);
|
|
||||||
|
|
||||||
// adjust pitch if aerostabilized
|
|
||||||
if (aero_stabilized) pitch = atan2( vs, hs ) * SG_RADIANS_TO_DEGREES;
|
if (aero_stabilized) pitch = atan2( vs, hs ) * SG_RADIANS_TO_DEGREES;
|
||||||
|
|
||||||
|
// recalculate total speed
|
||||||
|
speed = sqrt( vs * vs + hs * hs);
|
||||||
|
|
||||||
// set destruction flag if altitude less than sea level -1000
|
// set destruction flag if altitude less than sea level -1000
|
||||||
if (altitude < -1000.0) setDie(true);
|
if (altitude < -1000.0) setDie(true);
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ FGAIBase::FGAIBase() {
|
||||||
model = 0;
|
model = 0;
|
||||||
_otype = otNull;
|
_otype = otNull;
|
||||||
index = 0;
|
index = 0;
|
||||||
|
fp = (FGAIFlightPlan*)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
FGAIBase::~FGAIBase() {
|
FGAIBase::~FGAIBase() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue