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