#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
#include <Main/viewmgr.hxx>
+#include <Scenery/scenery.hxx>
+
#include "acmodel.hxx"
+#include "model.hxx"
\f
FGAircraftModel::FGAircraftModel ()
: _aircraft(0),
+ _selector(new ssgSelector),
_scene(new ssgRoot),
_nearplane(0.01f),
- _farplane(5000.0f)
+ _farplane(100.0f)
{
}
{
delete _aircraft;
delete _scene;
+ // SSG will delete it
+ globals->get_scenery()->get_aircraft_branch()->removeKid(_selector);
}
void
FGAircraftModel::init ()
{
_aircraft = new FG3DModel;
- _aircraft->init(fgGetString("/sim/model/path", "Models/Geometry/glider.ac"));
+ string path = fgGetString("/sim/model/path", "Models/Geometry/glider.ac");
+ try {
+ _aircraft->init(path);
+ } 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("Models/Geometry/glider.ac");
+ }
_scene->addKid(_aircraft->getSceneGraph());
+ _selector->addKid(_aircraft->getSceneGraph());
+ globals->get_scenery()->get_aircraft_branch()->addKid(_selector);
}
void
}
void
-FGAircraftModel::update (int dt)
+FGAircraftModel::update (double dt)
{
int view_number = globals->get_viewmgr()->get_current();
if (view_number == 0 && !fgGetBool("/sim/view/internal")) {
_aircraft->setVisible(false);
- return;
+ } else {
+ _aircraft->setVisible(true);
}
- _aircraft->setVisible(true);
-
_aircraft->setPosition(fgGetDouble("/position/longitude-deg"),
fgGetDouble("/position/latitude-deg"),
fgGetDouble("/position/altitude-ft"));
fgGetDouble("/orientation/heading-deg"));
_aircraft->update(dt);
+}
+
+void
+FGAircraftModel::draw ()
+{
// OK, now adjust the clip planes and draw
// FIXME: view number shouldn't be
// hard-coded.
- if (globals->get_current_view()->getType() == 0) {
+ int view_number = globals->get_viewmgr()->get_current();
+ if (_aircraft->getVisible() && view_number == 0) {
glClearDepth(1);
glClear(GL_DEPTH_BUFFER_BIT);
ssgSetNearFar(_nearplane, _farplane);
+ ssgCullAndDraw(_scene);
+ _selector->select(0);
+ } else {
+ _selector->select(1);
}
- ssgCullAndDraw(_scene);
-}
+}
// end of model.cxx