From 0e2862105173185e1104283271cd392101f6d9b1 Mon Sep 17 00:00:00 2001 From: onox Date: Sat, 25 Apr 2015 12:33:34 +0200 Subject: [PATCH] Use InputValue for yaw-offset and pitch-offset Signed-off-by: onox Signed-off-by: Erik Hofman --- src/AIModel/submodel.cxx | 49 +++++++++++++++++++++++++++++++++------- src/AIModel/submodel.hxx | 8 +++++-- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/AIModel/submodel.cxx b/src/AIModel/submodel.cxx index b3721466a..70a13eec3 100644 --- a/src/AIModel/submodel.cxx +++ b/src/AIModel/submodel.cxx @@ -28,6 +28,8 @@ using std::endl; using std::string; using std::vector; +using FGXMLAutopilot::InputValue; + const double FGSubmodelMgr::lbs_to_slugs = 0.031080950172; FGSubmodelMgr::FGSubmodelMgr() @@ -264,6 +266,14 @@ bool FGSubmodelMgr::release(submodel *sm, double dt) sm->first_time = false; } + double yaw_offset = 0.0; + double pitch_offset = 0.0; + + if (sm->yaw_node != 0) + yaw_offset = sm->yaw_node->get_value(); + if (sm->pitch_node != 0) + pitch_offset = sm->pitch_node->get_value(); + transform(sm); // calculate submodel's initial conditions in world-coordinates FGAIBallistic* ballist = new FGAIBallistic; @@ -302,8 +312,8 @@ bool FGSubmodelMgr::release(submodel *sm, double dt) ballist->setXoffset(sm->x_offset); ballist->setYoffset(sm->y_offset); ballist->setZoffset(sm->z_offset); - ballist->setPitchoffset(sm->pitch_offset); - ballist->setYawoffset(sm->yaw_offset); + ballist->setPitchoffset(pitch_offset); + ballist->setYawoffset(yaw_offset); ballist->setParentNodes(_selected_ac); ballist->setContentsNode(sm->contents_node); ballist->setWeight(sm->weight); @@ -353,6 +363,13 @@ void FGSubmodelMgr::transform(submodel *sm) if (sm->speed_node != 0) sm->speed = sm->speed_node->getDoubleValue(); + double yaw_offset = 0.0; + double pitch_offset = 0.0; + + if (sm->yaw_node != 0) + yaw_offset = sm->yaw_node->get_value(); + if (sm->pitch_node != 0) + pitch_offset = sm->pitch_node->get_value(); //cout << " name " << name << " id " << id << " sub id" << sub_id << endl; @@ -434,8 +451,8 @@ void FGSubmodelMgr::transform(submodel *sm) // Get submodel initial velocity vector angles in XZ and XY planes. // This vector should be added to aircraft's vector. - IC.elevation += (sm->yaw_offset * sinRx) + (sm->pitch_offset * cosRx); - IC.azimuth += (sm->yaw_offset * cosRx) - (sm->pitch_offset * sinRx); + IC.elevation += (yaw_offset * sinRx) + (pitch_offset * cosRx); + IC.azimuth += (yaw_offset * cosRx) - (pitch_offset * sinRx); // calculate the total speed north IC.total_speed_north = sm->speed * cos(IC.elevation * SG_DEGREES_TO_RADIANS) @@ -547,8 +564,6 @@ void FGSubmodelMgr::setData(int id, const string& path, bool serviceable) sm->x_offset = entry_node->getDoubleValue("x-offset", 0.0); sm->y_offset = entry_node->getDoubleValue("y-offset", 0.0); 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.034); sm->life = entry_node->getDoubleValue("life", 900.0); sm->buoyancy = entry_node->getDoubleValue("buoyancy", 0); @@ -571,6 +586,16 @@ void FGSubmodelMgr::setData(int id, const string& path, bool serviceable) sm->random = entry_node->getBoolValue("random", false); sm->randomness = entry_node->getDoubleValue("randomness", 0.5); + SGPropertyNode_ptr a = entry_node->getNode("yaw-offset"); + SGPropertyNode_ptr b = entry_node->getNode("pitch-offset"); + SGPropertyNode_ptr prop_root = fgGetNode("/", true); + sm->yaw_node = 0; + sm->pitch_node = 0; + if (a != 0) + sm->yaw_node = new InputValue(*prop_root, *a); + if (b != 0) + sm->pitch_node = new InputValue(*prop_root, *b); + if (sm->contents_node != 0) sm->contents = sm->contents_node->getDoubleValue(); @@ -652,8 +677,6 @@ void FGSubmodelMgr::setSubData(int id, const string& path, bool serviceable) sm->x_offset = entry_node->getDoubleValue("x-offset", 0.0); sm->y_offset = entry_node->getDoubleValue("y-offset", 0.0); 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.034); sm->life = entry_node->getDoubleValue("life", 900.0); sm->buoyancy = entry_node->getDoubleValue("buoyancy", 0); @@ -676,6 +699,16 @@ void FGSubmodelMgr::setSubData(int id, const string& path, bool serviceable) sm->random = entry_node->getBoolValue("random", false); sm->randomness = entry_node->getDoubleValue("randomness", 0.5); + SGPropertyNode_ptr a = entry_node->getNode("yaw-offset"); + SGPropertyNode_ptr b = entry_node->getNode("pitch-offset"); + SGPropertyNode_ptr prop_root = fgGetNode("/", true); + sm->yaw_node = 0; + sm->pitch_node = 0; + if (a != 0) + sm->yaw_node = new InputValue(*prop_root, *a); + if (b != 0) + sm->pitch_node = new InputValue(*prop_root, *b); + if (sm->contents_node != 0) sm->contents = sm->contents_node->getDoubleValue(); diff --git a/src/AIModel/submodel.hxx b/src/AIModel/submodel.hxx index 5d01d3d76..5546f0df2 100644 --- a/src/AIModel/submodel.hxx +++ b/src/AIModel/submodel.hxx @@ -15,9 +15,13 @@ #include #include +#include + #include #include +using FGXMLAutopilot::InputValue_ptr; + class FGAIBase; class FGAIManager; @@ -32,6 +36,8 @@ public: SGPropertyNode_ptr contents_node; SGPropertyNode_ptr submodel_node; SGPropertyNode_ptr speed_node; + InputValue_ptr yaw_node; + InputValue_ptr pitch_node; std::string name; std::string model; @@ -44,8 +50,6 @@ public: double x_offset; double y_offset; double z_offset; - double yaw_offset; - double pitch_offset; double drag_area; double life; double buoyancy; -- 2.39.5