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