diff --git a/src/ATC/AIEntity.hxx b/src/ATC/AIEntity.hxx index 1c8afdc9e..17c62b0c6 100644 --- a/src/ATC/AIEntity.hxx +++ b/src/ATC/AIEntity.hxx @@ -21,11 +21,14 @@ #ifndef _FG_AIEntity_HXX #define _FG_AIEntity_HXX -#include #include #include + #include +#include +#include + /***************************************************************** * diff --git a/src/ATC/AILocalTraffic.cxx b/src/ATC/AILocalTraffic.cxx index e6667699b..7cf30c5f3 100644 --- a/src/ATC/AILocalTraffic.cxx +++ b/src/ATC/AILocalTraffic.cxx @@ -157,8 +157,11 @@ bool FGAILocalTraffic::Init(string ICAO, OperatingState initialState, PatternLeg string planepath = "Aircraft/c172/Models/c172-dpm.ac"; SGPath path = globals->get_fg_root(); path.append(planepath); - aip.init( path.str(), planepath.c_str(), globals->get_props(), - globals->get_sim_time_sec() ); + ssgBranch *model = fgLoad3DModel( path.str(), + planepath.c_str(), + globals->get_props(), + globals->get_sim_time_sec() ); + aip.init( model ); aip.setVisible(false); // This will be set to true once a valid ground elevation has been determined globals->get_scenery()->get_scene_graph()->addKid(aip.getSceneGraph()); diff --git a/src/FDM/LaRCsim.cxx b/src/FDM/LaRCsim.cxx index c4c0eb48f..fe404157e 100644 --- a/src/FDM/LaRCsim.cxx +++ b/src/FDM/LaRCsim.cxx @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/FDM/YASim/YASim.cxx b/src/FDM/YASim/YASim.cxx index f1cbe429e..a57e5e42c 100644 --- a/src/FDM/YASim/YASim.cxx +++ b/src/FDM/YASim/YASim.cxx @@ -6,7 +6,7 @@ #include
#include
#include -#include +#include #include "FGFDM.hpp" #include "Atmosphere.hpp" diff --git a/src/FDM/flight.cxx b/src/FDM/flight.cxx index 59bc6cbc0..f9ba04a61 100644 --- a/src/FDM/flight.cxx +++ b/src/FDM/flight.cxx @@ -35,7 +35,7 @@ #include #include
#include
-#include +#include #include #include "flight.hxx" diff --git a/src/Main/viewer.cxx b/src/Main/viewer.cxx index fd7b13312..16a035f9a 100644 --- a/src/Main/viewer.cxx +++ b/src/Main/viewer.cxx @@ -43,7 +43,7 @@ #include #include
#include -#include +#include #include "viewer.hxx" diff --git a/src/Model/Makefile.am b/src/Model/Makefile.am index 12380e0f2..9397c0159 100644 --- a/src/Model/Makefile.am +++ b/src/Model/Makefile.am @@ -1,10 +1,12 @@ noinst_LIBRARIES = libModel.a libModel_a_SOURCES = \ + acmodel.cxx acmodel.hxx \ loader.cxx loader.hxx \ model.cxx model.hxx \ + model_panel.cxx model_panel.hxx \ modelmgr.cxx modelmgr.hxx \ - acmodel.cxx acmodel.hxx \ - panelnode.cxx panelnode.hxx + panelnode.cxx panelnode.hxx \ + placement.cxx placement.hxx INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src diff --git a/src/Model/acmodel.cxx b/src/Model/acmodel.cxx index a39b76a3f..1155d824f 100644 --- a/src/Model/acmodel.cxx +++ b/src/Model/acmodel.cxx @@ -22,8 +22,10 @@ #include
#include +#include "model_panel.hxx" +#include "placement.hxx" + #include "acmodel.hxx" -#include "model.hxx" @@ -54,17 +56,19 @@ FGAircraftModel::init () _aircraft = new FGModelPlacement; string path = fgGetString("/sim/model/path", "Models/Geometry/glider.ac"); try { - _aircraft->init( globals->get_fg_root(), - path, - globals->get_props(), - globals->get_sim_time_sec() ); + ssgBranch *model = fgLoad3DModelPanel( globals->get_fg_root(), + path, + globals->get_props(), + globals->get_sim_time_sec() ); + _aircraft->init( model ); } catch (const sg_exception &ex) { SG_LOG(SG_GENERAL, SG_ALERT, "Failed to load aircraft from " << path); SG_LOG(SG_GENERAL, SG_ALERT, "(Falling back to glider.ac.)"); - _aircraft->init( globals->get_fg_root(), - "Models/Geometry/glider.ac", - globals->get_props(), - globals->get_sim_time_sec() ); + ssgBranch *model = fgLoad3DModelPanel( globals->get_fg_root(), + "Models/Geometry/glider.ac", + globals->get_props(), + globals->get_sim_time_sec() ); + _aircraft->init( model ); } _scene->addKid(_aircraft->getSceneGraph()); _selector->addKid(_aircraft->getSceneGraph()); diff --git a/src/Model/model.cxx b/src/Model/model.cxx index d2859c26e..cbc8ac89a 100644 --- a/src/Model/model.cxx +++ b/src/Model/model.cxx @@ -7,28 +7,26 @@ # include #endif +#include + #include // for strcmp() +#include + #include #include #include -#include -#include -#include -#include -#include #include #include -#include +#include #include #include -#include - -#include "panelnode.hxx" #include "model.hxx" +SG_USING_STD(vector); + //////////////////////////////////////////////////////////////////////// @@ -84,9 +82,9 @@ splice_branch (ssgBranch * branch, ssgEntity * child) /** * Make an offset matrix from rotations and position offset. */ -static void -make_offsets_matrix (sgMat4 * result, double h_rot, double p_rot, double r_rot, - double x_off, double y_off, double z_off) +void +fgMakeOffsetsMatrix( sgMat4 * result, double h_rot, double p_rot, double r_rot, + double x_off, double y_off, double z_off ) { sgMat4 rot_matrix; sgMat4 pos_matrix; @@ -96,13 +94,13 @@ make_offsets_matrix (sgMat4 * result, double h_rot, double p_rot, double r_rot, } -static void -make_animation (ssgBranch * model, - const char * name, - vector &name_nodes, - SGPropertyNode *prop_root, - SGPropertyNode_ptr node, - double sim_time_sec ) +void +fgMakeAnimation( ssgBranch * model, + const char * name, + vector &name_nodes, + SGPropertyNode *prop_root, + SGPropertyNode_ptr node, + double sim_time_sec ) { Animation * animation = 0; const char * type = node->getStringValue("type", "none"); @@ -165,6 +163,7 @@ make_animation (ssgBranch * model, } + //////////////////////////////////////////////////////////////////////// // Global functions. @@ -214,7 +213,7 @@ fgLoad3DModel( const string &fg_root, const string &path, ssgTransform * alignmainmodel = new ssgTransform; alignmainmodel->addKid(model); sgMat4 res_matrix; - make_offsets_matrix(&res_matrix, + fgMakeOffsetsMatrix(&res_matrix, props.getFloatValue("/offsets/heading-deg", 0.0), props.getFloatValue("/offsets/roll-deg", 0.0), props.getFloatValue("/offsets/pitch-deg", 0.0), @@ -223,16 +222,7 @@ fgLoad3DModel( const string &fg_root, const string &path, props.getFloatValue("/offsets/z-m", 0.0)); alignmainmodel->setTransform(res_matrix); - // Load panels unsigned int i; - 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 animations vector animation_nodes = props.getChildren("animation"); @@ -240,8 +230,8 @@ fgLoad3DModel( const string &fg_root, const string &path, const char * name = animation_nodes[i]->getStringValue("name", 0); vector name_nodes = animation_nodes[i]->getChildren("object-name"); - make_animation( model, name, name_nodes, prop_root, animation_nodes[i], - sim_time_sec); + fgMakeAnimation( model, name, name_nodes, prop_root, animation_nodes[i], + sim_time_sec); } // Load sub-models @@ -250,7 +240,7 @@ fgLoad3DModel( const string &fg_root, const string &path, SGPropertyNode_ptr node = model_nodes[i]; ssgTransform * align = new ssgTransform; sgMat4 res_matrix; - make_offsets_matrix(&res_matrix, + fgMakeOffsetsMatrix(&res_matrix, node->getFloatValue("offsets/heading-deg", 0.0), node->getFloatValue("offsets/roll-deg", 0.0), node->getFloatValue("offsets/pitch-deg", 0.0), @@ -269,124 +259,4 @@ fgLoad3DModel( const string &fg_root, const string &path, } - -//////////////////////////////////////////////////////////////////////// -// Implementation of FGModelPlacement. -//////////////////////////////////////////////////////////////////////// - -FGModelPlacement::FGModelPlacement () - : _lon_deg(0), - _lat_deg(0), - _elev_ft(0), - _roll_deg(0), - _pitch_deg(0), - _heading_deg(0), - _selector(new ssgSelector), - _position(new ssgTransform), - _location(new FGLocation) -{ -} - -FGModelPlacement::~FGModelPlacement () -{ -} - -void -FGModelPlacement::init( const string &fg_root, - const string &path, - SGPropertyNode *prop_root, - double sim_time_sec ) -{ - ssgBranch * model = fgLoad3DModel( fg_root, path, prop_root, sim_time_sec ); - if (model != 0) - _position->addKid(model); - _selector->addKid(_position); - _selector->clrTraversalMaskBits(SSGTRAV_HOT); -} - -void -FGModelPlacement::update( const Point3D scenery_center ) -{ - _location->setPosition( _lon_deg, _lat_deg, _elev_ft ); - _location->setOrientation( _roll_deg, _pitch_deg, _heading_deg ); - - sgCopyMat4( POS, _location->getTransformMatrix(scenery_center) ); - - sgVec3 trans; - sgCopyVec3(trans, _location->get_view_pos()); - - for(int i = 0; i < 4; i++) { - float tmp = POS[i][3]; - for( int j=0; j<3; j++ ) { - POS[i][j] += (tmp * trans[j]); - } - } - _position->setTransform(POS); -} - -bool -FGModelPlacement::getVisible () const -{ - return (_selector->getSelect() != 0); -} - -void -FGModelPlacement::setVisible (bool visible) -{ - _selector->select(visible); -} - -void -FGModelPlacement::setLongitudeDeg (double lon_deg) -{ - _lon_deg = lon_deg; -} - -void -FGModelPlacement::setLatitudeDeg (double lat_deg) -{ - _lat_deg = lat_deg; -} - -void -FGModelPlacement::setElevationFt (double elev_ft) -{ - _elev_ft = elev_ft; -} - -void -FGModelPlacement::setPosition (double lon_deg, double lat_deg, double elev_ft) -{ - _lon_deg = lon_deg; - _lat_deg = lat_deg; - _elev_ft = elev_ft; -} - -void -FGModelPlacement::setRollDeg (double roll_deg) -{ - _roll_deg = roll_deg; -} - -void -FGModelPlacement::setPitchDeg (double pitch_deg) -{ - _pitch_deg = pitch_deg; -} - -void -FGModelPlacement::setHeadingDeg (double heading_deg) -{ - _heading_deg = heading_deg; -} - -void -FGModelPlacement::setOrientation (double roll_deg, double pitch_deg, - double heading_deg) -{ - _roll_deg = roll_deg; - _pitch_deg = pitch_deg; - _heading_deg = heading_deg; -} - // end of model.cxx diff --git a/src/Model/model.hxx b/src/Model/model.hxx index 22d55cf0b..4102460db 100644 --- a/src/Model/model.hxx +++ b/src/Model/model.hxx @@ -17,23 +17,9 @@ SG_USING_STD(vector); #include #include -#include #include -// Don't pull in the headers, since we don't need them here. -class ssgBranch; -class ssgCutout; -class ssgEntity; -class ssgRangeSelector; -class ssgSelector; -class ssgTransform; - -class SGInterpTable; -class FGCondition; -class FGLocation; - - // Has anyone done anything *really* stupid, like making min and max macros? #ifdef min #undef min @@ -44,7 +30,10 @@ class FGLocation; /** - * Load a 3D model with or without XML wrapper. + * Load a 3D model with or without XML wrapper. Note, this version + * Does not know about or load the panel/cockpit information. Use the + * "model_panel.hxx" version if you want to load an aircraft + * (i.e. ownship) with a panel. * * If the path ends in ".xml", then it will be used as a property- * list wrapper to add animations to the model. @@ -56,80 +45,23 @@ ssgBranch * fgLoad3DModel( const string& fg_root, const string &path, SGPropertyNode *prop_root, double sim_time_sec ); -//////////////////////////////////////////////////////////////////////// -// Model placement. -//////////////////////////////////////////////////////////////////////// +/** + * Make an offset matrix from rotations and position offset. + */ +void +fgMakeOffsetsMatrix( sgMat4 * result, double h_rot, double p_rot, double r_rot, + double x_off, double y_off, double z_off ); /** - * A wrapper for a model with a definite placement. + * Make the animation */ -class FGModelPlacement -{ -public: +void +fgMakeAnimation( ssgBranch * model, + const char * name, + vector &name_nodes, + SGPropertyNode *prop_root, + SGPropertyNode_ptr node, + double sim_time_sec ); - FGModelPlacement (); - virtual ~FGModelPlacement (); - - virtual void init( const string &fg_root, - const string &path, - SGPropertyNode *prop_root, - double sim_time_sec ); - virtual void update( const Point3D scenery_center ); - - virtual ssgEntity * getSceneGraph () { return (ssgEntity *)_selector; } - - virtual FGLocation * getFGLocation () { return _location; } - - virtual bool getVisible () const; - virtual void setVisible (bool visible); - - virtual double getLongitudeDeg () const { return _lon_deg; } - 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 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); - - // Addition by Diarmuid Tyson for Multiplayer Support - // Allows multiplayer to get players position transform - virtual const sgVec4 *get_POS() { return POS; } - -private: - - // Geodetic position - double _lon_deg; - double _lat_deg; - double _elev_ft; - - // Orientation - double _roll_deg; - double _pitch_deg; - double _heading_deg; - - ssgSelector * _selector; - ssgTransform * _position; - - // Location - FGLocation * _location; - - - // Addition by Diarmuid Tyson for Multiplayer Support - // Moved from update method - // POS for transformation Matrix - sgMat4 POS; - -}; #endif // __MODEL_HXX diff --git a/src/Model/model_panel.cxx b/src/Model/model_panel.cxx new file mode 100644 index 000000000..3e09b6fff --- /dev/null +++ b/src/Model/model_panel.cxx @@ -0,0 +1,143 @@ +// model.cxx - manage a 3D aircraft model. +// Written by David Megginson, started 2002. +// +// This file is in the Public Domain, and comes with no warranty. + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include // for strcmp() + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "panelnode.hxx" + +#include "model.hxx" +#include "model_panel.hxx" + +SG_USING_STD(vector); + + + +//////////////////////////////////////////////////////////////////////// +// 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 xmlpath; + SGPath modelpath = path; + if ( ulIsAbsolutePathName( path.c_str() ) ) { + xmlpath = modelpath; + } + else { + xmlpath = fg_root; + xmlpath.append(modelpath.str()); + } + + // Check for an XML wrapper + if (xmlpath.str().substr(xmlpath.str().size() - 4, 4) == ".xml") { + readProperties(xmlpath.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 *)xmlpath.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; + fgMakeOffsetsMatrix(&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 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"); + fgMakeAnimation( model, name, name_nodes, prop_root, animation_nodes[i], + sim_time_sec); + } + + // 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; + fgMakeOffsetsMatrix(&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 = fgLoad3DModel( fg_root, node->getStringValue("path"), + prop_root, sim_time_sec ); + align->addKid(kid); + model->addKid(align); + } + + return alignmainmodel; +} + + +// end of model_panel.cxx diff --git a/src/Model/model_panel.hxx b/src/Model/model_panel.hxx new file mode 100644 index 000000000..98b5ffe71 --- /dev/null +++ b/src/Model/model_panel.hxx @@ -0,0 +1,63 @@ +// model.hxx - manage a 3D aircraft model. +// Written by David Megginson, started 2002. +// +// This file is in the Public Domain, and comes with no warranty. + +#ifndef __MODEL_HXX +#define __MODEL_HXX 1 + +#ifndef __cplusplus +# error This library requires C++ +#endif + +#include + +SG_USING_STD(vector); + +#include +#include + +#include +#include + + +// Don't pull in the headers, since we don't need them here. +class ssgBranch; +class ssgCutout; +class ssgEntity; +class ssgRangeSelector; +class ssgSelector; +class ssgTransform; + +class SGInterpTable; +class FGCondition; +class FGLocation; + + +// Has anyone done anything *really* stupid, like making min and max macros? +#ifdef min +#undef min +#endif +#ifdef max +#undef max +#endif + + +/** + * Load a 3D model with or without XML wrapper. This version supports + * also loading the instrument panel and is wired in with dependencies + * on panelnode.hxx, and thus files in src/Cockpit and also GUI/mouse + * input code to support the 3d clickable hotspots. + * + * If the path ends in ".xml", then it will be used as a property- + * list wrapper to add animations to the model. + * + * Subsystems should not normally invoke this function directly; + * instead, they should use the FGModelLoader declared in loader.hxx. + */ +ssgBranch *fgLoad3DModelPanel( const string& fg_root, const string &path, + SGPropertyNode *prop_root, + double sim_time_sec ); + + +#endif // __MODEL_HXX diff --git a/src/Model/modelmgr.cxx b/src/Model/modelmgr.cxx index 609f7abdf..72d257368 100644 --- a/src/Model/modelmgr.cxx +++ b/src/Model/modelmgr.cxx @@ -8,8 +8,10 @@ #include
#include -#include "modelmgr.hxx" #include "model.hxx" +#include "placement.hxx" + +#include "modelmgr.hxx" FGModelMgr::FGModelMgr () @@ -36,12 +38,15 @@ FGModelMgr::init () SG_LOG(SG_GENERAL, SG_INFO, "Adding model " << node->getStringValue("name", "[unnamed]")); Instance * instance = new Instance; - FGModelPlacement * model = new FGModelPlacement; + FGModelPlacement *model = new FGModelPlacement; instance->model = model; - model->init( globals->get_fg_root(), - node->getStringValue("path", "Models/Geometry/glider.ac"), - globals->get_props(), - globals->get_sim_time_sec() ); + ssgBranch *object + = fgLoad3DModel( globals->get_fg_root(), + node->getStringValue("path", + "Models/Geometry/glider.ac"), + globals->get_props(), + globals->get_sim_time_sec() ); + model->init( object ); // Set position and orientation either // indirectly through property refs diff --git a/src/Model/placement.cxx b/src/Model/placement.cxx new file mode 100644 index 000000000..d8bf21e2f --- /dev/null +++ b/src/Model/placement.cxx @@ -0,0 +1,157 @@ +// placement.cxx - manage the placment of a 3D model. +// Written by David Megginson, started 2002. +// +// This file is in the Public Domain, and comes with no warranty. + +#include + +#include // for strcmp() + +#include + +#include +#include +#include + +#include + +#include "model.hxx" + +#include "placement.hxx" + +SG_USING_STD(vector); + + + +//////////////////////////////////////////////////////////////////////// +// Implementation of FGModelPlacement. +//////////////////////////////////////////////////////////////////////// + +FGModelPlacement::FGModelPlacement () + : _lon_deg(0), + _lat_deg(0), + _elev_ft(0), + _roll_deg(0), + _pitch_deg(0), + _heading_deg(0), + _selector(new ssgSelector), + _position(new ssgTransform), + _location(new FGLocation) +{ +} + +FGModelPlacement::~FGModelPlacement () +{ +} + +#if 0 +void +FGModelPlacement::init( const string &fg_root, + const string &path, + SGPropertyNode *prop_root, + double sim_time_sec, int dummy ) +{ + ssgBranch * model = fgLoad3DModel( fg_root, path, prop_root, sim_time_sec ); + if (model != 0) + _position->addKid(model); + _selector->addKid(_position); + _selector->clrTraversalMaskBits(SSGTRAV_HOT); +} +#endif + +void +FGModelPlacement::init( ssgBranch * model ) +{ + if (model != 0) { + _position->addKid(model); + } + _selector->addKid(_position); + _selector->clrTraversalMaskBits(SSGTRAV_HOT); +} + +void +FGModelPlacement::update( const Point3D scenery_center ) +{ + _location->setPosition( _lon_deg, _lat_deg, _elev_ft ); + _location->setOrientation( _roll_deg, _pitch_deg, _heading_deg ); + + sgCopyMat4( POS, _location->getTransformMatrix(scenery_center) ); + + sgVec3 trans; + sgCopyVec3(trans, _location->get_view_pos()); + + for(int i = 0; i < 4; i++) { + float tmp = POS[i][3]; + for( int j=0; j<3; j++ ) { + POS[i][j] += (tmp * trans[j]); + } + } + _position->setTransform(POS); +} + +bool +FGModelPlacement::getVisible () const +{ + return (_selector->getSelect() != 0); +} + +void +FGModelPlacement::setVisible (bool visible) +{ + _selector->select(visible); +} + +void +FGModelPlacement::setLongitudeDeg (double lon_deg) +{ + _lon_deg = lon_deg; +} + +void +FGModelPlacement::setLatitudeDeg (double lat_deg) +{ + _lat_deg = lat_deg; +} + +void +FGModelPlacement::setElevationFt (double elev_ft) +{ + _elev_ft = elev_ft; +} + +void +FGModelPlacement::setPosition (double lon_deg, double lat_deg, double elev_ft) +{ + _lon_deg = lon_deg; + _lat_deg = lat_deg; + _elev_ft = elev_ft; +} + +void +FGModelPlacement::setRollDeg (double roll_deg) +{ + _roll_deg = roll_deg; +} + +void +FGModelPlacement::setPitchDeg (double pitch_deg) +{ + _pitch_deg = pitch_deg; +} + +void +FGModelPlacement::setHeadingDeg (double heading_deg) +{ + _heading_deg = heading_deg; +} + +void +FGModelPlacement::setOrientation (double roll_deg, double pitch_deg, + double heading_deg) +{ + _roll_deg = roll_deg; + _pitch_deg = pitch_deg; + _heading_deg = heading_deg; +} + +// end of model.cxx diff --git a/src/Model/placement.hxx b/src/Model/placement.hxx new file mode 100644 index 000000000..453353b89 --- /dev/null +++ b/src/Model/placement.hxx @@ -0,0 +1,115 @@ +// placement.hxx - manage the placment of a 3D model. +// Written by David Megginson, started 2002. +// +// This file is in the Public Domain, and comes with no warranty. + + +#ifndef _SG_PLACEMENT_HXX +#define _SG_PLACEMENT_HXX 1 + +#ifndef __cplusplus +# error This library requires C++ +#endif + +#include + +SG_USING_STD(vector); + +#include +#include + +#include +#include + + +// Don't pull in the headers, since we don't need them here. +class FGLocation; + + +// Has anyone done anything *really* stupid, like making min and max macros? +#ifdef min +#undef min +#endif +#ifdef max +#undef max +#endif + + +//////////////////////////////////////////////////////////////////////// +// Model placement. +//////////////////////////////////////////////////////////////////////// + +/** + * A wrapper for a model with a definite placement. + */ +class FGModelPlacement +{ +public: + + FGModelPlacement (); + virtual ~FGModelPlacement (); + + virtual void FGModelPlacement::init( ssgBranch * model ); + /* virtual void init( const string &fg_root, + const string &path, + SGPropertyNode *prop_root, + double sim_time_sec, int dummy ); */ + virtual void update( const Point3D scenery_center ); + + virtual ssgEntity * getSceneGraph () { return (ssgEntity *)_selector; } + + virtual FGLocation * getFGLocation () { return _location; } + + virtual bool getVisible () const; + virtual void setVisible (bool visible); + + virtual double getLongitudeDeg () const { return _lon_deg; } + 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 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); + + // Addition by Diarmuid Tyson for Multiplayer Support + // Allows multiplayer to get players position transform + virtual const sgVec4 *get_POS() { return POS; } + +private: + + // Geodetic position + double _lon_deg; + double _lat_deg; + double _elev_ft; + + // Orientation + double _roll_deg; + double _pitch_deg; + double _heading_deg; + + ssgSelector * _selector; + ssgTransform * _position; + + // Location + FGLocation * _location; + + + // Addition by Diarmuid Tyson for Multiplayer Support + // Moved from update method + // POS for transformation Matrix + sgMat4 POS; + +}; + +#endif // _SG_PLACEMENT_HXX diff --git a/src/Network/multiplay.cxx b/src/Network/multiplay.cxx index dfb6b6a15..ff88c98c2 100644 --- a/src/Network/multiplay.cxx +++ b/src/Network/multiplay.cxx @@ -29,6 +29,8 @@ #include +#include + #include "multiplay.hxx" SG_USING_STD(string);