]> git.mxchange.org Git - flightgear.git/commitdiff
Vivian Meazza:
authorehofman <ehofman>
Sun, 5 Sep 2004 09:45:34 +0000 (09:45 +0000)
committerehofman <ehofman>
Sun, 5 Sep 2004 09:45:34 +0000 (09:45 +0000)
I've added another parameter to the submodel - wind.

It's activated by the entry <wind>true</wind> in the ../submodel.xml file.
If true, the submodel is affected by the local wind, otherwise not. The
parameter defaults to false. This is useful for exhausts and smoke, and
possibly all objects.

src/AIModel/AIBallistic.cxx
src/AIModel/AIBallistic.hxx
src/AIModel/AIManager.cxx
src/AIModel/AIManager.hxx
src/AIModel/AIScenario.cxx
src/AIModel/AIScenario.hxx
src/Systems/submodel.cxx
src/Systems/submodel.hxx

index 76e7a9485c6291ac7c4ca4c20fc2213d2e0c6fab..781f2ffd4a67edf89a2d14844170e1e3a325b706 100644 (file)
@@ -33,8 +33,9 @@ FGAIBallistic::FGAIBallistic(FGAIManager* mgr) {
     _otype = otBallistic;
     drag_area = 0.007;
     life_timer = 0.0;
-    gravity = 32;
-    }
+       gravity = 32;
+//     buoyancy = 64;
+       }
 
 FGAIBallistic::~FGAIBallistic() {
 }
@@ -91,7 +92,17 @@ void FGAIBallistic::setBuoyancy(double fpss) {
    buoyancy = fpss;
 }
 
+void FGAIBallistic::setWind_from_east(double fps) {
+   wind_from_east = fps;
+}
+
+void FGAIBallistic::setWind_from_north(double fps) {
+   wind_from_north = fps;
+}
 
