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 const float RADIUS_LEVEL_1 = 20000.0f;
77 static const float RADIUS_LEVEL_2 = 5000.0f;
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 applyVisRangeAndCoverage(void);
107 bool isDefined3D(void);
109 // add one cloud, data is not copied, ownership given
110 void addCloud( SGVec3f& pos, osg::ref_ptr<simgear::EffectGeode> cloud);
113 * Add a new cloud with a given index at a specific point defined by lon/lat and an x/y offset
115 bool addCloud(float lon, float lat, float alt, int index, osg::ref_ptr<simgear::EffectGeode> geode);
116 bool addCloud(float lon, float lat, float alt, float x, float y, int index, osg::ref_ptr<simgear::EffectGeode> geode);
118 // Cloud handling functions.
119 bool deleteCloud(int identifier);
120 bool repositionCloud(int identifier, float lon, float lat, float alt);
121 bool repositionCloud(int identifier, float lon, float lat, float alt, float x, float y);
125 * reposition the cloud layer at the specified origin and
127 * @param p position vector
128 * @param up the local up vector
129 * @param lon specifies a rotation about the Z axis
130 * @param lat specifies a rotation about the new Y axis
131 * @param dt the time elapsed since the last call
132 * @param asl altitude of the layer
133 * @param speed of cloud layer movement (due to wind)
134 * @param direction of cloud layer movement (due to wind)
136 bool reposition( const SGVec3f& p, const SGVec3f& up,
137 double lon, double lat, double dt, int asl, float speed, float direction);
139 osg::Group* getNode() { return field_root.get(); }
141 // visibility distance for clouds in meters
142 static float CloudVis;
144 static SGVec3f view_vec, view_X, view_Y;
146 static float view_distance;
147 static double timer_dt;
148 static float fieldSize;
151 static float getVisRange(void) { return view_distance; }
152 static void setVisRange(float d) { view_distance = d; }
153 void applyVisRange(void);
155 static osg::Fog* getFog()
157 return CloudFog::instance()->fog.get();
159 static void updateFog(double visibility, const osg::Vec4f& color);
162 #endif // _CLOUDFIELD_HXX