]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/sky/cloudfield.hxx
Work around apparent OSG 3.2.0 normal binding bug.
[simgear.git] / simgear / scene / sky / cloudfield.hxx
index 703b17a1ea96ddcc3a65f8adfcadb7fd4fe42caf..28095c4b97321521d0cdbd79e4239bce141a4964 100644 (file)
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 //
 
 #ifndef _CLOUDFIELD_HXX
 #define _CLOUDFIELD_HXX
 
-#include <plib/sg.h>
 #include <simgear/compiler.h>
 #include <vector>
+#include <map>
 
+#include <osgDB/ReaderWriter>
 
-SG_USING_STD(vector);
+#include <osg/ref_ptr>
+#include <osg/Array>
+#include <osg/Geometry>
+#include <osg/Group>
+#include <osg/Switch>
+
+namespace osg
+{
+        class Fog;
+        class StateSet;
+        class Vec4f;
+}
+
+#include <simgear/misc/sg_path.hxx>
+#include <simgear/structure/Singleton.hxx>
+#include <simgear/math/SGMath.hxx>
+
+using std::vector;
 
 class SGNewCloud;
 
-class culledCloud {
-public:
-       SGNewCloud      *aCloud;
-       sgVec3          eyePos;
-       float           dist;
-       float           heading;
-       float           alt;
-       bool operator<(const culledCloud &b) const {
-               return (this->dist < b.dist);
-       }
-};
-typedef vector<culledCloud> list_of_culledCloud;
+namespace simgear
+{
+    class EffectGeode;
+}
+
+typedef std::map<int, osg::ref_ptr<osg::PositionAttitudeTransform> > CloudHash;
 
 /**
- * A layer of 3D clouds.
+ * A layer of 3D clouds, defined by lat/long/alt.
  */
 class SGCloudField {
 
@@ -54,31 +66,39 @@ private:
        class Cloud  {
        public:
                SGNewCloud      *aCloud;
-               sgVec3          pos;
+               SGVec3f         pos;
                bool            visible;
        };
 
+  float Rnd(float);
+        
+  // Theoretical maximum cloud depth, used for fudging the LoD
+  // ranges to ensure that clouds become visible at maximum range
+  static float MAX_CLOUD_DEPTH;
 
-       typedef vector<Cloud> list_of_Cloud;
-
-       // cull all clouds of a tiled field
-       void cullClouds(sgVec3 eyePos, sgMat4 mat);
+  // this is a relative position only, with that we can move all clouds at once
+  SGVec3f relative_position;
 
-       void applyDensity(void);
+  osg::ref_ptr<osg::Group> field_root;
+  osg::ref_ptr<osg::Group> placed_root;
+  osg::ref_ptr<osg::PositionAttitudeTransform> field_transform;
+  osg::ref_ptr<osg::PositionAttitudeTransform> altitude_transform;
+  osg::ref_ptr<osg::LOD> field_lod;
 
-       list_of_Cloud theField;
-       // this is a relative position only, with that we can move all clouds at once
-       sgVec3 relative_position;
-//     double lon, lat;
+  osg::Vec3f old_pos;
+  CloudHash cloud_hash;
 
-       sgFrustum frustum;
+  struct CloudFog : public simgear::Singleton<CloudFog>
+  {
+    CloudFog();
+    osg::ref_ptr<osg::Fog> fog;
+  };
 
-       sgMat4 transform;
-       double deltax, deltay, alt;
-    double last_lon, last_lat, last_course;
-
-       float   last_density;
-       bool    draw_in_3d;
+  void removeCloudFromTree(osg::ref_ptr<osg::PositionAttitudeTransform> transform);
+  void addCloudToTree(osg::ref_ptr<osg::PositionAttitudeTransform> transform, float lon, float lat, float alt, float x, float y);
+  void addCloudToTree(osg::ref_ptr<osg::PositionAttitudeTransform> transform, SGGeod loc, float x, float y);
+  void addCloudToTree(osg::ref_ptr<osg::PositionAttitudeTransform> transform, SGGeod loc);
+  void applyVisRangeAndCoverage(void);
 
 public:
 
@@ -86,43 +106,75 @@ public:
        ~SGCloudField();
 
        void clear(void);
+       bool isDefined3D(void);
 
        // add one cloud, data is not copied, ownership given
-       void addCloud( sgVec3 pos, SGNewCloud *cloud);
-
-       // for debug only
-       void buildTestLayer(void);
-
-       // Render a cloud field
-       void Render(void);
-
-       // reposition the cloud layer at the specified origin and orientation
-       void reposition( sgVec3 p, sgVec3 up, double lon, double lat, double alt, double dt, float direction, float speed);
-
-       bool is3D(void) { return draw_in_3d; }
-
-       // visibility distance for clouds in meters
-       static float CloudVis;
-
-       static sgVec3 view_vec, view_X, view_Y;
-
-       static float density;
-       static double timer_dt;
-       static double fieldSize;
-       static bool enable3D;
-
-       // return the size of the memory pool used by texture impostors
-       static int get_CacheSize(void);
-       static int get_CacheResolution(void);
-       static float get_CloudVis(void) { return CloudVis; }
-       static float get_density(void) { return density; }
-       static bool get_enable3dClouds(void) { return enable3D; }
-
-       static void set_CacheSize(int sizeKb);
-       static void set_CacheResolution(int resolutionPixels);
-       static void set_CloudVis(float distance);
-       static void set_density(float density);
-       static void set_enable3dClouds(bool enable);
+       void addCloud( SGVec3f& pos, osg::ref_ptr<simgear::EffectGeode> cloud);
+
+        /**
+        * Add a new cloud with a given index at a specific point defined by lon/lat and an x/y offset
+        */
+       bool addCloud(float lon, float lat, float alt, int index, osg::ref_ptr<simgear::EffectGeode> geode);
+       bool addCloud(float lon, float lat, float alt, float x, float y, int index, osg::ref_ptr<simgear::EffectGeode> geode);
+
+       // Cloud handling functions.
+  bool deleteCloud(int identifier);
+  bool repositionCloud(int identifier, float lon, float lat, float alt);
+  bool repositionCloud(int identifier, float lon, float lat, float alt, float x, float y);
+
+
+  /**
+    * reposition the cloud layer at the specified origin and
+    * orientation.
+    * @param p position vector
+    * @param up the local up vector
+    * @param lon specifies a rotation about the Z axis
+    * @param lat specifies a rotation about the new Y axis
+    * @param dt the time elapsed since the last call
+    * @param asl altitude of the layer
+    * @param speed of cloud layer movement (due to wind)
+    * @param direction of cloud layer movement (due to wind)
+    */
+  bool reposition( const SGVec3f& p, const SGVec3f& up,
+            double lon, double lat, double dt, int asl, float speed, float direction);
+
+  osg::Group* getNode() { return field_root.get(); }
+
+  // visibility distance for clouds in meters
+  static float CloudVis;
+
+  static SGVec3f view_vec, view_X, view_Y;
+
+  static float view_distance;
+  static float impostor_distance;
+  static float lod1_range;
+  static float lod2_range;
+  static bool use_impostors;
+  static double timer_dt;
+  static float fieldSize;
+  static bool wrap;
+
+  static bool getWrap(void) { return wrap; }
+  static void setWrap(bool w) { wrap = w; }
+
+  static float getImpostorDistance(void) { return impostor_distance; }
+  static void setImpostorDistance(float d) { impostor_distance = d; }
+  static float getLoD1Range(void) { return lod1_range; }
+  static void setLoD1Range(int d) { lod1_range = d; }
+  static float getLoD2Range(void) { return lod2_range; }
+  static void setLoD2Range(int d) { lod2_range = d; }
+  static void setUseImpostors(bool b) { use_impostors = b; }
+  static bool getUseImpostors(void) { return use_impostors; }
+  
+  static float getVisRange(void) { return view_distance; }
+  static void setVisRange(float d) { view_distance = d; }
+  void applyVisAndLoDRange(void);
+
+  static osg::Fog* getFog()
+  {
+          return CloudFog::instance()->fog.get();
+  }
+  static void updateFog(double visibility, const osg::Vec4f& color);
 };
 
 #endif // _CLOUDFIELD_HXX