]> git.mxchange.org Git - flightgear.git/blob - src/Scenery/scenery.hxx
a1cf2a77b7875ce9ae97bac44ab5cd8a935b55bc
[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 <list>
33
34 #include <osg/ref_ptr>
35 #include <osg/Group>
36
37 #include <simgear/compiler.h>
38 #include <simgear/structure/subsystem_mgr.hxx>
39 #include <simgear/math/point3d.hxx>
40 #include <simgear/scene/model/placementtrans.hxx>
41 #include <simgear/scene/util/SGPickCallback.hxx>
42
43 SG_USING_STD(list);
44
45 class SGMaterial;
46
47
48 // Define a structure containing global scenery parameters
49 class FGScenery : public SGSubsystem {
50     // center of current scenery chunk
51     SGVec3d center;
52
53     // FIXME this should be a views property
54     // angle of sun relative to current local horizontal
55     double sun_angle;
56
57     // SSG scene graph
58     osg::ref_ptr<osg::Group> scene_graph;
59     osg::ref_ptr<osg::Group> terrain_branch;
60     osg::ref_ptr<osg::Group> gnd_lights_root;
61     osg::ref_ptr<osg::Group> vasi_lights_root;
62     osg::ref_ptr<osg::Group> rwy_lights_root;
63     osg::ref_ptr<osg::Group> taxi_lights_root;
64     osg::ref_ptr<osg::Group> models_branch;
65     osg::ref_ptr<osg::Group> aircraft_branch;
66
67     // list of all placement transform, used to move the scenery center on the fly.
68     typedef list<osg::ref_ptr<SGPlacementTransform> > placement_list_type;
69     placement_list_type _placement_list;
70
71 public:
72
73     FGScenery();
74     ~FGScenery();
75
76     // Implementation of SGSubsystem.
77     void init ();
78     void bind ();
79     void unbind ();
80     void update (double dt);
81
82     /// Compute the elevation of the scenery at geodetic latitude lat,
83     /// geodetic longitude lon and not higher than max_alt.
84     /// If the exact flag is set to true, the scenery center is moved to
85     /// gain a higher accuracy of that query. The center is restored past
86     /// that to the original value.
87     /// The altitude hit is returned in the alt argument.
88     /// The method returns true if the scenery is available for the given
89     /// lat/lon pair. If there is no scenery for that point, the altitude
90     /// value is undefined. 
91     /// All values are meant to be in meters or degrees.
92     bool get_elevation_m(double lat, double lon, double max_alt,
93                          double& alt, const SGMaterial** material,
94                          bool exact = false);
95
96     /// Compute the elevation of the scenery beow the cartesian point pos.
97     /// you the returned scenery altitude is not higher than the position
98     /// pos plus an ofset given with max_altoff.
99     /// If the exact flag is set to true, the scenery center is moved to
100     /// gain a higher accuracy of that query. The center is restored past
101     /// that to the original value.
102     /// The altitude hit is returned in the alt argument.
103     /// The method returns true if the scenery is available for the given
104     /// lat/lon pair. If there is no scenery for that point, the altitude
105     /// value is undefined.
106     /// All values are meant to be in meters.
107     bool get_cart_elevation_m(const SGVec3d& pos, double max_altoff,
108                               double& radius, const SGMaterial** material,
109                               bool exact = false);
110
111     /// Compute the nearest intersection point of the line starting from 
112     /// start going in direction dir with the terrain.
113     /// The input and output values should be in cartesian coordinates in the
114     /// usual earth centered wgs84 coordiante system. Units are meters.
115     /// On success, true is returned.
116     bool get_cart_ground_intersection(const SGVec3d& start, const SGVec3d& dir,
117                                       SGVec3d& nearestHit, bool exact = false);
118     void pick(const SGVec3d& pos, const SGVec3d& dir,
119               std::vector<SGSceneryPick>& pickList);
120
121     const SGVec3d& get_center() const { return center; }
122     void set_center( const SGVec3d& p );
123
124     osg::Group *get_scene_graph () const { return scene_graph.get(); }
125     inline void set_scene_graph (osg::Group * s) { scene_graph = s; }
126
127     osg::Group *get_terrain_branch () const { return terrain_branch.get(); }
128     inline void set_terrain_branch (osg::Group * t) { terrain_branch = t; }
129
130     inline osg::Group *get_gnd_lights_root () const {
131         return gnd_lights_root.get();
132     }
133     inline void set_gnd_lights_root (osg::Group *r) {
134         gnd_lights_root = r;
135     }
136
137     inline osg::Group *get_vasi_lights_root () const {
138         return vasi_lights_root.get();
139     }
140     inline void set_vasi_lights_root (osg::Group *r) {
141         vasi_lights_root = r;
142     }
143
144     inline osg::Group *get_rwy_lights_root () const {
145         return rwy_lights_root.get();
146     }
147     inline void set_rwy_lights_root (osg::Group *r) {
148         rwy_lights_root = r;
149     }
150
151     inline osg::Group *get_taxi_lights_root () const {
152         return taxi_lights_root.get();
153     }
154     inline void set_taxi_lights_root (osg::Group *r) {
155         taxi_lights_root = r;
156     }
157
158     inline osg::Group *get_models_branch () const {
159         return models_branch.get();
160     }
161     inline void set_models_branch (osg::Group *t) {
162         models_branch = t;
163     }
164
165     inline osg::Group *get_aircraft_branch () const {
166         return aircraft_branch.get();
167     }
168     inline void set_aircraft_branch (osg::Group *t) {
169         aircraft_branch = t;
170     }
171
172     void register_placement_transform(SGPlacementTransform *trans);
173     void unregister_placement_transform(SGPlacementTransform *trans);
174 };
175
176
177 #endif // _SCENERY_HXX
178
179