1998-10-16 23:26:44 +00:00
|
|
|
// scenery.hxx -- data structures and routines for managing scenery.
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started May 1997.
|
|
|
|
//
|
2004-11-19 22:10:41 +00:00
|
|
|
// Copyright (C) 1997 Curtis L. Olson - http://www.flightgear.org/~curt
|
1998-10-16 23:26:44 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
1998-10-16 23:26:44 +00:00
|
|
|
//
|
|
|
|
// $Id$
|
1997-06-21 17:57:21 +00:00
|
|
|
|
|
|
|
|
1998-04-30 12:35:26 +00:00
|
|
|
#ifndef _SCENERY_HXX
|
|
|
|
#define _SCENERY_HXX
|
1997-06-21 17:57:21 +00:00
|
|
|
|
|
|
|
|
1998-04-30 12:35:26 +00:00
|
|
|
#ifndef __cplusplus
|
|
|
|
# error This library requires C++
|
|
|
|
#endif
|
1998-04-22 13:21:26 +00:00
|
|
|
|
2006-10-29 19:30:21 +00:00
|
|
|
#include <osg/ref_ptr>
|
2014-02-23 22:27:14 +00:00
|
|
|
#include <osg/Switch>
|
2002-05-14 05:49:47 +00:00
|
|
|
|
Mathias:
I have done a patch to eliminate the jitter of 3D-objects near the viewpoint
(for example 3D cockpit objects).
The problem is the roundoff accuracy of the float values used in the
scenegraph together with the transforms of the eyepoint relative to the
scenery center.
The solution will be to move the scenery center near the view point.
This way floats relative accuracy is enough to show a stable picture.
To get that right I have introduced a transform node for the scenegraph which
is responsible for that shift and uses double values as long as possible.
The scenery subsystem now has a list of all those transforms required to place
objects in the world and will tell all those transforms that the scenery
center has changed when the set_scenery_center() of the scenery subsystem is
called.
The problem was not solvable by SGModelPlacement and SGLocation, since not all
objects, especially the scenery, are placed using these classes.
The first approach was to have the scenery center exactly at the eyepoint.
This works well for the cockpit.
But then the ground jitters a bit below the aircraft. With our default views
you can't see that, but that F-18 has a camera view below the left engine
intake with the nose gear and the ground in its field of view, here I could
see that.
Having the scenery center constant will still have this roundoff problems, but
like it is now too, the roundoff error here is exactly the same in each
frame, so you will not notice any jitter.
The real solution is now to keep the scenery center constant as long as it is
in a ball of 30m radius around the view point. If the scenery center is
outside this ball, just put it at the view point.
As a sideeffect of now beeing able to switch the scenery center in the whole
scenegraph with one function call, I was able to remove a one half of a
problem when switching views, where the scenery center was far off for one or
two frames past switching from one view to the next. Also included is a fix
to the other half of this problem, where the view position was not yet copied
into a view when it is switched (at least under glut). This was responsible
for the 'Error: ...' messages of the cloud subsystem when views were
switched.
2005-04-29 14:38:24 +00:00
|
|
|
#include <simgear/compiler.h>
|
2007-05-08 06:12:26 +00:00
|
|
|
#include <simgear/math/SGMath.hxx>
|
2003-09-24 17:20:55 +00:00
|
|
|
#include <simgear/structure/subsystem_mgr.hxx>
|
1998-04-21 17:02:27 +00:00
|
|
|
|
2007-12-14 22:51:56 +00:00
|
|
|
#include "SceneryPager.hxx"
|
|
|
|
|
2012-08-27 18:51:16 +00:00
|
|
|
namespace simgear {
|
|
|
|
class BVHMaterial;
|
|
|
|
}
|
2004-09-19 18:34:47 +00:00
|
|
|
|
1998-10-16 23:26:44 +00:00
|
|
|
// Define a structure containing global scenery parameters
|
2014-02-23 22:27:14 +00:00
|
|
|
class FGScenery : public SGSubsystem
|
|
|
|
{
|
|
|
|
class ScenerySwitchListener;
|
|
|
|
friend class ScenerySwitchListener;
|
|
|
|
|
1998-07-12 03:18:27 +00:00
|
|
|
|
2007-05-03 18:12:29 +00:00
|
|
|
// scene graph
|
2014-02-23 22:27:14 +00:00
|
|
|
osg::ref_ptr<osg::Switch> scene_graph;
|
2006-10-29 19:30:21 +00:00
|
|
|
osg::ref_ptr<osg::Group> terrain_branch;
|
|
|
|
osg::ref_ptr<osg::Group> models_branch;
|
|
|
|
osg::ref_ptr<osg::Group> aircraft_branch;
|
2013-10-20 19:46:33 +00:00
|
|
|
osg::ref_ptr<osg::Group> interior_branch;
|
|
|
|
|
2012-04-15 13:30:44 +00:00
|
|
|
osg::ref_ptr<flightgear::SceneryPager> _pager;
|
2014-02-23 22:27:14 +00:00
|
|
|
ScenerySwitchListener* _listener;
|
2001-10-28 16:16:30 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
FGScenery();
|
|
|
|
~FGScenery();
|
|
|
|
|
2003-09-24 17:20:55 +00:00
|
|
|
// Implementation of SGSubsystem.
|
2001-10-28 16:16:30 +00:00
|
|
|
void init ();
|
2013-10-06 16:33:09 +00:00
|
|
|
void shutdown ();
|
2001-10-28 16:16:30 +00:00
|
|
|
void bind ();
|
|
|
|
void unbind ();
|
2002-05-11 16:28:50 +00:00
|
|
|
void update (double dt);
|
2001-10-28 16:16:30 +00:00
|
|
|
|
2005-08-14 12:57:12 +00:00
|
|
|
/// Compute the elevation of the scenery at geodetic latitude lat,
|
|
|
|
/// geodetic longitude lon and not higher than max_alt.
|
|
|
|
/// If the exact flag is set to true, the scenery center is moved to
|
|
|
|
/// gain a higher accuracy of that query. The center is restored past
|
|
|
|
/// that to the original value.
|
|
|
|
/// The altitude hit is returned in the alt argument.
|
|
|
|
/// The method returns true if the scenery is available for the given
|
|
|
|
/// lat/lon pair. If there is no scenery for that point, the altitude
|
|
|
|
/// value is undefined.
|
|
|
|
/// All values are meant to be in meters or degrees.
|
2007-07-29 10:21:22 +00:00
|
|
|
bool get_elevation_m(const SGGeod& geod, double& alt,
|
2012-08-27 18:51:16 +00:00
|
|
|
const simgear::BVHMaterial** material,
|
2009-08-07 05:24:18 +00:00
|
|
|
const osg::Node* butNotFrom = 0);
|
2005-08-14 12:57:12 +00:00
|
|
|
|
2012-04-15 13:30:44 +00:00
|
|
|
/// Compute the elevation of the scenery below the cartesian point pos.
|
2005-08-14 12:57:12 +00:00
|
|
|
/// you the returned scenery altitude is not higher than the position
|
2012-04-15 13:30:44 +00:00
|
|
|
/// pos plus an offset given with max_altoff.
|
2005-08-14 12:57:12 +00:00
|
|
|
/// If the exact flag is set to true, the scenery center is moved to
|
|
|
|
/// gain a higher accuracy of that query. The center is restored past
|
|
|
|
/// that to the original value.
|
|
|
|
/// The altitude hit is returned in the alt argument.
|
|
|
|
/// The method returns true if the scenery is available for the given
|
|
|
|
/// lat/lon pair. If there is no scenery for that point, the altitude
|
|
|
|
/// value is undefined.
|
|
|
|
/// All values are meant to be in meters.
|
2006-07-27 16:36:22 +00:00
|
|
|
bool get_cart_elevation_m(const SGVec3d& pos, double max_altoff,
|
2012-08-27 18:51:16 +00:00
|
|
|
double& elevation,
|
|
|
|
const simgear::BVHMaterial** material,
|
2009-08-07 05:24:18 +00:00
|
|
|
const osg::Node* butNotFrom = 0);
|
2001-10-28 16:16:30 +00:00
|
|
|
|
2005-11-09 17:08:04 +00:00
|
|
|
/// Compute the nearest intersection point of the line starting from
|
|
|
|
/// start going in direction dir with the terrain.
|
|
|
|
/// The input and output values should be in cartesian coordinates in the
|
2012-04-15 13:30:44 +00:00
|
|
|
/// usual earth centered wgs84 coordinate system. Units are meters.
|
2005-11-09 17:08:04 +00:00
|
|
|
/// On success, true is returned.
|
2006-07-27 16:36:22 +00:00
|
|
|
bool get_cart_ground_intersection(const SGVec3d& start, const SGVec3d& dir,
|
2009-08-07 05:24:18 +00:00
|
|
|
SGVec3d& nearestHit,
|
|
|
|
const osg::Node* butNotFrom = 0);
|
2001-10-28 16:16:30 +00:00
|
|
|
|
2006-10-29 19:30:21 +00:00
|
|
|
osg::Group *get_scene_graph () const { return scene_graph.get(); }
|
|
|
|
osg::Group *get_terrain_branch () const { return terrain_branch.get(); }
|
2007-05-08 06:12:26 +00:00
|
|
|
osg::Group *get_models_branch () const { return models_branch.get(); }
|
|
|
|
osg::Group *get_aircraft_branch () const { return aircraft_branch.get(); }
|
2013-10-20 19:46:33 +00:00
|
|
|
osg::Group *get_interior_branch () const { return interior_branch.get(); }
|
|
|
|
|
2012-04-15 13:30:44 +00:00
|
|
|
/// Returns true if scenery is available for the given lat, lon position
|
2008-03-22 09:31:06 +00:00
|
|
|
/// within a range of range_m.
|
|
|
|
/// lat and lon are expected to be in degrees.
|
2009-03-12 06:21:35 +00:00
|
|
|
bool scenery_available(const SGGeod& position, double range_m);
|
2008-03-22 09:31:06 +00:00
|
|
|
|
2007-12-14 22:51:56 +00:00
|
|
|
// Static because access to the pager is needed before the rest of
|
|
|
|
// the scenery is initialized.
|
|
|
|
static flightgear::SceneryPager* getPagerSingleton();
|
2013-11-12 22:26:37 +00:00
|
|
|
static void resetPagerSingleton();
|
|
|
|
|
2012-04-15 13:30:44 +00:00
|
|
|
flightgear::SceneryPager* getPager() { return _pager.get(); }
|
2015-12-10 22:30:26 +00:00
|
|
|
|
|
|
|
static const char* subsystemName() { return "scenery"; }
|
1997-07-11 01:29:58 +00:00
|
|
|
};
|
|
|
|
|
2001-10-28 16:16:30 +00:00
|
|
|
|
1998-10-16 23:26:44 +00:00
|
|
|
#endif // _SCENERY_HXX
|
|
|
|
|
|
|
|
|