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
26 #include <simgear/compiler.h>
29 #include <osgDB/ReaderWriter>
31 #include <osg/ref_ptr>
33 #include <osg/Geometry>
44 #include <simgear/misc/sg_path.hxx>
45 #include <simgear/structure/Singleton.hxx>
46 #include <simgear/math/SGMath.hxx>
53 * A layer of 3D clouds.
67 // We create a quadtree two levels deep
68 static const int BRANCH_SIZE = 16;
69 static const int QUADTREE_SIZE = 32;
71 // this is a relative position only, with that we can move all clouds at once
72 SGVec3f relative_position;
75 osg::ref_ptr<osg::Group> field_root;
76 osg::ref_ptr<osg::MatrixTransform> field_transform;
77 osg::ref_ptr<osg::PositionAttitudeTransform> altitude_transform;
78 osg::ref_ptr<osg::Switch> field_group[QUADTREE_SIZE][QUADTREE_SIZE];
79 osg::ref_ptr<osg::LOD> quad[BRANCH_SIZE][BRANCH_SIZE];
81 osg::ref_ptr<osg::LOD> field_lod;
83 double deltax, deltay, alt;
89 struct CloudFog : public simgear::Singleton<CloudFog>
92 osg::ref_ptr<osg::Fog> fog;
101 // add one cloud, data is not copied, ownership given
102 void addCloud( SGVec3f& pos, SGNewCloud *cloud);
105 * reposition the cloud layer at the specified origin and
107 * @param p position vector
108 * @param up the local up vector
109 * @param lon specifies a rotation about the Z axis
110 * @param lat specifies a rotation about the new Y axis
111 * @param dt the time elapsed since the last call
112 * @param asl altitude of the layer
114 bool reposition( const SGVec3f& p, const SGVec3f& up,
115 double lon, double lat, double dt, int asl);
117 osg::Group* getNode() { return field_root.get(); }
119 // visibility distance for clouds in meters
120 static float CloudVis;
122 static SGVec3f view_vec, view_X, view_Y;
124 static float view_distance;
125 static double timer_dt;
126 static float fieldSize;
130 float getCoverage(void) { return coverage; }
131 void setCoverage(float c) { coverage = c; }
133 static float getVisRange(void) { return view_distance; }
134 static void setVisRange(float d) { view_distance = d; }
136 void applyCoverage(void);
137 void applyVisRange(void);
139 static osg::Fog* getFog()
141 return CloudFog::instance()->fog.get();
143 static void updateFog(double visibility, const osg::Vec4f& color);
146 #endif // _CLOUDFIELD_HXX