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