]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/sky/dome.cxx
Added some OSG headers for the correct evaluation of the OSG_VERSION_LESS_THAN macro.
[simgear.git] / simgear / scene / sky / dome.cxx
index 5cd40cb43611206d9238e0ef45c32a1f8eca1abd..3cdc9923d4d9d3d4f545e1a4c157eb07d28e04e7 100644 (file)
 #include <osg/ShadeModel>
 #include <osg/PrimitiveSet>
 #include <osg/CullFace>
+#include <osgDB/Registry>
 
 #include <simgear/debug/logstream.hxx>
-#include <simgear/math/Math.hxx>
+#include <simgear/scene/util/OsgMath.hxx>
+#include <simgear/scene/util/SGReaderWriterOptions.hxx>
 #include <simgear/scene/util/VectorArrayAdapter.hxx>
 #include <simgear/scene/material/Effect.hxx>
 #include <simgear/scene/material/EffectGeode.hxx>
 using namespace osg;
 using namespace simgear;
 
-// proportions of max dimensions fed to the build() routine
-static const float center_elev = 1.0;
-
 namespace
 {
-/* unused ?
-struct DomeParam
-{
-    float radius;
-    float elev;
-} domeParams[] = {{.5, .8660},  // 60deg from horizon
-                  {.8660, .5},  // 30deg from horizon
-                  // Original dome horizon vertices
-                  {0.9701, 0.2425},
-                  {0.9960, 0.0885},
-                  {1.0, 0.0},
-                  {0.9922, -0.1240}};
-*/
-
-const int numRings = 64; //sizeof(domeParams) / sizeof(domeParams[0]);
-const int numBands = 64; // 12
-const int halfBands = numBands / 2;
-
-// Make dome a bit over half sphere
-const float domeAngle = 120.0;
-
-const float bandDelta = 360.0 / numBands;
-const float ringDelta = domeAngle / (numRings+1);
-
-// Which band is at horizon
-const int halfRings = numRings * (90.0 / domeAngle);
-const int upperRings = numRings * (60.0 / domeAngle); // top half
-const int middleRings = numRings * (15.0 / domeAngle);
-
-}
+  // proportions of max dimensions fed to the build() routine
+  const float center_elev = 1.0;
 
-static const float upper_radius = 0.9701; // (.6, 0.15)
-static const float upper_elev = 0.2425;
+  const int numRings = 64; //sizeof(domeParams) / sizeof(domeParams[0]);
+  const int numBands = 64; // 12
+  const int halfBands = numBands / 2;
 
-static const float middle_radius = 0.9960; // (.9, .08)
-static const float middle_elev = 0.0885;
+  // Make dome a bit over half sphere
+  const float domeAngle = 120.0;
 
-static const float lower_radius = 1.0;
-static const float lower_elev = 0.0;
-
-static const float bottom_radius = 0.9922; // (.8, -.1)
-static const float bottom_elev = -0.1240;
+  const float bandDelta = 360.0 / numBands;
+  const float ringDelta = domeAngle / (numRings+1);
 
+  // Which band is at horizon
+  const int halfRings = numRings * (90.0 / domeAngle);
+  const int upperRings = numRings * (60.0 / domeAngle); // top half
+  const int middleRings = numRings * (15.0 / domeAngle);
+}
 
 // Constructor
 SGSkyDome::SGSkyDome( void ) {
@@ -137,7 +111,7 @@ void SGSkyDome::makeDome(int rings, int bands, DrawElementsUShort& elements)
         = std::back_inserter(elements);
     GridIndex grid(*dome_vl, numBands, 1);
     for (int i = 0; i < bands; i++) {
-        *pusher = 0;  *pusher = grid(0, i+1);  *pusher = grid(0, i);
+        *pusher = 0;  *pusher = grid(0, (i+1)%bands);  *pusher = grid(0, i);
         // down a band
         for (int j = 0; j < rings - 1; ++j) {
             *pusher = grid(j, i);  *pusher = grid(j, (i + 1)%bands);
@@ -145,28 +119,18 @@ void SGSkyDome::makeDome(int rings, int bands, DrawElementsUShort& elements)
             *pusher = grid(j, i);  *pusher =  grid(j + 1, (i + 1)%bands);
             *pusher =  grid(j + 1, i);
         }
-        // and up the next one
-/*        for (int j = rings - 1; j > 0; --j) {
-            *pusher = grid(j, i + 1);  *pusher = grid(j - 1, i + 1);
-            *pusher = grid(j, (i + 2) % bands);
-            *pusher = grid(j, (i + 2) % bands); *pusher = grid(j - 1, i + 1);
-            *pusher = grid(j - 1, (i + 2) % bands);
-        }
-        *pusher = grid(0, i + 1);  *pusher = 0;
-        *pusher = grid(0, (i + 2) % bands);*/
     }
 }
 
 // initialize the sky object and connect it into our scene graph
 osg::Node*
