]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/sky/sky.hxx
Merge branch 'ehofman/sound'
[simgear.git] / simgear / scene / sky / sky.hxx
index 7ddb440a4714dc3186c1084e06623598c93d84d5..28678041ac820ea441acd39c7b64a6f63d738f84 100644 (file)
@@ -6,7 +6,7 @@
 // Written by Curtis Olson, started December 1997.
 // SSG-ified by Curtis Olson, February 2000.
 //
-// Copyright (C) 1997-2000  Curtis L. Olson  - curt@flightgear.org
+// Copyright (C) 1997-2000  Curtis L. Olson  - http://www.flightgear.org/~curt
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Library General Public
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // Library General Public License for more details.
 //
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the
-// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-// Boston, MA  02111-1307, USA.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
 #define _SG_SKY_HXX
 
 
-#ifndef __cplusplus                                                          
+#ifndef __cplusplus
 # error This library requires C++
-#endif                                   
-
-
-#include <plib/ssg.h>          // plib include
+#endif
 
 #include <simgear/compiler.h>
 #include <simgear/misc/sg_path.hxx>
+#include <simgear/props/props.hxx>
 
 #include <vector>
 
-#include <simgear/sky/cloud.hxx>
-#include <simgear/sky/dome.hxx>
-#include <simgear/sky/moon.hxx>
-#include <simgear/sky/oursun.hxx>
-#include <simgear/sky/stars.hxx>
-
-SG_USING_STD(vector);
-
-
-typedef vector < SGCloudLayer* > layer_list_type;
-typedef layer_list_type::iterator layer_list_iterator;
-typedef layer_list_type::const_iterator layer_list_const_iterator;
+#include <osg/ref_ptr>
+#include <osg/MatrixTransform>
+#include <osg/Node>
+#include <osg/Switch>
+
+#include <simgear/ephemeris/ephemeris.hxx>
+#include <simgear/math/SGMath.hxx>
+
+#include <simgear/scene/sky/cloud.hxx>
+#include <simgear/scene/sky/dome.hxx>
+#include <simgear/scene/sky/moon.hxx>
+#include <simgear/scene/sky/oursun.hxx>
+#include <simgear/scene/sky/stars.hxx>
+
+using std::vector;
+
+
+typedef struct {
+        SGVec3d pos;
+        SGGeod pos_geod;
+        SGQuatd ori;
+        double spin;
+       double gst;
+       double sun_dist;
+       double moon_dist;
+       double sun_angle;
+} SGSkyState;
+
+typedef struct {
+       SGVec3f sky_color;
+        SGVec3f adj_sky_color;
+        SGVec3f fog_color;
+       SGVec3f cloud_color;
+       double sun_angle, moon_angle;
+} SGSkyColor;
 
 /**
  * A class to model a realistic (time/date/position) based sky.
@@ -80,10 +100,10 @@ typedef layer_list_type::const_iterator layer_list_const_iterator;
  * texture_path() method.
 
  * The arguments you pass to the build() method allow you to specify
- * the size of your sun sphere and moon sphere, a number of planets,
- * and a multitude of stars.  For the planets and stars you pass in an
- * array of right ascensions, declinations, magnitudes, and the
- * distance from the view point.
+ * the horizontal and vertical radiuses of the sky dome, the size of
+ * your sun sphere and moon sphere, a number of planets, and a
+ * multitude of stars.  For the planets and stars you pass in an array
+ * of right ascensions, declinations, and magnitudes.
 
  * Cloud Layers 
 
@@ -128,22 +148,27 @@ typedef layer_list_type::const_iterator layer_list_const_iterator;
 
  * Rendering the Sky 
 
- * The sky is designed to be rendered in two stages. The first stage
+ * The sky is designed to be rendered in three stages. The first stage
  * renders the parts that form your back drop - the sky dome, the
  * stars and planets, the sun, and the moon.  These should be rendered
  * before the rest of your scene by calling the preDraw() method. The
- * second stage renders the clouds which are likely to be translucent
- * (depending on type) and should be drawn after your scene has been
- * rendered.  Use the postDraw() method to draw the second stage of
- * the sky.
+ * second stage renders the clouds that are above the viewer. This stage 
+ * is done before translucent objects in the main scene are drawn. It 
+ * is seperated from the preDraw routine to enable to implement a 
+ * multi passes technique and is located in the drawUpperClouds() method.
+ * The third stage renders the clouds that are below the viewer an which 
+ * are likely to be translucent (depending on type) and should be drawn 
+ * after your scene has been rendered.  Use the drawLowerClouds() method 
+ * to draw the second stage of the sky.
 
  * A typical application might do the following: 
 
- * <li> thesky->preDraw();
+ * <li> thesky->preDraw( my_altitude );
+ * <li> thesky->drawUpperClouds();
  * <li> ssgCullAndDraw ( myscene ) ;
- * <li> thesky->postDraw( my_altitude );
+ * <li> thesky->drawLowerClouds();
 
- * The current altitude in meters is passed to the postDraw() method
+ * The current altitude in meters is passed to the preDraw() method
  * so the clouds layers can be rendered correction from most distant
  * to closest.
 
@@ -184,19 +209,23 @@ typedef layer_list_type::const_iterator layer_list_const_iterator;
 class SGSky {
 
 private:
+    typedef std::vector<SGSharedPtr<SGCloudLayer> > layer_list_type;
+    typedef layer_list_type::iterator layer_list_iterator;
+    typedef layer_list_type::const_iterator layer_list_const_iterator;
 
     // components of the sky
-    SGSkyDome *dome;
-    SGSun *oursun;
-    SGMoon *moon;
-    SGStars *planets;
-    SGStars *stars;
+    SGSharedPtr<SGSkyDome> dome;
+    SGSharedPtr<SGSun> oursun;
+    SGSharedPtr<SGMoon> moon;
+    SGSharedPtr<SGStars> planets;
+    SGSharedPtr<SGStars> stars;
     layer_list_type cloud_layers;
 
-    ssgRoot *pre_root, *post_root;
+    osg::ref_ptr<osg::Group> pre_root, cloud_root;
+    osg::ref_ptr<osg::Switch> pre_selector;
+    osg::ref_ptr<osg::Group> pre_transform;
 
-    ssgSelector *pre_selector, *post_selector;
-    ssgTransform *pre_transform, *post_transform;
+    osg::ref_ptr<osg::MatrixTransform> _ephTransform;
 
     SGPath tex_path;
 
@@ -204,6 +233,9 @@ private:
     float visibility;
     float effective_visibility;
 
+    int in_cloud;
+    int cur_layer_pos;
+
     // near cloud visibility state variables
     bool in_puff;
     double puff_length;                // in seconds
@@ -211,6 +243,12 @@ private:
     double ramp_up;            // in seconds
     double ramp_down;          // in seconds
 
+    // 3D clouds enabled
+    bool clouds_3d_enabled;
+
+    // 3D cloud density
+    double clouds_3d_density;
+
 public:
 
     /** Constructor */
