1 // a layer of 3d clouds
3 // Written by Harald JOHNSEN, started April 2005.
5 // Copyright (C) 2005 Harald JOHNSEN - hjohnsen@evc.net
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.
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.
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.
23 #ifndef _CLOUDFIELD_HXX
24 #define _CLOUDFIELD_HXX
27 #include <simgear/compiler.h>
29 #include <osgSim/Impostor>
30 #include <osgDB/ReaderWriter>
32 #include <osg/ref_ptr>
34 #include <osg/Geometry>
37 #include <osg/Billboard>
39 #include <simgear/misc/sg_path.hxx>
46 * A layer of 3D clouds.
60 // We create a quadtree two levels deep
61 static const int BRANCH_SIZE = 16;
62 static const int QUADTREE_SIZE = 32;
64 // this is a relative position only, with that we can move all clouds at once
65 sgVec3 relative_position;
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> field_lod;
73 double deltax, deltay, alt;
75 sgSphere field_sphere;
86 // add one cloud, data is not copied, ownership given
87 void addCloud( SGVec3f& pos, SGNewCloud *cloud);
90 * reposition the cloud layer at the specified origin and
92 * @param p position vector
93 * @param up the local up vector
94 * @param lon specifies a rotation about the Z axis
95 * @param lat specifies a rotation about the new Y axis
96 * @param spin specifies a rotation about the new Z axis
97 * (and orients the sunrise/set effects)
98 * @param dt the time elapsed since the last call
100 bool reposition( const SGVec3f& p, const SGVec3f& up,
101 double lon, double lat, double dt = 0.0 );
103 osg::Group* getNode() { return field_root.get(); }
105 // visibility distance for clouds in meters
106 static float CloudVis;
108 static sgVec3 view_vec, view_X, view_Y;
110 static float density;
111 static double timer_dt;
112 static float fieldSize;
116 static float get_density(void) { return density; }
118 static void set_density(float density);
120 void applyDensity(void);
123 #endif // _CLOUDFIELD_HXX