]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/cloudfield.hxx
Change cloudfield::addCloud interface,
[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
29 #include <osgDB/ReaderWriter>
30
31 #include <osg/ref_ptr>
32 #include <osg/Array>
33 #include <osg/Geometry>
34 #include <osg/Group>
35 #include <osg/Switch>
36
37 namespace osg
38 {
39         class Fog;
40         class StateSet;
41         class Vec4f;
42 }
43
44 #include <simgear/misc/sg_path.hxx>
45 #include <simgear/structure/Singleton.hxx>
46 #include <simgear/math/SGMath.hxx>
47
48 using std::vector;
49
50 class SGNewCloud;
51
52 namespace simgear
53 {
54     class EffectGeode;
55 }
56
57 /**
58  * A layer of 3D clouds.
59  */
60 class SGCloudField {
61
62 private:
63         class Cloud  {
64         public:
65                 SGNewCloud      *aCloud;
66                 SGVec3f         pos;
67                 bool            visible;
68         };
69
70         float Rnd(float);
71         
72         // We create a quadtree two levels deep
73         static const int BRANCH_SIZE = 16;
74         static const int QUADTREE_SIZE = 32;
75
76         // this is a relative position only, with that we can move all clouds at once
77         SGVec3f relative_position;
78         //      double lon, lat;
79
80         osg::ref_ptr<osg::Group> field_root;
81         osg::ref_ptr<osg::MatrixTransform> field_transform;
82         osg::ref_ptr<osg::PositionAttitudeTransform> altitude_transform;
83         osg::ref_ptr<osg::Switch> field_group[QUADTREE_SIZE][QUADTREE_SIZE];
84         osg::ref_ptr<osg::LOD> quad[BRANCH_SIZE][BRANCH_SIZE];
85         
86         osg::ref_ptr<osg::LOD> field_lod;
87
88         double deltax, deltay, alt;
89         double last_course;
90         float last_coverage;
91         float coverage;
92         SGGeoc cld_pos;
93         int reposition_count;
94         struct CloudFog : public simgear::Singleton<CloudFog>
95         {
96                 CloudFog();
97                 osg::ref_ptr<osg::Fog> fog;
98         };
99 public:
100
101         SGCloudField();
102         ~SGCloudField();
103
104         void clear(void);
105
106         // add one cloud, data is not copied, ownership given
107         void addCloud( SGVec3f& pos, osg::ref_ptr<simgear::EffectGeode> cloud);
108
109         /**
110         * reposition the cloud layer at the specified origin and
111         * orientation.
112         * @param p position vector
113         * @param up the local up vector
114         * @param lon specifies a rotation about the Z axis
115         * @param lat specifies a rotation about the new Y axis
116         * @param dt the time elapsed since the last call
117         * @param asl altitude of the layer
118         */
119         bool reposition( const SGVec3f& p, const SGVec3f& up,
120                         double lon, double lat, double dt, int asl);
121
122         osg::Group* getNode() { return field_root.get(); }
123
124         // visibility distance for clouds in meters
125         static float CloudVis;
126
127         static SGVec3f view_vec, view_X, view_Y;
128
129         static float view_distance;
130         static double timer_dt;
131         static float fieldSize;
132         
133         bool defined3D;
134
135         float getCoverage(void) { return coverage; }
136         void setCoverage(float c) { coverage = c; }
137
138         static float getVisRange(void) { return view_distance; }
139         static void setVisRange(float d) { view_distance = d; }
140         
141         void applyCoverage(void);
142         void applyVisRange(void);
143         
144         static osg::Fog* getFog()
145         {
146                 return CloudFog::instance()->fog.get();
147         }
148         static void updateFog(double visibility, const osg::Vec4f& color);
149 };
150
151 #endif // _CLOUDFIELD_HXX