@@ -223,19 +261,20 @@ public:
      * Initialize the sky and connect the components to the scene
      * graph at the provided branch.  See discussion in detailed class
      * description.
+     * @param h_radius_m horizontal radius of sky dome
+     * @param v_radius_m vertical radius of sky dome
      * @param sun_size size of sun
      * @param moon_size size of moon
      * @param nplanets number of planets
      * @param planet_data an array of planet right ascensions, declinations,
      *        and magnitudes
-     * @param planet_dist distance from viewer to put the planets
      * @param nstars number of stars
      * @param star_data an array of star right ascensions, declinations,
      *        and magnitudes
-     * @param star_dist distance from viewer to put the stars */
-    void build( double sun_size, double moon_size,
-               int nplanets, sgdVec3 *planet_data, double planet_dist,
-               int nstars, sgdVec3 *star_data, double star_dist );
+     */
+    void build( double h_radius_m, double v_radius_m,
+                double sun_size, double moon_size,
+                const SGEphemeris& eph, SGPropertyNode *property_tree_node );
 
     /**
      * Repaint the sky components based on current value of sun_angle,
@@ -261,10 +300,7 @@ public:
      * @param star_data an array of star right ascensions, declinations,
      *        and magnitudes
      */
-    bool repaint( sgVec4 sky_color, sgVec4 fog_color, sgVec4 cloud_color,
-                 double sun_angle, double moon_angle,
-                 int nplanets, sgdVec3 *planet_data,
-                 int nstars, sgdVec3 *star_data );
+    bool repaint( const SGSkyColor &sc, const SGEphemeris& eph );
 
     /**
      * Reposition the sky at the specified origin and orientation
@@ -294,11 +330,7 @@ public:
      * @param moon_dec the moon's current declination
      * @param moon_dist the moon's distance from the current view point. 
      */
