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 // Theoretical maximum cloud depth, used for fudging the LoD
76 // ranges to ensure that clouds become visible at maximum range
77 static float MAX_CLOUD_DEPTH;
79 // this is a relative position only, with that we can move all clouds at once
80 SGVec3f relative_position;
82 osg::ref_ptr<osg::Group> field_root;
83 osg::ref_ptr<osg::Group> placed_root;
84 osg::ref_ptr<osg::PositionAttitudeTransform> field_transform;
85 osg::ref_ptr<osg::PositionAttitudeTransform> altitude_transform;
86 osg::ref_ptr<osg::LOD> field_lod;
91 struct CloudFog : public simgear::Singleton<CloudFog>
94 osg::ref_ptr<osg::Fog> fog;
97 void removeCloudFromTree(osg::ref_ptr<osg::PositionAttitudeTransform> transform);
98 void addCloudToTree(osg::ref_ptr<osg::PositionAttitudeTransform> transform, float lon, float lat, float alt, float x, float y);
99 void addCloudToTree(osg::ref_ptr<osg::PositionAttitudeTransform> transform, SGGeod loc, float x, float y);
100 void addCloudToTree(osg::ref_ptr<osg::PositionAttitudeTransform> transform, SGGeod loc);
101 void applyVisRangeAndCoverage(void);
109 bool isDefined3D(void);
111 // add one cloud, data is not copied, ownership given
112 void addCloud( SGVec3f& pos, osg::ref_ptr<simgear::EffectGeode> cloud);
115 * Add a new cloud with a given index at a specific point defined by lon/lat and an x/y offset
117 bool addCloud(float lon, float lat, float alt, int index, osg::ref_ptr<simgear::EffectGeode> geode);
118 bool addCloud(float lon, float lat, float alt, float x, float y, int index, osg::ref_ptr<simgear::EffectGeode> geode);
120 // Cloud handling functions.
121 bool deleteCloud(int identifier);
122 bool repositionCloud(int identifier, float lon, float lat, float alt);
123 bool repositionCloud(int identifier, float lon, float lat, float alt, float x, float y);
127 * reposition the cloud layer at the specified origin and
129 * @param p position vector
130 * @param up the local up vector
131 * @param lon specifies a rotation about the Z axis
132 * @param lat specifies a rotation about the new Y axis
133 * @param dt the time elapsed since the last call
134 * @param asl altitude of the layer
135 * @param speed of cloud layer movement (due to wind)
136 * @param direction of cloud layer movement (due to wind)
138 bool reposition( const SGVec3f& p, const SGVec3f& up,
139 double lon, double lat, double dt, int asl, float speed, float direction);
141 osg::Group* getNode() { return field_root.get(); }
143 // visibility distance for clouds in meters
144 static float CloudVis;
146 static SGVec3f view_vec, view_X, view_Y;
148 static float view_distance;
149 static float impostor_distance;
150 static float lod1_range;
151 static float lod2_range;
152 static bool use_impostors;
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 getImpostorDistance(void) { return impostor_distance; }
161 static void setImpostorDistance(float d) { impostor_distance = d; }
162 static float getLoD1Range(void) { return lod1_range; }
163 static void setLoD1Range(int d) { lod1_range = d; }
164 static float getLoD2Range(void) { return lod2_range; }
165 static void setLoD2Range(int d) { lod2_range = d; }
166 static void setUseImpostors(bool b) { use_impostors = b; }
167 static bool getUseImpostors(void) { return use_impostors; }
169 static float getVisRange(void) { return view_distance; }
170 static void setVisRange(float d) { view_distance = d; }
171 void applyVisAndLoDRange(void);
173 static osg::Fog* getFog()
175 return CloudFog::instance()->fog.get();
177 static void updateFog(double visibility, const osg::Vec4f& color);
180 #endif // _CLOUDFIELD_HXX