+void FGAIBallistic::setWind(bool val) {
+   wind = val;
+}
 void FGAIBallistic::Run(double dt) {
 
    life_timer += dt;
@@ -99,7 +110,9 @@ void FGAIBallistic::Run(double dt) {
 
    double speed_north_deg_sec;
    double speed_east_deg_sec;
-
+   double wind_speed_from_north_deg_sec;
+   double wind_speed_from_east_deg_sec;
+      
    // the two drag calculations below assume sea-level density, 
    // mass of 0.03 slugs,  drag coeff of 0.295
    // adjust speed due to drag 
@@ -111,10 +124,27 @@ void FGAIBallistic::Run(double dt) {
    // 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;
+   
+   // convert wind speed (fps) to degrees per second
+   
+   if (!wind){
+      wind_from_north = 0;
+      wind_from_east = 0;
+         }
 
+   wind_speed_from_north_deg_sec = wind_from_north / ft_per_deg_lat;
+   wind_speed_from_east_deg_sec  = wind_from_east / ft_per_deg_lon;
+   
    // set new position
-   pos.setlat( pos.lat() + speed_north_deg_sec * dt);
-   pos.setlon( pos.lon() + speed_east_deg_sec * dt); 
+//   pos.setlat( pos.lat() + (speed_north_deg_sec * dt)  );
+//   pos.setlon( pos.lon() + (speed_east_deg_sec * dt)  ); 
+   // set new position
+   
+   pos.setlat( pos.lat() + (speed_north_deg_sec - wind_speed_from_north_deg_sec) * dt );
+   pos.setlon( pos.lon() + (speed_east_deg_sec - wind_speed_from_east_deg_sec) * dt ); 
 
    // adjust vertical speed for acceleration of gravity
    vs -= (gravity - buoyancy) * dt;
index 7dca97c7531257bfa58b01e6c42bed825105e76a..958cf952ac8f148ec261e73837cd91e8ab5147d6 100644 (file)
@@ -41,7 +41,10 @@ public:
     void setStabilization( bool val );
     void setDragArea( double a );
     void setLife( double seconds );
-    void setBuoyancy( double fps2 );
+    void setBuoyancy( double fpss );
+       void setWind_from_east( double fps );
+       void setWind_from_north( double fps );
+       void setWind( bool val );
        
 private:
 
@@ -51,8 +54,11 @@ private:
     bool aero_stabilized;   // if true, object will point where it's going
     double drag_area;       // equivalent drag area in ft2
     double life_timer;      // seconds
-    double gravity;         // fps2
-    double buoyancy;        // fps2
+       double gravity;         // fps2
+       double buoyancy;        // fps2
+       double wind_from_east;  // fps
+       double wind_from_north; // fps
+       bool wind;              // if true, local wind will be applied to object
                
     void Run(double dt);
 };
index 6269e8a268c1f311ec01aa9b6524e2ae2f553d5a..b81167a66725069b3406d78e6fca8f7a0e435f9e 100644 (file)
@@ -253,7 +253,8 @@ int FGAIManager::createShip( string path, FGAIFlightPlan* flightplan ) {
 
 int FGAIManager::createBallistic( string path, double latitude, double longitude,
                                   double altitude, double azimuth, double elevation,
-                                  double speed, double eda, double life, double buoyancy ) {
+                                  double speed, double eda, double life, double buoyancy,
+                                                                 double wind_from_east, double wind_from_north, bool wind ) {
 
         FGAIBallistic* ai_ballistic = new FGAIBallistic(this);
         ai_list.push_back(ai_ballistic);
@@ -269,6 +270,9 @@ int FGAIManager::createBallistic( string path, double latitude, double longitude
         ai_ballistic->setDragArea(eda);
         ai_ballistic->setLife(life);
         ai_ballistic->setBuoyancy(buoyancy);
+               ai_ballistic->setWind_from_east(wind_from_east);
+               ai_ballistic->setWind_from_north(wind_from_north);
+               ai_ballistic->setWind(wind);
         ai_ballistic->init();
         ai_ballistic->bind();
         return ai_ballistic->getID();
@@ -308,7 +312,6 @@ int FGAIManager::createThermal( double latitude, double longitude,
         return ai_thermal->getID();
 }
 
-
 void FGAIManager::destroyObject( int ID ) {
         ai_list_itr = ai_list.begin();
         while(ai_list_itr != ai_list.end()) {
@@ -387,7 +390,8 @@ void FGAIManager::processScenario( string filename ) {
       } else if (en->aitype == "ballistic"){
         createBallistic( en->model_path, en->latitude, en->longitude,
                          en->altitude, en->azimuth, en->elevation, en->speed,
-                         en->eda, en->life, en->buoyancy );
+                         en->eda, en->life, en->buoyancy, en->wind_from_east,
+                                                en-> wind_from_north, en->wind);
       }      
     }
   }
index afa23eac6da0c91e1961537d359ea5f087331e51..809efba1e9f56fdb37f6b8d48e9a8ddcb2115596 100644 (file)
@@ -91,17 +91,20 @@ public:
     int createShip(     string path,        // path to exterior model
                         FGAIFlightPlan *flightplan );
 
-    int createBallistic( string path,       // path to exterior model
-                         double latitude,   // in degrees -90 to 90
-                         double longitude,  // in degrees -180 to 180
-                         double altitude,   // in feet
-                         double azimuth,    // in degrees (same as heading)
-                         double elevation,  // in degrees (same as pitch)
-                         double speed,      // in feet per second
-                         double eda,        // equivalent drag area, ft2
-                         double life,       // life span in seconds
-                         double buoyancy    // acceleration in ft per second2
-                         );
+    int createBallistic( string path,           // path to exterior model
+                         double latitude,       // in degrees -90 to 90
+                         double longitude,      // in degrees -180 to 180
+                         double altitude,       // in feet
+                         double azimuth,        // in degrees (same as heading)
+                         double elevation,      // in degrees (same as pitch)
+                         double speed,          // in feet per second
+                         double eda,            // equivalent drag area, ft2
+                         double life,           // life span in seconds
+                         double buoyancy,       // acceleration due to buoyancy feet per second2
+                         double wind_from_east, // in feet per second
+                                                double wind_from_north,  // in feet per second
+                                                bool wind               // val
+                                                );
      
     int createStorm( string path,        // path to exterior model
                      double latitude,    // in degrees -90 to 90
@@ -115,7 +118,19 @@ public:
                        double strength,    // in feet per second
                        double diameter );  // in feet
 
-        
+    int createSmoke     ( string path,       // path to exterior model
+                         double latitude,   // in degrees -90 to 90
+                         double longitude,  // in degrees -180 to 180
+                         double altitude,   // in feet
+                         double azimuth,    // in degrees (same as heading)
+                         double elevation,  // in degrees (same as pitch)
+                         double speed,      // in feet per second
+                         double eda,        // equivalent drag area, ft2
+                        double life,        // life span in seconds
+                        double buoyancy    // acceleration due to buoyancy feet per second2
+                         );
+
+                 
     void destroyObject( int ID );
 
     inline double get_user_latitude() { return user_latitude; }
index a431c2f5afeaf488fbedc75809d4e8d1485ff1e7..af9c525dff0ffba53abb444abd381562ce3fb7ab 100644 (file)
@@ -71,7 +71,10 @@ FGAIScenario::FGAIScenario(string filename)
      en->diameter       = entry_node->getDoubleValue("diameter-ft", 0.0);
      en->eda            = entry_node->getDoubleValue("eda", 0.007);
      en->life           = entry_node->getDoubleValue("life", 900.0);
-     en->buoyancy       = entry_node->getDoubleValue("buoyancy", 0); 
+        en->buoyancy       = entry_node->getDoubleValue("buoyancy", 0);
+        en->wind_from_east = entry_node->getDoubleValue("wind_from_east", 0);
+        en->wind_from_north = entry_node->getDoubleValue("wind_from_north", 0);
+        en->wind            = entry_node->getBoolValue("wind", false);
    }
 
   entry_iterator = entries.begin();
index cb798f093b29553541dbda97b1856e4e55ef1323..5118ddf6e6eec0c704e783e4fdc0055d7887b86d 100644 (file)
@@ -36,21 +36,24 @@ public:
    string aircraft_class;
    string model_path;
    string flightplan;
-   double repeat;       // in seconds
-   double latitude;     // used if no flightplan defined
-   double longitude;    // used if no flightplan defined
-   double altitude;     // used if no flightplan defined
-   double speed;        // used if no flightplan defined
-   double heading;      // used if no flightplan defined
-   double roll;         // used if no flightplan defined
-   double azimuth;      // used by ballistic objects
-   double elevation;    // used by ballistic objects
-   double rudder;       // used by ship objects 
-   double strength;     // used by thermal objects
-   double diameter;     // used by thermal objects
-   double eda;          // used by ballistic objects
-   double life;         // life span in seconds
-   double buoyancy;     // acceleration in ft per sec2
+   double repeat;             // in seconds
+   double latitude;           // used if no flightplan defined
+   double longitude;          // used if no flightplan defined
+   double altitude;           // used if no flightplan defined
+   double speed;              // used if no flightplan defined
+   double heading;            // used if no flightplan defined
+   double roll;               // used if no flightplan defined
+   double azimuth;            // used by ballistic objects
+   double elevation;          // used by ballistic objects
+   double rudder;             // used by ship objects 
+   double strength;           // used by thermal objects
+   double diameter;           // used by thermal objects
+   double eda;                // used by ballistic objects
+   double life;               // life span in seconds
+   double buoyancy;           // acceleration in ft per sec2
+   double wind_from_east;     // in feet per second
+   double wind_from_north;    // in feet per second
+   bool wind;
   } entry;
 
    FGAIScenario(string filename);
index 1c68551aba26e719cde45abde14208c47b68dad3..47c2a2cd7bfdab4f594bbf950a2025f903c33eb6 100644 (file)
@@ -30,7 +30,7 @@ SubmodelSystem::init ()
 {
     load();
     _serviceable_node = fgGetNode("/sim/systems/submodels/serviceable", true);
-       
+
     _user_lat_node = fgGetNode("/position/latitude-deg", true);
     _user_lon_node = fgGetNode("/position/longitude-deg", true);
     _user_alt_node = fgGetNode("/position/altitude-ft", true);
@@ -41,7 +41,9 @@ SubmodelSystem::init ()
     _user_yaw_node =     fgGetNode("/orientation/yaw-deg", true);
 
     _user_speed_node = fgGetNode("/velocities/uBody-fps", true);
-       
+
+    _user_wind_from_east_node  = fgGetNode("/environment/wind-from-east-fps",true);
+    _user_wind_from_north_node = fgGetNode("/environment/wind-from-north-fps",true);
 
     ai = (FGAIManager*)globals->get_subsystem("ai_model");
 }
@@ -86,12 +88,15 @@ SubmodelSystem::release (submodel* sm, double dt)
   if (sm->timer < sm->delay) return false;
   sm->timer = 0.0;
 
-  transform(sm);  // calculate submodel's initial conditions in world-coordinates
+  // calculate submodel's initial conditions in world-coordinates
+  transform(sm);
 
   //cout << "Creating a submodel." << endl; 
   int rval = ai->createBallistic( sm->model, IC.lat, IC.lon, IC.alt, IC.azimuth,
-                                  IC.elevation, IC.speed, sm->drag_area, sm->life,
-                                 sm-> buoyancy );
+                                  IC.elevation, IC.speed, 
+                                 sm->drag_area, sm->life,
+                                 sm->buoyancy,
+                                 IC.wind_from_east, IC.wind_from_north, sm->wind);
   //cout << "Submodel created." << endl;
   if (sm->count > 0) (sm->count)--; 
 
@@ -141,6 +146,7 @@ SubmodelSystem::load ()
      sm->drag_area      = entry_node->getDoubleValue("eda", 0.007);
      sm->life           = entry_node->getDoubleValue("life", 900.0);
      sm->buoyancy       = entry_node->getDoubleValue("buoyancy", 0);
+     sm->wind           = entry_node->getBoolValue  ("wind", false); 
 
      sm->trigger->setBoolValue(false);
      sm->timer = sm->delay;
@@ -159,15 +165,18 @@ SubmodelSystem::load ()
 void
 SubmodelSystem::transform( submodel* sm) 
 {
-  IC.lat =            _user_lat_node->getDoubleValue();
-  IC.lon =            _user_lon_node->getDoubleValue();
-  IC.alt =            _user_alt_node->getDoubleValue();
-  IC.azimuth =        _user_heading_node->getDoubleValue() + sm->yaw_offset;
-  IC.elevation =      _user_pitch_node->getDoubleValue() + sm->pitch_offset;
-  IC.speed =          _user_speed_node->getDoubleValue() + sm->speed;
-  
-}
+  IC.lat =             _user_lat_node->getDoubleValue();
+  IC.lon =             _user_lon_node->getDoubleValue();
+  IC.alt =             _user_alt_node->getDoubleValue();
+  IC.azimuth =         _user_heading_node->getDoubleValue() + sm->yaw_offset;
+  IC.elevation =       _user_pitch_node->getDoubleValue() + sm->pitch_offset;
+  IC.speed =           _user_speed_node->getDoubleValue() + sm->speed;
+  IC.wind_from_east =  _user_wind_from_east_node->getDoubleValue();
+  IC.wind_from_north = _user_wind_from_north_node->getDoubleValue();
+//  IC.wind_from_east =  4;
+//   IC.wind_from_north = 5;
 
+}
 
 // end of submodel.cxx
 
index 79c141ec3ec2705e494069747ec435fd4b079abb..7e8c38188c1af29aa697ad5d9b9dd00049a0c6d0 100644 (file)
@@ -44,7 +44,8 @@ public:
   double             drag_area; 
   double             life;
   double             buoyancy;
-  
+  bool               wind;
+    
  } submodel; 
 
  typedef struct {
@@ -54,7 +55,9 @@ public:
   double     azimuth;
   double     elevation;
   double     speed;
+  double     wind_from_east;
+  double     wind_from_north;
+  
  } IC_struct;  
 
     SubmodelSystem ();
@@ -89,7 +92,8 @@ private:
     SGPropertyNode_ptr _user_roll_node;
     SGPropertyNode_ptr _user_yaw_node;
     SGPropertyNode_ptr _user_speed_node;
-
+       SGPropertyNode_ptr _user_wind_from_east_node;
+    SGPropertyNode_ptr _user_wind_from_north_node;
     FGAIManager* ai;
     IC_struct  IC;
 };