FlightGear next
scenery.hxx
Go to the documentation of this file.
1// scenery.hxx -- data structures and routines for managing scenery.
2//
3// Written by Curtis Olson, started May 1997.
4//
5// Copyright (C) 1997 Curtis L. Olson - http://www.flightgear.org/~curt
6//
7// This program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public License as
9// published by the Free Software Foundation; either version 2 of the
10// License, or (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful, but
13// WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15// General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program; if not, write to the Free Software
19// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20//
21// $Id$
22
23
24#ifndef _SCENERY_HXX
25#define _SCENERY_HXX
26
27
28#ifndef __cplusplus
29# error This library requires C++
30#endif
31
32#include <osg/ref_ptr>
33#include <osg/Switch>
34
35#include <simgear/compiler.h>
36#include <simgear/math/SGMath.hxx>
37#include <simgear/scene/model/particles.hxx>
38#include <simgear/structure/subsystem_mgr.hxx>
39
40#include "SceneryPager.hxx"
41#include "terrain.hxx"
42
43namespace simgear {
44class BVHMaterial;
45}
46
47class FGTerrain;
48
49// Define a structure containing global scenery parameters
50class FGScenery : public SGSubsystem
51{
54
55 // scene graph
56 osg::ref_ptr<osg::Switch> scene_graph;
57 osg::ref_ptr<osg::Group> terrain_branch;
58 osg::ref_ptr<osg::Group> models_branch;
59 osg::ref_ptr<osg::Group> aircraft_branch;
60 osg::ref_ptr<osg::Group> interior_branch;
61 osg::ref_ptr<osg::Group> particles_branch;
62 osg::ref_ptr<osg::Group> precipitation_branch;
63
64 osg::ref_ptr<flightgear::SceneryPager> _pager;
65 ScenerySwitchListener* _listener;
66
69 TextureCacheListener* _textureCacheListener;
70
73 ElevationMeshListener* _elevationMeshListener;
74
75public:
76 FGScenery();
77 ~FGScenery();
78
79 // Subsystem API.
80 void bind() override;
81 void init() override;
82 void reinit() override;
83 void shutdown() override;
84 void unbind() override;
85 void update(double dt) override;
86
87 // Subsystem identification.
88 static const char* staticSubsystemClassId() { return "scenery"; }
89
100 bool get_elevation_m(const SGGeod& geod, double& alt,
101 const simgear::BVHMaterial** material,
102 const osg::Node* butNotFrom = 0);
103
115 bool get_cart_elevation_m(const SGVec3d& pos, double max_altoff,
116 double& elevation,
117 const simgear::BVHMaterial** material,
118 const osg::Node* butNotFrom = 0);
119
125 bool get_cart_ground_intersection(const SGVec3d& start, const SGVec3d& dir,
126 SGVec3d& nearestHit,
127 const osg::Node* butNotFrom = 0);
128
129 osg::Group *get_scene_graph () const { return scene_graph.get(); }
130 osg::Group *get_terrain_branch () const { return terrain_branch.get(); }
131 osg::Group *get_models_branch () const { return models_branch.get(); }
132 osg::Group *get_aircraft_branch () const { return aircraft_branch.get(); }
133 osg::Group *get_interior_branch () const { return interior_branch.get(); }
134 osg::Group *get_particles_branch () const { return particles_branch.get(); }
135 osg::Group *get_precipitation_branch () const { return precipitation_branch.get(); }
136
140 bool scenery_available(const SGGeod& position, double range_m);
141
142 // Static because access to the pager is needed before the rest of
143 // the scenery is initialized.
145 static void resetPagerSingleton();
146
147 flightgear::SceneryPager* getPager() { return _pager.get(); }
148
149 // tile mgr api
150 bool schedule_scenery(const SGGeod& position, double range_m, double duration=0.0);
151 void materialLibChanged();
152private:
153 // the terrain engine
154 std::unique_ptr<FGTerrain> _terrain;
155
156 // The state of the scene graph.
157 bool _inited;
158};
159
160#endif // _SCENERY_HXX
void bind() override
Definition scenery.cxx:510
static void resetPagerSingleton()
Definition scenery.cxx:567
osg::Group * get_models_branch() const
Definition scenery.hxx:131
osg::Group * get_scene_graph() const
Definition scenery.hxx:129
bool get_cart_elevation_m(const SGVec3d &pos, double max_altoff, double &elevation, const simgear::BVHMaterial **material, const osg::Node *butNotFrom=0)
Compute the elevation of the scenery below the cartesian point pos.
Definition scenery.cxx:517
osg::Group * get_particles_branch() const
Definition scenery.hxx:134
osg::Group * get_aircraft_branch() const
Definition scenery.hxx:132
bool schedule_scenery(const SGGeod &position, double range_m, double duration=0.0)
Definition scenery.cxx:548
osg::Group * get_interior_branch() const
Definition scenery.hxx:133
bool get_cart_ground_intersection(const SGVec3d &start, const SGVec3d &dir, SGVec3d &nearestHit, const osg::Node *butNotFrom=0)
Compute the nearest intersection point of the line starting from start going in direction dir with th...
Definition scenery.cxx:536
void update(double dt) override
Definition scenery.cxx:505
void unbind() override
Definition scenery.cxx:513
flightgear::SceneryPager * getPager()
Definition scenery.hxx:147
bool get_elevation_m(const SGGeod &geod, double &alt, const simgear::BVHMaterial **material, const osg::Node *butNotFrom=0)
Compute the elevation of the scenery at geodetic latitude lat, geodetic longitude lon and not higher ...
Definition scenery.cxx:527
void materialLibChanged()
Definition scenery.cxx:553
bool scenery_available(const SGGeod &position, double range_m)
Returns true if scenery is available for the given lat, lon position within a range of range_m.
Definition scenery.cxx:543
static flightgear::SceneryPager * getPagerSingleton()
Definition scenery.cxx:560
osg::Group * get_terrain_branch() const
Definition scenery.hxx:130
void shutdown() override
Definition scenery.cxx:485
osg::Group * get_precipitation_branch() const
Definition scenery.hxx:135
void init() override
Definition scenery.cxx:406
static const char * staticSubsystemClassId()
Definition scenery.hxx:88
void reinit() override
Definition scenery.cxx:478