From 924e95fec2db4a1539f97ab3edbff8fb3b87c044 Mon Sep 17 00:00:00 2001 From: ehofman Date: Fri, 2 Apr 2004 14:41:35 +0000 Subject: [PATCH] Frederic Bouvier: Call sgLoad3DModel from simgear instead of duplicating code. --- src/Model/model_panel.cxx | 111 +++----------------------------------- 1 file changed, 6 insertions(+), 105 deletions(-) diff --git a/src/Model/model_panel.cxx b/src/Model/model_panel.cxx index 692270138..732e0691a 100644 --- a/src/Model/model_panel.cxx +++ b/src/Model/model_panel.cxx @@ -9,19 +9,9 @@ #include -#include // for strcmp() - -#include - -#include #include -#include -#include -#include #include -#include -#include #include #include "panelnode.hxx" @@ -30,111 +20,22 @@ SG_USING_STD(vector); - +static +ssgEntity *load_panel(SGPropertyNode *n) +{ + return new FGPanelNode(n); +} //////////////////////////////////////////////////////////////////////// // Global functions. //////////////////////////////////////////////////////////////////////// -// FIXME: should attempt to share more of the code with -// fgLoad3DModel() since these routines are almost identical with the -// exception of the panel node section. - ssgBranch * fgLoad3DModelPanel( const string &fg_root, const string &path, SGPropertyNode *prop_root, double sim_time_sec ) { - ssgBranch * model = 0; - SGPropertyNode props; - - // Load the 3D aircraft object itself - SGPath modelpath = path; - if ( !ulIsAbsolutePathName( path.c_str() ) ) { - SGPath tmp = fg_root; - tmp.append(modelpath.str()); - modelpath = tmp; - } - - // Check for an XML wrapper - if (modelpath.str().substr(modelpath.str().size() - 4, 4) == ".xml") { - readProperties(modelpath.str(), &props); - if (props.hasValue("/path")) { - modelpath = modelpath.dir(); - modelpath.append(props.getStringValue("/path")); - } else { - if (model == 0) - model = new ssgBranch; - } - } - - // Assume that textures are in - // the same location as the XML file. - if (model == 0) { - ssgTexturePath((char *)modelpath.dir().c_str()); - model = (ssgBranch *)ssgLoad((char *)modelpath.c_str()); - if (model == 0) - throw sg_exception("Failed to load 3D model"); - } - - // Set up the alignment node - ssgTransform * alignmainmodel = new ssgTransform; - alignmainmodel->addKid(model); - sgMat4 res_matrix; - sgMakeOffsetsMatrix(&res_matrix, - props.getFloatValue("/offsets/heading-deg", 0.0), - props.getFloatValue("/offsets/roll-deg", 0.0), - props.getFloatValue("/offsets/pitch-deg", 0.0), - props.getFloatValue("/offsets/x-m", 0.0), - props.getFloatValue("/offsets/y-m", 0.0), - props.getFloatValue("/offsets/z-m", 0.0)); - alignmainmodel->setTransform(res_matrix); - - unsigned int i; - - // Load panels - vector panel_nodes = props.getChildren("panel"); - for (i = 0; i < panel_nodes.size(); i++) { - SG_LOG(SG_INPUT, SG_DEBUG, "Loading a panel"); - FGPanelNode * panel = new FGPanelNode(panel_nodes[i]); - if (panel_nodes[i]->hasValue("name")) - panel->setName((char *)panel_nodes[i]->getStringValue("name")); - model->addKid(panel); - } - - // Load sub-models - vector model_nodes = props.getChildren("model"); - for (i = 0; i < model_nodes.size(); i++) { - SGPropertyNode_ptr node = model_nodes[i]; - ssgTransform * align = new ssgTransform; - sgMat4 res_matrix; - sgMakeOffsetsMatrix(&res_matrix, - node->getFloatValue("offsets/heading-deg", 0.0), - node->getFloatValue("offsets/roll-deg", 0.0), - node->getFloatValue("offsets/pitch-deg", 0.0), - node->getFloatValue("offsets/x-m", 0.0), - node->getFloatValue("offsets/y-m", 0.0), - node->getFloatValue("offsets/z-m", 0.0)); - align->setTransform(res_matrix); - - ssgBranch * kid = sgLoad3DModel( fg_root, node->getStringValue("path"), - prop_root, sim_time_sec ); - align->addKid(kid); - align->setName(node->getStringValue("name", "")); - model->addKid(align); - } - - // Load animations - vector animation_nodes = props.getChildren("animation"); - for (i = 0; i < animation_nodes.size(); i++) { - const char * name = animation_nodes[i]->getStringValue("name", 0); - vector name_nodes = - animation_nodes[i]->getChildren("object-name"); - sgMakeAnimation( model, name, name_nodes, prop_root, animation_nodes[i], - sim_time_sec); - } - - return alignmainmodel; + return sgLoad3DModel( fg_root, path, prop_root, sim_time_sec, load_panel ); } -- 2.39.5