]> git.mxchange.org Git - flightgear.git/commitdiff
David Culp:
authorehofman <ehofman>
Sat, 21 Aug 2004 12:24:54 +0000 (12:24 +0000)
committerehofman <ehofman>
Sat, 21 Aug 2004 12:24:54 +0000 (12:24 +0000)
The AIBase code was updated to fix an uninitialized pointer, and the
AIBallistic code has an improved FDM.

src/AIModel/AIBallistic.cxx
src/AIModel/AIBase.cxx

index 63fceb8653d163473914eff3349e41c7b3ae0a61..1a752f7e4f09fea619048b1c04e8f8167070e50e 100644 (file)
@@ -39,8 +39,6 @@ FGAIBallistic::~FGAIBallistic() {
 
 bool FGAIBallistic::init() {
    FGAIBase::init();
-   vs = sin( elevation * 0.017453293 ) * speed;
-   hs = cos( elevation * 0.017453293 ) * speed;
    aero_stabilized =  true;
    hdg = azimuth;
    pitch = elevation;
@@ -48,11 +46,11 @@ bool FGAIBallistic::init() {
 }
 
 void FGAIBallistic::bind() {
-    FGAIBase::bind();
+//    FGAIBase::bind();
 }
 
 void FGAIBallistic::unbind() {
-    FGAIBase::unbind();
+//    FGAIBase::unbind();
 }
 
 void FGAIBallistic::update(double dt) {
@@ -63,12 +61,12 @@ void FGAIBallistic::update(double dt) {
 
 
 void FGAIBallistic::setAzimuth(double az) {
-   azimuth = az;
+   hdg = azimuth = az;
 }
 
 
 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, 
    // mass of 0.03 slugs,  drag coeff of 0.295, frontal area of 0.007 ft2 
-   // adjust horizontal speed due to drag 
-   hs -= 0.000082 * hs * hs * dt;
-   if ( hs < 0.0 ) hs = 0.0;
-
-   // adjust vertical speed due to drag
-   if (vs > 0.0) {
-     vs -= 0.000082 * vs * vs * dt;
-   } else {
-     vs += 0.000082 * vs * vs * dt;
-   }
-   
+   // adjust speed due to drag 
+   speed -= 0.000082 * speed * speed * dt;
+   if ( speed < 0.0 ) speed = 0.0;
+   vs = sin( pitch * SG_DEGREES_TO_RADIANS ) * speed;
+   hs = cos( pitch * SG_DEGREES_TO_RADIANS ) * speed;
+
    // convert horizontal speed (fps) to degrees per second
    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;
@@ -103,16 +96,19 @@ void FGAIBallistic::Run(double dt) {
    pos.setlat( pos.lat() + speed_north_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
    vs -= 32.17 * dt;
 
-   // adjust altitude (meters)
-   altitude += vs * dt * SG_FEET_TO_METER;
-   pos.setelev(altitude); 
-
-   // adjust pitch if aerostabilized
+   // recalculate pitch (velocity vector) if aerostabilized
    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
    if (altitude < -1000.0) setDie(true);
 
index 6b6b7f9e10184d00b1c4ec044f68ca7ccb20ab9a..dc48ca2b9f8ecabfe6d6051a635e015adccf10fb 100644 (file)
@@ -55,6 +55,7 @@ FGAIBase::FGAIBase() {
     model = 0;
     _otype = otNull;
     index = 0;
+    fp = (FGAIFlightPlan*)0;
 }
 
 FGAIBase::~FGAIBase() {