]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/sky/moon.cxx
Merge branch 'ehofman/sound'
[simgear.git] / simgear / scene / sky / moon.cxx
index 6cfb8788cb66b920a62ef2d1a89e21cfa8975223..a5366c71681d2908053173e1e950264ca821cb70 100644 (file)
@@ -30,8 +30,9 @@
 #include <simgear/compiler.h>
 
 #include <stdio.h>
-#include STL_IOSTREAM
+#include <iostream>
 
+#include <simgear/structure/OSGVersion.hxx>
 #include <osg/Array>
 #include <osg/AlphaFunc>
 #include <osg/BlendFunc>
 #include <osg/ShadeModel>
 #include <osg/TexEnv>
 #include <osg/Texture2D>
+#if SG_OSG_MIN_VERSION_REQUIRED(2,9,5)
+#include <osgDB/Options>
+#endif
 
 #include <simgear/constants.h>
 #include <simgear/screen/colors.hxx>
 #include <simgear/scene/model/model.hxx>
+#include <simgear/misc/PathOptions.hxx>
 
 #include "sphere.hxx"
 #include "moon.hxx"
 
+using namespace simgear;
+
 // Constructor
 SGMoon::SGMoon( void ) :
     prev_moon_angle(-1)
@@ -71,9 +78,10 @@ SGMoon::build( SGPath path, double moon_size ) {
     stateSet->setRenderBinDetails(-5, "RenderBin");
 
     // set up the orb state
-    path.append( "moon.rgba" );
+    osg::ref_ptr<osgDB::ReaderWriter::Options> options
+        = makeOptionsFromPath(path);
 
-    osg::Texture2D* texture = SGLoadTexture2D(path);
+    osg::Texture2D* texture = SGLoadTexture2D("moon.png", options.get());
     stateSet->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);
     osg::TexEnv* texEnv = new osg::TexEnv;
     texEnv->setMode(osg::TexEnv::MODULATE);
@@ -105,11 +113,11 @@ SGMoon::build( SGPath path, double moon_size ) {
     blendFunc->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE);
     stateSet->setAttributeAndModes(blendFunc);
 
-//     osg::AlphaFunc* alphaFunc = new osg::AlphaFunc;
-//     alphaFunc->setFunction(osg::AlphaFunc::GREATER);
-//     alphaFunc->setReferenceValue(0.01);
-//     stateSet->setAttributeAndModes(alphaFunc);
-    stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::OFF);
+    osg::AlphaFunc* alphaFunc = new osg::AlphaFunc;
+    alphaFunc->setFunction(osg::AlphaFunc::GREATER);
+    alphaFunc->setReferenceValue(0.01);
+    stateSet->setAttribute(alphaFunc);
+    stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON);
 
     // force a repaint of the moon colors with arbitrary defaults
     repaint( 0.0 );
@@ -161,28 +169,19 @@ bool SGMoon::repaint( double moon_angle ) {
 // declination, offset by our current position (p) so that it appears
 // fixed at a great distance from the viewer.  Also add in an optional
 // rotation (i.e. for the current time of day.)
-bool SGMoon::reposition( const SGVec3f& p, double angle,
-                        double rightAscension, double declination,
+bool SGMoon::reposition( double rightAscension, double declination,
                         double moon_dist )
 {
-    osg::Matrix T1, T2, GST, RA, DEC;
-
-    T1.makeTranslate(p.osg());
-
-    GST.makeRotate(SGD_DEGREES_TO_RADIANS*angle, osg::Vec3(0, 0, -1));
+    osg::Matrix T2, RA, DEC;
 
-    // xglRotatef( ((SGD_RADIANS_TO_DEGREES * rightAscension)- 90.0),
-    //             0.0, 0.0, 1.0);
     RA.makeRotate(rightAscension - 90.0 * SGD_DEGREES_TO_RADIANS,
                   osg::Vec3(0, 0, 1));
 
-    // xglRotatef((SGD_RADIANS_TO_DEGREES * declination), 1.0, 0.0, 0.0);
     DEC.makeRotate(declination, osg::Vec3(1, 0, 0));
 
-    // xglTranslatef(0,moon_dist);
     T2.makeTranslate(osg::Vec3(0, moon_dist, 0));
 
-    moon_transform->setMatrix(T2*DEC*RA*GST*T1);
+    moon_transform->setMatrix(T2*DEC*RA);
 
     return true;
 }