]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/cloudfield.hxx
Remove using std:: from the metar header, remove HTTP support, add very basic unit...
[simgear.git] / simgear / scene / sky / cloudfield.hxx
1 // a layer of 3d clouds
2 //
3 // Written by Harald JOHNSEN, started April 2005.
4 //
5 // Copyright (C) 2005  Harald JOHNSEN - hjohnsen@evc.net
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 //
22
23 #ifndef _CLOUDFIELD_HXX
24 #define _CLOUDFIELD_HXX
25
26 #include <simgear/compiler.h>
27 #include <vector>
28 #include <map>
29
30 #include <osgDB/ReaderWriter>
31
32 #include <osg/ref_ptr>
33 #include <osg/Array>
34 #include <osg/Geometry>
35 #include <osg/Group>
36 #include <osg/Switch>
37
38 namespace osg
39 {
40         class Fog;
41         class StateSet;
42         class Vec4f;
43 }
44
45 #include <simgear/misc/sg_path.hxx>
46 #include <simgear/structure/Singleton.hxx>
47 #include <simgear/math/SGMath.hxx>
48
49 using std::vector;
50
51 class SGNewCloud;
52
53 namespace simgear
54 {
55     class EffectGeode;
56 }
57
58 typedef std::map<int, osg::ref_ptr<osg::PositionAttitudeTransform> > CloudHash;
59
60 /**
61  * A layer of 3D clouds, defined by lat/long/alt.
62  */
63 class SGCloudField {
64
65 private:
66         class Cloud  {
67         public:
68                 SGNewCloud      *aCloud;
69                 SGVec3f         pos;
70                 bool            visible;
71         };
72
73         float Rnd(float);
74         
75   // Radius of the LoD nodes for the dynamic quadtrees.
76   static float RADIUS_LEVEL_1;
77   static float RADIUS_LEVEL_2;
78
79         // this is a relative position only, with that we can move all clouds at once
80         SGVec3f relative_position;
81
82         osg::ref_ptr<osg::Group> field_root;
83   osg::ref_ptr<osg::Group> placed_root;
84   osg::ref_ptr<osg::PositionAttitudeTransform> field_transform;
85         osg::ref_ptr<osg::PositionAttitudeTransform> altitude_transform;
86         osg::ref_ptr<osg::LOD> field_lod;
87
88   osg::Vec3f old_pos;
89   CloudHash cloud_hash;
90
91         struct CloudFog : public simgear::Singleton<CloudFog>
92         {
93                 CloudFog();
94                 osg::ref_ptr<osg::Fog> fog;
95         };
96
97   void removeCloudFromTree(osg::ref_ptr<osg::PositionAttitudeTransform> transform);
98   void addCloudToTree(osg::ref_ptr<osg::PositionAttitudeTransform> transform, float lon, float lat, float alt, float x, float y);
99   void applyVisRangeAndCoverage(void);
100
101 public:
102
103         SGCloudField();
104         ~SGCloudField();
105
106         void clear(void);
107         bool isDefined3D(void);
108
109         // add one cloud, data is not copied, ownership given
110         void addCloud( SGVec3f& pos, osg::ref_ptr<simgear::EffectGeode> cloud);
111
112         /**
113          * Add a new cloud with a given index at a specific point defined by lon/lat and an x/y offset
114          */
115         bool addCloud(float lon, float lat, float alt, int index, osg::ref_ptr<simgear::EffectGeode> geode);
116         bool addCloud(float lon, float lat, float alt, float x, float y, int index, osg::ref_ptr<simgear::EffectGeode> geode);
117
118         // Cloud handling functions.
119   bool deleteCloud(int identifier);
120   bool repositionCloud(int identifier, float lon, float lat, float alt);
121   bool repositionCloud(int identifier, float lon, float lat, float alt, float x, float y);
122
123
124   /**
125         * reposition the cloud layer at the specified origin and
126         * orientation.
127         * @param p position vector
128         * @param up the local up vector
129         * @param lon specifies a rotation about the Z axis
130         * @param lat specifies a rotation about the new Y axis
131         * @param dt the time elapsed since the last call
132         * @param asl altitude of the layer
133         * @param speed of cloud layer movement (due to wind)
134         * @param direction of cloud layer movement (due to wind)
135         */
136         bool reposition( const SGVec3f& p, const SGVec3f& up,
137                   double lon, double lat, double dt, int asl, float speed, float direction);
138
139         osg::Group* getNode() { return field_root.get(); }
140
141         // visibility distance for clouds in meters
142               static float CloudVis;
143
144               static SGVec3f view_vec, view_X, view_Y;
145
146         static float view_distance;
147         static double timer_dt;
148         static float fieldSize;
149               static bool wrap;
150         
151         static bool getWrap(void) { return wrap; }
152         static void setWrap(bool w) { wrap = w; }
153
154         static float getVisRange(void) { return view_distance; }
155         static void setVisRange(float d) { view_distance = d; }
156         void applyVisRange(void);
157         
158         static osg::Fog* getFog()
159         {
160                 return CloudFog::instance()->fog.get();
161         }
162         static void updateFog(double visibility, const osg::Vec4f& color);
163 };
164
165 #endif // _CLOUDFIELD_HXX