2002-04-05 03:19:34 +00:00
|
|
|
|
// 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 <string.h> // for strcmp()
|
|
|
|
|
|
|
|
|
|
#include <plib/sg.h>
|
|
|
|
|
#include <plib/ssg.h>
|
|
|
|
|
|
|
|
|
|
#include <simgear/compiler.h>
|
|
|
|
|
#include <simgear/debug/logstream.hxx>
|
|
|
|
|
#include <simgear/misc/exception.hxx>
|
|
|
|
|
#include <simgear/misc/sg_path.hxx>
|
2003-05-09 19:39:48 +00:00
|
|
|
|
#include <simgear/scene/model/placement.hxx>
|
2002-04-05 03:19:34 +00:00
|
|
|
|
|
|
|
|
|
#include <Main/globals.hxx>
|
|
|
|
|
#include <Main/fg_props.hxx>
|
|
|
|
|
#include <Main/viewmgr.hxx>
|
2002-05-14 05:49:47 +00:00
|
|
|
|
#include <Scenery/scenery.hxx>
|
2002-04-20 14:07:03 +00:00
|
|
|
|
|
2003-05-08 20:28:46 +00:00
|
|
|
|
#include "model_panel.hxx"
|
|
|
|
|
|
2002-04-05 03:19:34 +00:00
|
|
|
|
#include "acmodel.hxx"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Implementation of FGAircraftModel
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
FGAircraftModel::FGAircraftModel ()
|
2002-04-09 21:08:28 +00:00
|
|
|
|
: _aircraft(0),
|
2002-04-13 21:36:22 +00:00
|
|
|
|
_selector(new ssgSelector),
|
2002-04-09 21:08:28 +00:00
|
|
|
|
_scene(new ssgRoot),
|
|
|
|
|
_nearplane(0.01f),
|
2003-09-15 22:55:39 +00:00
|
|
|
|
_farplane(1000.0f)
|
2002-04-05 03:19:34 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FGAircraftModel::~FGAircraftModel ()
|
|
|
|
|
{
|
|
|
|
|
delete _aircraft;
|
2002-04-09 21:08:28 +00:00
|
|
|
|
delete _scene;
|
2002-04-13 21:36:22 +00:00
|
|
|
|
// SSG will delete it
|
2002-05-14 05:49:47 +00:00
|
|
|
|
globals->get_scenery()->get_aircraft_branch()->removeKid(_selector);
|
2002-04-05 03:19:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGAircraftModel::init ()
|
|
|
|
|
{
|
2003-05-13 03:18:42 +00:00
|
|
|
|
_aircraft = new SGModelPlacement;
|
2002-05-29 22:04:36 +00:00
|
|
|
|
string path = fgGetString("/sim/model/path", "Models/Geometry/glider.ac");
|
|
|
|
|
try {
|
2003-05-08 20:28:46 +00:00
|
|
|
|
ssgBranch *model = fgLoad3DModelPanel( globals->get_fg_root(),
|
|
|
|
|
path,
|
|
|
|
|
globals->get_props(),
|
|
|
|
|
globals->get_sim_time_sec() );
|
|
|
|
|
_aircraft->init( model );
|
2002-05-29 22:04:36 +00:00
|
|
|
|
} 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.)");
|
2003-05-08 20:28:46 +00:00
|
|
|
|
ssgBranch *model = fgLoad3DModelPanel( globals->get_fg_root(),
|
|
|
|
|
"Models/Geometry/glider.ac",
|
|
|
|
|
globals->get_props(),
|
|
|
|
|
globals->get_sim_time_sec() );
|
|
|
|
|
_aircraft->init( model );
|
2002-05-29 22:04:36 +00:00
|
|
|
|
}
|
2002-04-09 21:08:28 +00:00
|
|
|
|
_scene->addKid(_aircraft->getSceneGraph());
|
2002-04-13 21:36:22 +00:00
|
|
|
|
_selector->addKid(_aircraft->getSceneGraph());
|
2002-05-14 05:49:47 +00:00
|
|
|
|
globals->get_scenery()->get_aircraft_branch()->addKid(_selector);
|
2002-04-05 03:19:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGAircraftModel::bind ()
|
|
|
|
|
{
|
|
|
|
|
// No-op
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGAircraftModel::unbind ()
|
|
|
|
|
{
|
|
|
|
|
// No-op
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2002-05-11 16:28:50 +00:00
|
|
|
|
FGAircraftModel::update (double dt)
|
2002-04-05 03:19:34 +00:00
|
|
|
|
{
|
|
|
|
|
int view_number = globals->get_viewmgr()->get_current();
|
|
|
|
|
|
|
|
|
|
if (view_number == 0 && !fgGetBool("/sim/view/internal")) {
|
|
|
|
|
_aircraft->setVisible(false);
|
2002-04-11 04:25:30 +00:00
|
|
|
|
} else {
|
|
|
|
|
_aircraft->setVisible(true);
|
2002-04-05 03:19:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_aircraft->setPosition(fgGetDouble("/position/longitude-deg"),
|
|
|
|
|
fgGetDouble("/position/latitude-deg"),
|
|
|
|
|
fgGetDouble("/position/altitude-ft"));
|
|
|
|
|
_aircraft->setOrientation(fgGetDouble("/orientation/roll-deg"),
|
|
|
|
|
fgGetDouble("/orientation/pitch-deg"),
|
|
|
|
|
fgGetDouble("/orientation/heading-deg"));
|
2003-05-06 23:46:24 +00:00
|
|
|
|
_aircraft->update( globals->get_scenery()->get_center() );
|
2002-04-09 21:08:28 +00:00
|
|
|
|
|
2002-04-11 04:25:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGAircraftModel::draw ()
|
|
|
|
|
{
|
2002-04-09 21:08:28 +00:00
|
|
|
|
// OK, now adjust the clip planes and draw
|
|
|
|
|
// FIXME: view number shouldn't be
|
|
|
|
|
// hard-coded.
|
2002-04-13 12:11:27 +00:00
|
|
|
|
int view_number = globals->get_viewmgr()->get_current();
|
2002-04-13 21:36:22 +00:00
|
|
|
|
if (_aircraft->getVisible() && view_number == 0) {
|
|
|
|
|
glClearDepth(1);
|
|
|
|
|
glClear(GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
ssgSetNearFar(_nearplane, _farplane);
|
2002-04-11 04:25:30 +00:00
|
|
|
|
ssgCullAndDraw(_scene);
|
2002-04-13 21:36:22 +00:00
|
|
|
|
_selector->select(0);
|
|
|
|
|
} else {
|
|
|
|
|
_selector->select(1);
|
2002-04-09 21:08:28 +00:00
|
|
|
|
}
|
2002-04-05 03:19:34 +00:00
|
|
|
|
|
2002-04-11 04:25:30 +00:00
|
|
|
|
}
|
2002-04-05 03:19:34 +00:00
|
|
|
|
|
|
|
|
|
// end of model.cxx
|