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