]> git.mxchange.org Git - flightgear.git/blobdiff - src/Systems/submodel.cxx
Boris Koenig:
[flightgear.git] / src / Systems / submodel.cxx
index d405e63d453f29c3851406da44a73813e809ddbb..e35d6554e35561541afdbacc0b1a245500cbce25 100644 (file)
@@ -13,6 +13,8 @@
 #include <AIModel/AIManager.hxx>
 
 
+const double SubmodelSystem::lbs_to_slugs = 0.031080950172;
+
 SubmodelSystem::SubmodelSystem ()
 {
     
@@ -23,6 +25,7 @@ SubmodelSystem::SubmodelSystem ()
   
   out[0] = out[1] = out[2] = 0;
   in[3] = out[3] = 1;
+  string contents_node;
 }
 
 SubmodelSystem::~SubmodelSystem ()
@@ -52,8 +55,8 @@ SubmodelSystem::init ()
 
     _user_speed_down_fps_node   = fgGetNode("/velocities/speed-down-fps",true);
     _user_speed_east_fps_node   = fgGetNode("/velocities/speed-east-fps",true);
-       _user_speed_north_fps_node  = fgGetNode("/velocities/speed-north-fps",true);
-       
+    _user_speed_north_fps_node  = fgGetNode("/velocities/speed-north-fps",true);
+
     ai = (FGAIManager*)globals->get_subsystem("ai_model");
 
 
@@ -124,6 +127,8 @@ SubmodelSystem::release (submodel* sm, double dt)
   entity.wind_from_east = IC.wind_from_east;
   entity.wind_from_north = IC.wind_from_north;
   entity.wind = sm->wind;
+  entity.cd = sm->cd;
+  entity.mass = IC.mass;
   ai->createBallistic( &entity );
  
   if (sm->count > 0) (sm->count)--; 
@@ -134,6 +139,7 @@ SubmodelSystem::release (submodel* sm, double dt)
 void
 SubmodelSystem::load ()
 {
+
     int i;
     SGPropertyNode *path = fgGetNode("/sim/systems/submodels/path");
     SGPropertyNode root;
@@ -161,7 +167,7 @@ SubmodelSystem::load ()
      sm->trigger        = fgGetNode(entry_node->getStringValue("trigger", "none"), true);
      sm->name           = entry_node->getStringValue("name", "none_defined");
      sm->model          = entry_node->getStringValue("model", "Models/Geometry/rocket.ac");
-     sm->speed          = entry_node->getDoubleValue("speed", 0.0);
+     sm->speed          = entry_node->getDoubleValue("speed", 2329.4 );
      sm->repeat         = entry_node->getBoolValue  ("repeat", false); 
      sm->delay          = entry_node->getDoubleValue("delay", 0.25); 
      sm->count          = entry_node->getIntValue   ("count", 1); 
@@ -171,18 +177,25 @@ SubmodelSystem::load ()
      sm->z_offset       = entry_node->getDoubleValue("z-offset", 0.0); 
      sm->yaw_offset     = entry_node->getDoubleValue("yaw-offset", 0.0); 
      sm->pitch_offset   = entry_node->getDoubleValue("pitch-offset", 0.0);
-     sm->drag_area      = entry_node->getDoubleValue("eda", 0.007);
+     sm->drag_area      = entry_node->getDoubleValue("eda", 0.034);
      sm->life           = entry_node->getDoubleValue("life", 900.0);
      sm->buoyancy       = entry_node->getDoubleValue("buoyancy", 0);
      sm->wind           = entry_node->getBoolValue  ("wind", false); 
      sm->first_time     = false;
+     sm->cd             = entry_node->getDoubleValue("cd", 0.193);
+     sm->weight         = entry_node->getDoubleValue("weight", 0.25);
+     sm->contents_node  = fgGetNode(entry_node->getStringValue("contents", "none"), true);
 
      sm->trigger->setBoolValue(false);
      sm->timer = sm->delay;
-
+     sm->contents = sm->contents_node->getDoubleValue();
      sm->prop = fgGetNode("/systems/submodels/submodel", i, true);
      sm->prop->tie("count", SGRawValuePointer<int>(&(sm->count)));
 
+//   sm->prop->tie("contents", SGRawValuePointer<double>(&(sm->contents)));
+//   sm->prop->tie("contents path", SGRawValuePointer<const char *>(&(sm->contents_node)));
      submodels.push_back( sm );
    }
 
@@ -195,10 +208,19 @@ void
 SubmodelSystem::transform( submodel* sm) 
 {
 
- // get initial conditions 
+// get initial conditions 
+// get the weight of the contents (lbs) and convert to mass (slugs)
+  sm->contents = sm->contents_node->getDoubleValue();
+  
+  IC.mass = (sm->weight + sm->contents) * lbs_to_slugs;;
+//  cout << IC.mass << endl;
+    
+// set contents to 0 in the parent
+   sm->contents_node->setDoubleValue(0); 
     
   IC.lat =        _user_lat_node->getDoubleValue();    
-  IC.lon =        _user_lon_node->getDoubleValue();       
+  IC.lon =        _user_lon_node->getDoubleValue();   
   IC.alt =        _user_alt_node->getDoubleValue();    
   IC.roll =       _user_roll_node->getDoubleValue();    // rotation about x axis 
   IC.elevation =  _user_pitch_node->getDoubleValue();   // rotation about y axis 
@@ -216,7 +238,8 @@ SubmodelSystem::transform( submodel* sm)
   in[0] = sm->x_offset;
   in[1] = sm->y_offset;
   in[2] = sm->z_offset; 
-
+  
 // pre-process the trig functions
 
     cosRx = cos(-IC.roll * SG_DEGREES_TO_RADIANS);
@@ -289,22 +312,22 @@ SubmodelSystem::transform( submodel* sm)
   // re-calculate speed, elevation and azimuth
 
    IC.speed = sqrt( IC.total_speed_north * IC.total_speed_north + 
-                      IC.total_speed_east * IC.total_speed_east +
-                                         IC.total_speed_down * IC.total_speed_down);
-                         
+                    IC.total_speed_east * IC.total_speed_east +
+                    IC.total_speed_down * IC.total_speed_down);
+
    IC.azimuth = atan(IC.total_speed_east/IC.total_speed_north) * SG_RADIANS_TO_DEGREES;
    
    // rationalise the output
    
    if (IC.total_speed_north <= 0){
     IC.azimuth = 180 + IC.azimuth;
-       }
+   }
    else{
      if(IC.total_speed_east <= 0){
      IC.azimuth = 360 + IC.azimuth;
-        }
+   }
   }
-        
     IC.elevation = -atan(IC.total_speed_down/sqrt(IC.total_speed_north * 
                        IC.total_speed_north + 
                        IC.total_speed_east * IC.total_speed_east)) * SG_RADIANS_TO_DEGREES;
@@ -323,3 +346,4 @@ SubmodelSystem::updatelat(double lat)
 
 
 
+