]> git.mxchange.org Git - flightgear.git/blob - src/Scenery/scenery.hxx
Allow using the system version of flite and the HTS engine
[flightgear.git] / src / Scenery / scenery.hxx
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/structure/subsystem_mgr.hxx>
38
39 #include "SceneryPager.hxx"
40
41 namespace simgear {
42 class BVHMaterial;
43 }
44
45 // Define a structure containing global scenery parameters
46 class FGScenery : public SGSubsystem
47 {
48     class ScenerySwitchListener;
49     friend class ScenerySwitchListener;
50   
51
52     // scene graph
53     osg::ref_ptr<osg::Switch> scene_graph;
54     osg::ref_ptr<osg::Group> terrain_branch;
55     osg::ref_ptr<osg::Group> models_branch;
56     osg::ref_ptr<osg::Group> aircraft_branch;
57     osg::ref_ptr<osg::Group> interior_branch;
58     
59     osg::ref_ptr<flightgear::SceneryPager> _pager;
60     ScenerySwitchListener* _listener;
61 public:
62
63     FGScenery();
64     ~FGScenery();
65
66     // Implementation of SGSubsystem.
67     void init ();
68     void shutdown ();
69     void bind ();
70     void unbind ();
71     void update (double dt);
72
73     /// Compute the elevation of the scenery at geodetic latitude lat,
74     /// geodetic longitude lon and not higher than max_alt.
75     /// If the exact flag is set to true, the scenery center is moved to
76     /// gain a higher accuracy of that query. The center is restored past
77     /// that to the original value.
78     /// The altitude hit is returned in the alt argument.
79     /// The method returns true if the scenery is available for the given
80     /// lat/lon pair. If there is no scenery for that point, the altitude
81     /// value is undefined. 
82     /// All values are meant to be in meters or degrees.
83     bool get_elevation_m(const SGGeod& geod, double& alt,
84                          const simgear::BVHMaterial** material,
85                          const osg::Node* butNotFrom = 0);
86
87     /// Compute the elevation of the scenery below the cartesian point pos.
88     /// you the returned scenery altitude is not higher than the position
89     /// pos plus an offset given with max_altoff.
90     /// If the exact flag is set to true, the scenery center is moved to
91     /// gain a higher accuracy of that query. The center is restored past
92     /// that to the original value.
93     /// The altitude hit is returned in the alt argument.
94     /// The method returns true if the scenery is available for the given
95     /// lat/lon pair. If there is no scenery for that point, the altitude
96     /// value is undefined.
97     /// All values are meant to be in meters.
98     bool get_cart_elevation_m(const SGVec3d& pos, double max_altoff,
99                               double& elevation,
100                               const simgear::BVHMaterial** material,
101                               const osg::Node* butNotFrom = 0);
102
103     /// Compute the nearest intersection point of the line starting from 
104     /// start going in direction dir with the terrain.
105     /// The input and output values should be in cartesian coordinates in the
106     /// usual earth centered wgs84 coordinate system. Units are meters.
107     /// On success, true is returned.
108     bool get_cart_ground_intersection(const SGVec3d& start, const SGVec3d& dir,
109                                       SGVec3d& nearestHit,
110                                       const osg::Node* butNotFrom = 0);
111
112     osg::Group *get_scene_graph () const { return scene_graph.get(); }
113     osg::Group *get_terrain_branch () const { return terrain_branch.get(); }
114     osg::Group *get_models_branch () const { return models_branch.get(); }
115     osg::Group *get_aircraft_branch () const { return aircraft_branch.get(); }
116     osg::Group *get_interior_branch () const { return interior_branch.get(); }
117     
118     /// Returns true if scenery is available for the given lat, lon position
119     /// within a range of range_m.
120     /// lat and lon are expected to be in degrees.
121     bool scenery_available(const SGGeod& position, double range_m);
122
123     // Static because access to the pager is needed before the rest of
124     // the scenery is initialized.
125     static flightgear::SceneryPager* getPagerSingleton();
126     static void resetPagerSingleton();
127     
128     flightgear::SceneryPager* getPager() { return _pager.get(); }
129 };
130
131
132 #endif // _SCENERY_HXX
133
134