From: david Date: Fri, 12 Apr 2002 12:45:49 +0000 (+0000) Subject: Added support for additional animated, dynamic 3D models configured in X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8bed5a8cf465190897b6ab7d6f8dcad34e655ce5;p=flightgear.git Added support for additional animated, dynamic 3D models configured in XML. --- diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index 7a4899fe2..9d5b0518b 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -65,6 +65,7 @@ class FGATCMgr; class FGATCDisplay; class FGAIMgr; class FGAircraftModel; +class FGModelMgr; /** @@ -152,6 +153,8 @@ private: FGAircraftModel *acmodel; + FGModelMgr * model_mgr; + // list of serial port-like configurations string_list *channel_options_list; @@ -251,6 +254,13 @@ public: acmodel = model; } + inline FGModelMgr *get_model_mgr () { return model_mgr; } + + inline void set_model_mgr (FGModelMgr * mgr) + { + model_mgr = mgr; + } + inline string_list *get_channel_options_list () { return channel_options_list; } diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 2ba337327..9ce9970a5 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -97,6 +97,7 @@ SG_USING_STD(endl); #include #include #include +#include #ifdef FG_NETWORK_OLK #include #endif @@ -383,6 +384,7 @@ void trRenderFrame( void ) { thesky->postDraw( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER ); + globals->get_model_mgr()->draw(); globals->get_aircraft_model()->draw(); // need to do this here as hud_and_panel state is static to @@ -719,6 +721,7 @@ void fgRenderFrame( void ) { thesky->postDraw( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER ); } + globals->get_model_mgr()->draw(); globals->get_aircraft_model()->draw(); // display HUD && Panel @@ -846,6 +849,7 @@ void fgUpdateTimeDepCalcs() { } + globals->get_model_mgr()->update(multi_loop); globals->get_aircraft_model()->update(multi_loop); // update the view angle @@ -1479,6 +1483,14 @@ int mainLoop( int argc, char **argv ) { SGPath modelpath( globals->get_fg_root() ); ssgModelPath( (char *)modelpath.c_str() ); + //////////////////////////////////////////////////////////////////// + // Initialize the general model subsystem. + //////////////////////////////////////////////////////////////////// + + globals->set_model_mgr(new FGModelMgr); + globals->get_model_mgr()->init(); + globals->get_model_mgr()->bind(); + //////////////////////////////////////////////////////////////////// // Initialize the 3D aircraft model subsystem. //////////////////////////////////////////////////////////////////// diff --git a/src/Model/Makefile.am b/src/Model/Makefile.am index ddb86d876..7cc804d04 100644 --- a/src/Model/Makefile.am +++ b/src/Model/Makefile.am @@ -1,6 +1,7 @@ noinst_LIBRARIES = libModel.a libModel_a_SOURCES = model.cxx model.hxx \ + modelmgr.cxx modelmgr.hxx \ acmodel.cxx acmodel.hxx if OLD_AUTOMAKE diff --git a/src/Model/model.cxx b/src/Model/model.cxx index 9c1369b20..1119de043 100644 --- a/src/Model/model.cxx +++ b/src/Model/model.cxx @@ -257,6 +257,24 @@ FG3DModel::setVisible (bool visible) _selector->select(visible); } +void +FG3DModel::setLongitudeDeg (double lon_deg) +{ + _lon_deg = lon_deg; +} + +void +FG3DModel::setLatitudeDeg (double lat_deg) +{ + _lat_deg = lat_deg; +} + +void +FG3DModel::setElevationFt (double elev_ft) +{ + _elev_ft = elev_ft; +} + void FG3DModel::setPosition (double lon_deg, double lat_deg, double elev_ft) { @@ -265,6 +283,24 @@ FG3DModel::setPosition (double lon_deg, double lat_deg, double elev_ft) _elev_ft = elev_ft; } +void +FG3DModel::setRollDeg (double roll_deg) +{ + _roll_deg = roll_deg; +} + +void +FG3DModel::setPitchDeg (double pitch_deg) +{ + _pitch_deg = pitch_deg; +} + +void +FG3DModel::setHeadingDeg (double heading_deg) +{ + _heading_deg = heading_deg; +} + void FG3DModel::setOrientation (double roll_deg, double pitch_deg, double heading_deg) diff --git a/src/Model/model.hxx b/src/Model/model.hxx index 78417d08f..fa85b592f 100644 --- a/src/Model/model.hxx +++ b/src/Model/model.hxx @@ -43,12 +43,18 @@ public: virtual double getLatitudeDeg () const { return _lat_deg; } virtual double getElevationFt () const { return _elev_ft; } + virtual void setLongitudeDeg (double lon_deg); + virtual void setLatitudeDeg (double lat_deg); + virtual void setElevationFt (double elev_ft); virtual void setPosition (double lon_deg, double lat_deg, double elev_ft); - virtual double getRoll () const { return _roll_deg; } - virtual double getPitch () const { return _pitch_deg; } - virtual double getHeading () const { return _heading_deg; } + virtual double getRollDeg () const { return _roll_deg; } + virtual double getPitchDeg () const { return _pitch_deg; } + virtual double getHeadingDeg () const { return _heading_deg; } + virtual void setRollDeg (double roll_deg); + virtual void setPitchDeg (double pitch_deg); + virtual void setHeadingDeg (double heading_deg); virtual void setOrientation (double roll_deg, double pitch_deg, double heading_deg); diff --git a/src/Model/modelmgr.cxx b/src/Model/modelmgr.cxx new file mode 100644 index 000000000..e25884c30 --- /dev/null +++ b/src/Model/modelmgr.cxx @@ -0,0 +1,154 @@ +// modelmgr.cxx - manage a collection of 3D models. +// Written by David Megginson, started 2002. +// +// This file is in the Public Domain, and comes with no warranty. + +#include "modelmgr.hxx" + +#include
+ + +FGModelMgr::FGModelMgr () + : _scene(new ssgRoot), + _nearplane(0.5f), + _farplane(120000.0f) +{ +} + +FGModelMgr::~FGModelMgr () +{ + for (int i = 0; i < _instances.size(); i++) { + delete _instances[i]; + } + delete _scene; +} + +void +FGModelMgr::init () +{ + vector model_nodes = + fgGetNode("/models", true)->getChildren("model"); + for (int i = 0; i < model_nodes.size(); i++) { + SGPropertyNode * node = model_nodes[i]; + SG_LOG(SG_GENERAL, SG_INFO, + "Adding model " << node->getStringValue("name", "[unnamed]")); + Instance * instance = new Instance; + FG3DModel * model = new FG3DModel; + instance->model = model; + model->init(node->getStringValue("path", "Models/Geometry/glider.ac")); + + // Set position and orientation either + // indirectly through property refs + // or directly with static values. + SGPropertyNode * child = node->getChild("longitude-deg-prop"); + if (child != 0) + instance->lon_deg_node = child; + else + model->setLongitudeDeg(node->getDoubleValue("longitude-deg")); + + child = node->getChild("latitude-deg-prop"); + if (child != 0) + instance->lat_deg_node = fgGetNode(child->getStringValue(), true); + else + model->setLatitudeDeg(node->getDoubleValue("latitude-deg")); + + child = node->getChild("elevation-ft-prop"); + if (child != 0) + instance->elev_ft_node = fgGetNode(child->getStringValue(), true); + else + model->setElevationFt(node->getDoubleValue("elevation-ft")); + + child = node->getChild("roll-deg-prop"); + if (child != 0) + instance->roll_deg_node = fgGetNode(child->getStringValue(), true); + else + model->setRollDeg(node->getDoubleValue("roll-deg")); + + child = node->getChild("pitch-deg-prop"); + if (child != 0) + instance->pitch_deg_node = fgGetNode(child->getStringValue(), true); + else + model->setPitchDeg(node->getDoubleValue("pitch-deg")); + + child = node->getChild("heading-deg-prop"); + if (child != 0) + instance->heading_deg_node = fgGetNode(child->getStringValue(), true); + else + model->setHeadingDeg(node->getDoubleValue("heading-deg")); + + // Add this model to the scene graph + _scene->addKid(model->getSceneGraph()); + + // Save this instance for updating + _instances.push_back(instance); + } +} + +void +FGModelMgr::bind () +{ +} + +void +FGModelMgr::unbind () +{ +} + +void +FGModelMgr::update (int dt) +{ + for (int i = 0; i < _instances.size(); i++) { + Instance * instance = _instances[i]; + FG3DModel * model = instance->model; + + instance->model->update(dt); + + // Optionally set position from properties + if (instance->lon_deg_node != 0) + model->setLongitudeDeg(instance->lon_deg_node->getDoubleValue()); + if (instance->lat_deg_node != 0) + model->setLatitudeDeg(instance->lat_deg_node->getDoubleValue()); + if (instance->elev_ft_node != 0) + model->setElevationFt(instance->elev_ft_node->getDoubleValue()); + + // Optionally set orientation from properties + if (instance->roll_deg_node != 0) + model->setRollDeg(instance->roll_deg_node->getDoubleValue()); + if (instance->pitch_deg_node != 0) + model->setPitchDeg(instance->pitch_deg_node->getDoubleValue()); + if (instance->heading_deg_node != 0) + model->setHeadingDeg(instance->heading_deg_node->getDoubleValue()); + + } +} + +void +FGModelMgr::draw () +{ + ssgSetNearFar(_nearplane, _farplane); + ssgCullAndDraw(_scene); +} + + + +//////////////////////////////////////////////////////////////////////// +// Implementation of FGModelMgr::Instance +//////////////////////////////////////////////////////////////////////// + +FGModelMgr::Instance::Instance () + : model(0), + lon_deg_node(0), + lat_deg_node(0), + elev_ft_node(0), + roll_deg_node(0), + pitch_deg_node(0), + heading_deg_node(0) +{ +} + +FGModelMgr::Instance::~Instance () +{ + delete model; +} + +// end of modelmgr.cxx diff --git a/src/Model/modelmgr.hxx b/src/Model/modelmgr.hxx new file mode 100644 index 000000000..1ea8aef6d --- /dev/null +++ b/src/Model/modelmgr.hxx @@ -0,0 +1,69 @@ +// model-mgr.hxx - manage user-specified 3D models. +// Written by David Megginson, started 2002. +// +// This file is in the Public Domain, and comes with no warranty. + +#ifndef __MODELMGR_HXX +#define __MODELMGR_HXX 1 + +#ifndef __cplusplus +# error This library requires C++ +#endif + +#include + +#include + +#include +#include + +#include
+ +#include "model.hxx" + +SG_USING_STD(vector); + + +/** + * Manage a list of user-specified models. + */ +class FGModelMgr : public FGSubsystem +{ +public: + FGModelMgr (); + virtual ~FGModelMgr (); + + virtual void init (); + virtual void bind (); + virtual void unbind (); + virtual void update (int dt); + + virtual void draw (); + +private: + + struct Instance + { + Instance (); + virtual ~Instance (); + FG3DModel * model; + SGPropertyNode * lon_deg_node; + SGPropertyNode * lat_deg_node; + SGPropertyNode * elev_ft_node; + SGPropertyNode * roll_deg_node; + SGPropertyNode * pitch_deg_node; + SGPropertyNode * heading_deg_node; + }; + + vector _instances; + + ssgRoot * _scene; + float _nearplane; + float _farplane; + +}; + +#endif // __MODELMGR_HXX + + +