1
0
Fork 0

Working at unraveling and breaking dependencies inside of src/Model.

I split the FGModelPlacement code out into it's own set of source files.
I created two versions of the fgLoad3DModel() routine.  One that is
  unecumbered by a panelnode dependency and one that is.  acmodel.cxx is
  the only place that needs to load an aircraft with instrument panels.
model.[ch]xx are now pretty much free to move over into simgear.
loader.[ch]xx should be able to follow closely behind.
This will be a big step towards being able to move the material management
code over into simgear.
This commit is contained in:
curt 2003-05-08 20:28:46 +00:00
parent fe7a61d3ff
commit 575b3ac98c
16 changed files with 561 additions and 262 deletions

View file

@ -21,11 +21,14 @@
#ifndef _FG_AIEntity_HXX #ifndef _FG_AIEntity_HXX
#define _FG_AIEntity_HXX #define _FG_AIEntity_HXX
#include <Model/model.hxx>
#include <plib/sg.h> #include <plib/sg.h>
#include <plib/ssg.h> #include <plib/ssg.h>
#include <simgear/math/point3d.hxx> #include <simgear/math/point3d.hxx>
#include <Model/model.hxx>
#include <Model/placement.hxx>
/***************************************************************** /*****************************************************************
* *

View file

@ -157,8 +157,11 @@ bool FGAILocalTraffic::Init(string ICAO, OperatingState initialState, PatternLeg
string planepath = "Aircraft/c172/Models/c172-dpm.ac"; string planepath = "Aircraft/c172/Models/c172-dpm.ac";
SGPath path = globals->get_fg_root(); SGPath path = globals->get_fg_root();
path.append(planepath); path.append(planepath);
aip.init( path.str(), planepath.c_str(), globals->get_props(), ssgBranch *model = fgLoad3DModel( path.str(),
globals->get_sim_time_sec() ); 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 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()); globals->get_scenery()->get_scene_graph()->addKid(aip.getSceneGraph());

View file

@ -28,7 +28,7 @@
#include <Aircraft/aircraft.hxx> #include <Aircraft/aircraft.hxx>
#include <Controls/controls.hxx> #include <Controls/controls.hxx>
#include <Model/model.hxx> #include <Model/placement.hxx>
#include <FDM/flight.hxx> #include <FDM/flight.hxx>
#include <FDM/LaRCsim/ls_cockpit.h> #include <FDM/LaRCsim/ls_cockpit.h>
#include <FDM/LaRCsim/ls_generic.h> #include <FDM/LaRCsim/ls_generic.h>

View file

@ -6,7 +6,7 @@
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
#include <Model/acmodel.hxx> #include <Model/acmodel.hxx>
#include <Model/model.hxx> #include <Model/placement.hxx>
#include "FGFDM.hpp" #include "FGFDM.hpp"
#include "Atmosphere.hpp" #include "Atmosphere.hpp"

View file

@ -35,7 +35,7 @@
#include <FDM/LaRCsim/ls_interface.h> #include <FDM/LaRCsim/ls_interface.h>
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
#include <Model/model.hxx> #include <Model/placement.hxx>
#include <Model/acmodel.hxx> #include <Model/acmodel.hxx>
#include "flight.hxx" #include "flight.hxx"

View file

@ -43,7 +43,7 @@
#include <simgear/math/vector.hxx> #include <simgear/math/vector.hxx>
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <Model/acmodel.hxx> #include <Model/acmodel.hxx>
#include <Model/model.hxx> #include <Model/placement.hxx>
#include "viewer.hxx" #include "viewer.hxx"

View file

@ -1,10 +1,12 @@
noinst_LIBRARIES = libModel.a noinst_LIBRARIES = libModel.a
libModel_a_SOURCES = \ libModel_a_SOURCES = \
acmodel.cxx acmodel.hxx \
loader.cxx loader.hxx \ loader.cxx loader.hxx \
model.cxx model.hxx \ model.cxx model.hxx \
model_panel.cxx model_panel.hxx \
modelmgr.cxx modelmgr.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 INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src

View file

@ -22,8 +22,10 @@
#include <Main/viewmgr.hxx> #include <Main/viewmgr.hxx>
#include <Scenery/scenery.hxx> #include <Scenery/scenery.hxx>
#include "model_panel.hxx"
#include "placement.hxx"
#include "acmodel.hxx" #include "acmodel.hxx"
#include "model.hxx"
@ -54,17 +56,19 @@ FGAircraftModel::init ()
_aircraft = new FGModelPlacement; _aircraft = new FGModelPlacement;
string path = fgGetString("/sim/model/path", "Models/Geometry/glider.ac"); string path = fgGetString("/sim/model/path", "Models/Geometry/glider.ac");
try { try {
_aircraft->init( globals->get_fg_root(), ssgBranch *model = fgLoad3DModelPanel( globals->get_fg_root(),
path, path,
globals->get_props(), globals->get_props(),
globals->get_sim_time_sec() ); globals->get_sim_time_sec() );
_aircraft->init( model );
} catch (const sg_exception &ex) { } catch (const sg_exception &ex) {
SG_LOG(SG_GENERAL, SG_ALERT, "Failed to load aircraft from " << path); SG_LOG(SG_GENERAL, SG_ALERT, "Failed to load aircraft from " << path);
SG_LOG(SG_GENERAL, SG_ALERT, "(Falling back to glider.ac.)"); SG_LOG(SG_GENERAL, SG_ALERT, "(Falling back to glider.ac.)");
_aircraft->init( globals->get_fg_root(), ssgBranch *model = fgLoad3DModelPanel( globals->get_fg_root(),
"Models/Geometry/glider.ac", "Models/Geometry/glider.ac",
globals->get_props(), globals->get_props(),
globals->get_sim_time_sec() ); globals->get_sim_time_sec() );
_aircraft->init( model );
} }
_scene->addKid(_aircraft->getSceneGraph()); _scene->addKid(_aircraft->getSceneGraph());
_selector->addKid(_aircraft->getSceneGraph()); _selector->addKid(_aircraft->getSceneGraph());

View file

@ -7,28 +7,26 @@
# include <config.h> # include <config.h>
#endif #endif
#include <simgear/compiler.h>
#include <string.h> // for strcmp() #include <string.h> // for strcmp()
#include <vector>
#include <plib/sg.h> #include <plib/sg.h>
#include <plib/ssg.h> #include <plib/ssg.h>
#include <plib/ul.h> #include <plib/ul.h>
#include <simgear/compiler.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/math/interpolater.hxx>
#include <simgear/math/point3d.hxx>
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/misc/exception.hxx> #include <simgear/misc/exception.hxx>
#include <simgear/misc/sg_path.hxx> #include <simgear/misc/sg_path.hxx>
#include <simgear/props/condition.hxx> #include <simgear/props/props.hxx>
#include <simgear/props/props_io.hxx> #include <simgear/props/props_io.hxx>
#include <simgear/scene/model/animation.hxx> #include <simgear/scene/model/animation.hxx>
#include <simgear/scene/model/location.hxx>
#include "panelnode.hxx"
#include "model.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. * Make an offset matrix from rotations and position offset.
*/ */
static void void
make_offsets_matrix (sgMat4 * result, double h_rot, double p_rot, double r_rot, fgMakeOffsetsMatrix( sgMat4 * result, double h_rot, double p_rot, double r_rot,
double x_off, double y_off, double z_off) double x_off, double y_off, double z_off )
{ {
sgMat4 rot_matrix; sgMat4 rot_matrix;
sgMat4 pos_matrix; sgMat4 pos_matrix;
@ -96,13 +94,13 @@ make_offsets_matrix (sgMat4 * result, double h_rot, double p_rot, double r_rot,
} }
static void void
make_animation (ssgBranch * model, fgMakeAnimation( ssgBranch * model,
const char * name, const char * name,
vector<SGPropertyNode_ptr> &name_nodes, vector<SGPropertyNode_ptr> &name_nodes,
SGPropertyNode *prop_root, SGPropertyNode *prop_root,
SGPropertyNode_ptr node, SGPropertyNode_ptr node,
double sim_time_sec ) double sim_time_sec )
{ {
Animation * animation = 0; Animation * animation = 0;
const char * type = node->getStringValue("type", "none"); const char * type = node->getStringValue("type", "none");
@ -165,6 +163,7 @@ make_animation (ssgBranch * model,
} }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Global functions. // Global functions.
@ -214,7 +213,7 @@ fgLoad3DModel( const string &fg_root, const string &path,
ssgTransform * alignmainmodel = new ssgTransform; ssgTransform * alignmainmodel = new ssgTransform;
alignmainmodel->addKid(model); alignmainmodel->addKid(model);
sgMat4 res_matrix; sgMat4 res_matrix;
make_offsets_matrix(&res_matrix, fgMakeOffsetsMatrix(&res_matrix,
props.getFloatValue("/offsets/heading-deg", 0.0), props.getFloatValue("/offsets/heading-deg", 0.0),
props.getFloatValue("/offsets/roll-deg", 0.0), props.getFloatValue("/offsets/roll-deg", 0.0),
props.getFloatValue("/offsets/pitch-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)); props.getFloatValue("/offsets/z-m", 0.0));
alignmainmodel->setTransform(res_matrix); alignmainmodel->setTransform(res_matrix);
// Load panels
unsigned int i; unsigned int i;
vector<SGPropertyNode_ptr> 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 // Load animations
vector<SGPropertyNode_ptr> animation_nodes = props.getChildren("animation"); vector<SGPropertyNode_ptr> 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); const char * name = animation_nodes[i]->getStringValue("name", 0);
vector<SGPropertyNode_ptr> name_nodes = vector<SGPropertyNode_ptr> name_nodes =
animation_nodes[i]->getChildren("object-name"); animation_nodes[i]->getChildren("object-name");
make_animation( model, name, name_nodes, prop_root, animation_nodes[i], fgMakeAnimation( model, name, name_nodes, prop_root, animation_nodes[i],
sim_time_sec); sim_time_sec);
} }
// Load sub-models // Load sub-models
@ -250,7 +240,7 @@ fgLoad3DModel( const string &fg_root, const string &path,
SGPropertyNode_ptr node = model_nodes[i]; SGPropertyNode_ptr node = model_nodes[i];
ssgTransform * align = new ssgTransform; ssgTransform * align = new ssgTransform;
sgMat4 res_matrix; sgMat4 res_matrix;
make_offsets_matrix(&res_matrix, fgMakeOffsetsMatrix(&res_matrix,
node->getFloatValue("offsets/heading-deg", 0.0), node->getFloatValue("offsets/heading-deg", 0.0),
node->getFloatValue("offsets/roll-deg", 0.0), node->getFloatValue("offsets/roll-deg", 0.0),
node->getFloatValue("offsets/pitch-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 // end of model.cxx

View file

@ -17,23 +17,9 @@ SG_USING_STD(vector);
#include <plib/sg.h> #include <plib/sg.h>
#include <plib/ssg.h> #include <plib/ssg.h>
#include <simgear/math/point3d.hxx>
#include <simgear/props/props.hxx> #include <simgear/props/props.hxx>
// 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? // Has anyone done anything *really* stupid, like making min and max macros?
#ifdef min #ifdef min
#undef 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- * If the path ends in ".xml", then it will be used as a property-
* list wrapper to add animations to the model. * 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 ); 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 void
{ fgMakeAnimation( ssgBranch * model,
public: const char * name,
vector<SGPropertyNode_ptr> &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 #endif // __MODEL_HXX

143
src/Model/model_panel.cxx Normal file
View file

@ -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 <config.h>
#endif
#include <simgear/compiler.h>
#include <string.h> // for strcmp()
#include <vector>
#include <plib/sg.h>
#include <plib/ssg.h>
#include <plib/ul.h>
#include <simgear/misc/exception.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/props/props.hxx>
#include <simgear/props/props_io.hxx>
#include <simgear/scene/model/animation.hxx>
#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<SGPropertyNode_ptr> 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<SGPropertyNode_ptr> animation_nodes = props.getChildren("animation");
for (i = 0; i < animation_nodes.size(); i++) {
const char * name = animation_nodes[i]->getStringValue("name", 0);
vector<SGPropertyNode_ptr> 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<SGPropertyNode_ptr> 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

63
src/Model/model_panel.hxx Normal file
View file

@ -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 <vector>
SG_USING_STD(vector);
#include <plib/sg.h>
#include <plib/ssg.h>
#include <simgear/math/point3d.hxx>
#include <simgear/props/props.hxx>
// 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

View file

@ -8,8 +8,10 @@
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
#include <Scenery/scenery.hxx> #include <Scenery/scenery.hxx>
#include "modelmgr.hxx"
#include "model.hxx" #include "model.hxx"
#include "placement.hxx"
#include "modelmgr.hxx"
FGModelMgr::FGModelMgr () FGModelMgr::FGModelMgr ()
@ -36,12 +38,15 @@ FGModelMgr::init ()
SG_LOG(SG_GENERAL, SG_INFO, SG_LOG(SG_GENERAL, SG_INFO,
"Adding model " << node->getStringValue("name", "[unnamed]")); "Adding model " << node->getStringValue("name", "[unnamed]"));
Instance * instance = new Instance; Instance * instance = new Instance;
FGModelPlacement * model = new FGModelPlacement; FGModelPlacement *model = new FGModelPlacement;
instance->model = model; instance->model = model;
model->init( globals->get_fg_root(), ssgBranch *object
node->getStringValue("path", "Models/Geometry/glider.ac"), = fgLoad3DModel( globals->get_fg_root(),
globals->get_props(), node->getStringValue("path",
globals->get_sim_time_sec() ); "Models/Geometry/glider.ac"),
globals->get_props(),
globals->get_sim_time_sec() );
model->init( object );
// Set position and orientation either // Set position and orientation either
// indirectly through property refs // indirectly through property refs

157
src/Model/placement.cxx Normal file
View file

@ -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 <simgear/compiler.h>
#include <string.h> // for strcmp()
#include <vector>
#include <plib/sg.h>
#include <plib/ssg.h>
#include <plib/ul.h>
#include <simgear/scene/model/location.hxx>
#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

115
src/Model/placement.hxx Normal file
View file

@ -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 <vector>
SG_USING_STD(vector);
#include <plib/sg.h>
#include <plib/ssg.h>
#include <simgear/math/point3d.hxx>
#include <simgear/props/props.hxx>
// 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

View file

@ -29,6 +29,8 @@
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <Model/placement.hxx>
#include "multiplay.hxx" #include "multiplay.hxx"
SG_USING_STD(string); SG_USING_STD(string);