-    bool reposition( sgVec3 view_pos, sgVec3 zero_elev, sgVec3 view_up,
-                    double lon, double lat, double alt, double spin,
-                    double gst, 
-                    double sun_ra, double sun_dec, double sun_dist,
-                    double moon_ra, double moon_dec, double moon_dist );
+    bool reposition( const SGSkyState &st, const SGEphemeris& eph, double dt = 0.0 );
 
     /**
      * Modify the given visibility based on cloud layers, thickness,
@@ -310,33 +342,18 @@ public:
      */
     void modify_vis( float alt, float time_factor );
 
-    /**
-     * Draw background portions of the sky ... do this before you draw
-     * the rest of your scene.  See discussion in detailed
-     * class description.
-     */
-    void preDraw();
-
-    /**
-     * Draw translucent clouds ... do this after you've drawn all the
-     * oapaque elements of your scene.  See discussion in detailed
-     * class description.
-     * @param alt current altitude
-     */
-    void postDraw( float alt );
+    osg::Node* getPreRoot() { return pre_root.get(); }
+    osg::Node* getCloudRoot() { return cloud_root.get(); }
 
     /** 
      * Specify the texture path (optional, defaults to current directory)
      * @param path base path to texture locations
      */
-    inline void texture_path( const string& path ) {
-       tex_path = SGPath( path );
-    }
+    void texture_path( const string& path );
 
     /** Enable drawing of the sky. */
     inline void enable() {
-       pre_selector->select( 1 );
-       post_selector->select( 1 );
+        pre_selector->setValue(0, 1);
     }
 
     /**
@@ -344,16 +361,18 @@ public:
      * there, how ever it won't be traversed on by ssgCullandRender()
      */
     inline void disable() {
-       pre_selector->select( 0 );
-       post_selector->select( 0 );
+        pre_selector->setValue(0, 0);
     }
 
-
     /**
      * Get the current sun color
      */
-    inline float *get_sun_color() { return oursun->get_color(); }
+    inline SGVec4f get_sun_color() { return oursun->get_color(); }
 
+    /**
+     * Get the current scene color
+     */
+    inline SGVec4f get_scene_color() { return oursun->get_scene_color(); }
 
     /**
      * Add a cloud layer.
@@ -402,8 +421,25 @@ public:
      * @param v visibility in meters
      */
     inline void set_visibility( float v ) {
-       effective_visibility = visibility = v;
+       effective_visibility = visibility = (v <= 25.0) ? 25.0 : v;
     }
+
+    /** Get 3D cloud density */
+    virtual double get_3dCloudDensity() const;
+
+    /** Set 3D cloud density 
+     * @param density 3D cloud density
+     */
+    virtual void set_3dCloudDensity(double density);
+
+    /** Get 3D cloud visibility range*/
+    virtual float get_3dCloudVisRange() const;
+
+    /** Set 3D cloud visibility range
+     * @param density 3D cloud visibility range
+     */
+    virtual void set_3dCloudVisRange(float vis);
+
 };