-SGSkyDome::build( double hscale, double vscale ) {
+SGSkyDome::build( double hscale, double vscale, simgear::SGReaderWriterOptions *options ) {
 
     EffectGeode* geode = new EffectGeode;
-//    Geode* geode = new Geode;
     geode->setName("Skydome");
     geode->setCullingActive(false); // Prevent skydome from being culled away
 
-    Effect *effect = makeEffect("Effects/skydome", true);
+    Effect *effect = makeEffect("Effects/skydome", true, options);
     if(effect)
       geode->setEffect(effect);
 
@@ -214,8 +178,7 @@ SGSkyDome::build( double hscale, double vscale ) {
     geom->setName("Dome Elements");
     geom->setUseDisplayList(false);
     geom->setVertexArray(dome_vl.get());
-    geom->setColorArray(dome_cl.get());
-    geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
+    geom->setColorArray(dome_cl.get(), osg::Array::BIND_PER_VERTEX);
     geom->setNormalBinding(osg::Geometry::BIND_OFF);
     geom->addPrimitiveSet(domeElements);
     geode->addDrawable(geom);
@@ -234,7 +197,7 @@ static void fade_to_black(osg::Vec3 sky_color[], float asl, int count) {
         sky_color[i] *= d;
 }
 
-inline void clampColor(osg::Vec3& color)
+static inline void clampColor(osg::Vec3& color)
 {
     color.x() = osg::clampTo(color.x(), 0.0f, 1.0f);
     color.y() = osg::clampTo(color.y(), 0.0f, 1.0f);
@@ -270,7 +233,7 @@ SGSkyDome::repaint( const SGVec3f& sun_color, const SGVec3f& sky_color,
        outer_diff = SGVec3f(0, 0, 0);
        middle_diff = SGVec3f(0, 0, 0);
     }
-    // printf("  outer_red_param = %.2f  outer_red_diff = %.2f\n", 
+    // printf("  outer_red_param = %.2f  outer_red_diff = %.2f\n",
     //        outer_red_param, outer_red_diff);
 
     // calculate transition colors between sky and fog
@@ -310,17 +273,17 @@ SGSkyDome::repaint( const SGVec3f& sun_color, const SGVec3f& sky_color,
         int j=0;
         // Color top half by linear interpolation (90...60 degrees)
         for (; j < upperRings; j++)
-            colors(j, i) = simgear::math::lerp(toOsg(sky_color), colors(upperRings, i), j / (float)upperRings);
+            colors(j, i) = SGMiscf::lerp(toOsg(sky_color), colors(upperRings, i), j / (float)upperRings);
 
         j++; // Skip the 60 deg ring
         // From 60 to ~85 degrees
         for (int l = 0; j < upperRings + middleRings + 1; j++, l++)
-            colors(j, i) = simgear::math::lerp(colors(upperRings, i),
+            colors(j, i) = SGMiscf::lerp(colors(upperRings, i),
                        toOsg(sky_color - middleVisFactor * diff + middle_amt), l / (float)middleRings);
 
         // 85 to 90 degrees
         for (int l = 0; j < halfRings; j++, l++)
-            colors(j, i) = simgear::math::lerp(colors(upperRings + middleRings, i), toOsg(fog_color + outer_amt),
+            colors(j, i) = SGMiscf::lerp(colors(upperRings + middleRings, i), toOsg(fog_color + outer_amt),
                         l / (float)(halfRings - upperRings - middleRings));
 
         // Original colors
@@ -379,7 +342,7 @@ SGSkyDome::reposition( const SGVec3f& p, double _asl,
     // xglTranslatef( zero_elev.x(), zero_elev.y(), zero_elev.z() );
     T.makeTranslate( toOsg(p) );
 
-    // printf("  Translated to %.2f %.2f %.2f\n", 
+    // printf("  Translated to %.2f %.2f %.2f\n",
     //        zero_elev.x, zero_elev.y, zero_elev.z );
 
     // Rotate to proper orientation