From 3d4bec275b3c10ff7c07483b536a1903701a45c0 Mon Sep 17 00:00:00 2001 From: david Date: Mon, 25 Feb 2002 20:07:34 +0000 Subject: [PATCH] If the model path specified ends with .xml, then read properties from the XML file, including the path to the 3D file. This change obsoletes the existing /sim/model/*-offset-deg and /sim/model/*-offset-m properties in the main property tree, and replaces them with /offsets/*-deg and /offsets/*-m in the model property file. The /path property in the model XML file is relative to the XML file's location rather than FG_ROOT. --- src/Main/model.cxx | 36 ++++++++++++++++++++++++------------ src/Main/model.hxx | 2 ++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/Main/model.cxx b/src/Main/model.cxx index 7bfbcd839..5d20a357b 100644 --- a/src/Main/model.cxx +++ b/src/Main/model.cxx @@ -13,6 +13,7 @@ #include #include #include +#include #include "globals.hxx" #include "fg_props.hxx" @@ -45,7 +46,8 @@ find_named_node (ssgEntity * node, const string &name) } FGAircraftModel::FGAircraftModel () - : _object(0), + : _props(new SGPropertyNode), + _object(0), _selector(new ssgSelector), _position(new ssgTransform), _prop_position(0) @@ -54,6 +56,7 @@ FGAircraftModel::FGAircraftModel () FGAircraftModel::~FGAircraftModel () { + delete _props; // since the nodes are attached to the scene graph, they'll be // deleted automatically } @@ -67,6 +70,18 @@ FGAircraftModel::init () // Load the 3D aircraft object itself SGPath path = globals->get_fg_root(); path.append(fgGetString("/sim/model/path", "Models/Geometry/glider.ac")); + + if (path.str().substr(path.str().size() - 4, 4) == ".xml") { + readProperties(path.str(), _props); + if (_props->hasValue("/path")) { + path = path.dir();; + path.append(_props->getStringValue("/path")); + } else { + path = globals->get_fg_root(); + path.append("Models/Geometry/glider.ac"); + } + } + ssgTexturePath((char *)path.dir().c_str()); _object = ssgLoad((char *)path.c_str()); if (_object == 0) { @@ -93,12 +108,12 @@ FGAircraftModel::init () sgMat4 rot_matrix; sgMat4 off_matrix; sgMat4 res_matrix; - float h_rot = fgGetFloat("/sim/model/heading-offset-deg", 0.0); - float p_rot = fgGetFloat("/sim/model/roll-offset-deg", 0.0); - float r_rot = fgGetFloat("/sim/model/pitch-offset-deg", 0.0); - float x_off = fgGetFloat("/sim/model/x-offset-m", 0.0); - float y_off = fgGetFloat("/sim/model/y-offset-m", 0.0); - float z_off = fgGetFloat("/sim/model/z-offset-m", 0.0); + float h_rot = _props->getFloatValue("/offsets/heading-deg", 0.0); + float p_rot = _props->getFloatValue("/offsets/roll-deg", 0.0); + float r_rot = _props->getFloatValue("/offsets/pitch-deg", 0.0); + float x_off = _props->getFloatValue("/offsets/x-m", 0.0); + float y_off = _props->getFloatValue("/offsets/y-m", 0.0); + float z_off = _props->getFloatValue("/offsets/z-m", 0.0); sgMakeRotMat4(rot_matrix, h_rot, p_rot, r_rot); sgMakeTransMat4(off_matrix, x_off, y_off, z_off); sgMultMat4(res_matrix, off_matrix, rot_matrix); @@ -140,12 +155,9 @@ FGAircraftModel::update (int dt) prop_rotation -= 360; // END TEMPORARY KLUDGE - if (globals->get_viewmgr()->get_current() == 0 - && !fgGetBool("/sim/model/enable-interior")) { + if (globals->get_viewmgr()->get_current() == 0) { _selector->select(false); } else { - // TODO: use correct alignment in pilot - // view. _selector->select(true); FGViewerRPH *pilot_view = (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 ); @@ -170,7 +182,7 @@ FGAircraftModel::update (int dt) // START TEMPORARY KLUDGE if (_prop_position != 0) { - double offset = fgGetDouble("/tmp/offset", -.75); + double offset = -.75; sgMat4 tmp; sgMakeTransMat4(prop_matrix, 0, 0, offset); sgMakeRotMat4(tmp, 0, 0, prop_rotation); diff --git a/src/Main/model.hxx b/src/Main/model.hxx index ab2890585..e92884523 100644 --- a/src/Main/model.hxx +++ b/src/Main/model.hxx @@ -11,6 +11,7 @@ #endif #include "fgfs.hxx" +#include #include class FGAircraftModel : public FGSubsystem @@ -27,6 +28,7 @@ public: private: + SGPropertyNode * _props; ssgEntity * _object; ssgSelector * _selector; ssgTransform * _position;