]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/cloudfield.hxx
Stuart Buchanan :
[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 <plib/sg.h>
27 #include <simgear/compiler.h>
28 #include <vector>
29 #include <osgSim/Impostor>
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 #include <osg/Billboard>
38
39 #include <simgear/misc/sg_path.hxx>
40
41 using std::vector;
42
43 class SGNewCloud;
44
45 /**
46  * A layer of 3D clouds.
47  */
48 class SGCloudField {
49
50 private:
51         class Cloud  {
52         public:
53                 SGNewCloud      *aCloud;
54                 sgVec3          pos;
55                 bool            visible;
56         };
57
58         float Rnd(float);
59         
60         // We create a quadtree two levels deep
61         static const int BRANCH_SIZE = 16;
62         static const int QUADTREE_SIZE = 32;
63
64         // this is a relative position only, with that we can move all clouds at once
65         sgVec3 relative_position;
66         //      double lon, lat;
67
68         osg::ref_ptr<osg::Group> field_root;
69         osg::ref_ptr<osg::MatrixTransform> field_transform;
70         osg::ref_ptr<osg::Switch> field_group[QUADTREE_SIZE][QUADTREE_SIZE];
71         osg::ref_ptr<osg::LOD> quad[BRANCH_SIZE][BRANCH_SIZE];
72         
73         osg::ref_ptr<osg::LOD> field_lod;
74
75         double deltax, deltay, alt;
76         double last_course;
77         sgSphere field_sphere;
78         float   last_coverage;
79         SGGeoc cld_pos;
80         int reposition_count;
81 public:
82
83         SGCloudField();
84         ~SGCloudField();
85
86         void clear(void);
87
88         // add one cloud, data is not copied, ownership given
89         void addCloud( SGVec3f& pos, SGNewCloud *cloud);
90
91         /**
92         * reposition the cloud layer at the specified origin and
93         * orientation.
94         * @param p position vector
95         * @param up the local up vector
96         * @param lon specifies a rotation about the Z axis
97         * @param lat specifies a rotation about the new Y axis
98         * @param dt the time elapsed since the last call
99         * @param asl altitude of the layer
100         */
101         bool reposition( const SGVec3f& p, const SGVec3f& up,
102                         double lon, double lat, double dt, int asl);
103
104         osg::Group* getNode() { return field_root.get(); }
105
106         // visibility distance for clouds in meters
107         static float CloudVis;
108
109         static sgVec3 view_vec, view_X, view_Y;
110
111         static float coverage;
112         static float view_distance;
113         static double timer_dt;
114         static float fieldSize;
115         
116         bool defined3D;
117
118         static float getCoverage(void) { return coverage; }
119         static void setCoverage(float coverage) { coverage = coverage; }
120
121         static float getVisRange(void) { return view_distance; }
122         static void setVisRange(float d) { view_distance = d; }
123         
124         void applyCoverage(void);
125         void applyVisRange(void);
126         
127         typedef std::map<std::string, osg::ref_ptr<osg::StateSet> > StateSetMap;
128         static StateSetMap cloudTextureMap;
129 };
130
131 #endif // _CLOUDFIELD_HXX