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