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>
30 #include <osgDB/ReaderWriter>
32 #include <osg/ref_ptr>
34 #include <osg/Geometry>
45 #include <simgear/misc/sg_path.hxx>
46 #include <simgear/structure/Singleton.hxx>
47 #include <simgear/math/SGMath.hxx>
58 typedef std::map<int, osg::ref_ptr<osg::PositionAttitudeTransform> > CloudHash;
61 * A layer of 3D clouds, defined by lat/long/alt.
75 // Radius of the LoD nodes for the dynamic quadtrees.
76 static float RADIUS_LEVEL_1;
77 static float RADIUS_LEVEL_2;
79 // Theoretical maximum cloud depth, used for fudging the LoD
80 // ranges to ensure that clouds become visible at maximum range
81 static float MAX_CLOUD_DEPTH;
83 // this is a relative position only, with that we can move all clouds at once
84 SGVec3f relative_position;
86 osg::ref_ptr<osg::Group> field_root;
87 osg::ref_ptr<osg::Group> placed_root;
88 osg::ref_ptr<osg::PositionAttitudeTransform> field_transform;
89 osg::ref_ptr<osg::PositionAttitudeTransform> altitude_transform;
90 osg::ref_ptr<osg::LOD> field_lod;
95 struct CloudFog : public simgear::Singleton<CloudFog>
98 osg::ref_ptr<osg::Fog> fog;
101 void removeCloudFromTree(osg::ref_ptr<osg::PositionAttitudeTransform> transform);
102 void addCloudToTree(osg::ref_ptr<osg::PositionAttitudeTransform> transform, float lon, float lat, float alt, float x, float y);
103 void addCloudToTree(osg::ref_ptr<osg::PositionAttitudeTransform> transform, SGGeod loc, float x, float y);
104 void addCloudToTree(osg::ref_ptr<osg::PositionAttitudeTransform> transform, SGGeod loc);
105 void applyVisRangeAndCoverage(void);
113 bool isDefined3D(void);
115 // add one cloud, data is not copied, ownership given
116 void addCloud( SGVec3f& pos, osg::ref_ptr<simgear::EffectGeode> cloud);
119 * Add a new cloud with a given index at a specific point defined by lon/lat and an x/y offset
121 bool addCloud(float lon, float lat, float alt, int index, osg::ref_ptr<simgear::EffectGeode> geode);
122 bool addCloud(float lon, float lat, float alt, float x, float y, int index, osg::ref_ptr<simgear::EffectGeode> geode);
124 // Cloud handling functions.
125 bool deleteCloud(int identifier);
126 bool repositionCloud(int identifier, float lon, float lat, float alt);
127 bool repositionCloud(int identifier, float lon, float lat, float alt, float x, float y);
131 * reposition the cloud layer at the specified origin and
133 * @param p position vector
134 * @param up the local up vector
135 * @param lon specifies a rotation about the Z axis
136 * @param lat specifies a rotation about the new Y axis
137 * @param dt the time elapsed since the last call
138 * @param asl altitude of the layer
139 * @param speed of cloud layer movement (due to wind)
140 * @param direction of cloud layer movement (due to wind)
142 bool reposition( const SGVec3f& p, const SGVec3f& up,
143 double lon, double lat, double dt, int asl, float speed, float direction);
145 osg::Group* getNode() { return field_root.get(); }
147 // visibility distance for clouds in meters
148 static float CloudVis;
150 static SGVec3f view_vec, view_X, view_Y;
152 static float view_distance;
153 static double timer_dt;
154 static float fieldSize;
157 static bool getWrap(void) { return wrap; }
158 static void setWrap(bool w) { wrap = w; }
160 static float getVisRange(void) { return view_distance; }
161 static void setVisRange(float d) { view_distance = d; }
162 void applyVisRange(void);
164 static osg::Fog* getFog()
166 return CloudFog::instance()->fog.get();
168 static void updateFog(double visibility, const osg::Vec4f& color);
171 #endif // _CLOUDFIELD_HXX