]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/sky/newcloud.cxx
Reduce compiler.h to almost nothing (but it's worth keeping around I think, for
[simgear.git] / simgear / scene / sky / newcloud.cxx
index 2fd119b0d5c9e6c9369dd73eaa88c1c7e257b0fe..d15b456109a90653f194e87b751137b2a2172c63 100644 (file)
@@ -16,7 +16,7 @@
 //
 // 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.
 //
 //
 
 #  include <simgear_config.h>
 #endif
 
+#include <osg/ref_ptr>
+#include <osg/Texture2D>
+
 #include <simgear/compiler.h>
 
 #include <plib/sg.h>
-#include <plib/ssg.h>
 #include <simgear/math/sg_random.h>
 #include <simgear/misc/sg_path.hxx>
 
-#include STL_ALGORITHM
+#include <algorithm>
 #include SG_GLU_H
 
 #include "cloudfield.hxx"
 /*
 */
 
-static ssgTexture *cloudTextures[SGNewCloud::CLTexture_max];
+static osg::ref_ptr<osg::Texture2D> cloudTextures[SGNewCloud::CLTexture_max];
 
 
 bool SGNewCloud::useAnisotropic = true;
 SGBbCache *SGNewCloud::cldCache = 0;
 static bool texturesLoaded = false;
 static float minx, maxx, miny, maxy, minz, maxz;
+static int cloudIdCounter = 1;
 
 float SGNewCloud::nearRadius = 3500.0f;
 bool SGNewCloud::lowQuality = false;
@@ -64,7 +67,7 @@ void SGNewCloud::init(void) {
        pauseLength = 0.0f;
        last_step = -1.0f;
        familly = CLFamilly_nn;
-       cloudId = (int) this;
+       cloudId = ++cloudIdCounter;
        sgSetVec3(center, 0.0f, 0.0f, 0.0f);
        sgSetVec3(cloudpos, 0.0f, 0.0f, 0.0f);
        radius = 0.0f;
@@ -127,13 +130,15 @@ void SGNewCloud::loadTextures(const string &tex_path) {
 
     cloud_path.set(tex_path);
     cloud_path.append("cl_cumulus.rgb");
-    cloudTextures[ CLTexture_cumulus ] = new ssgTexture( cloud_path.str().c_str(), false, false, false );
-    cloudTextures[ CLTexture_cumulus ]->ref();
+    // OSGFIXME
+//     cloudTextures[ CLTexture_cumulus ] = new osg::Texture2D( cloud_path.str().c_str(), false, false, false );
+    cloudTextures[ CLTexture_cumulus ] = new osg::Texture2D;
 
     cloud_path.set(tex_path);
     cloud_path.append("cl_stratus.rgb");
-    cloudTextures[ CLTexture_stratus ] = new ssgTexture( cloud_path.str().c_str(), false, false, false );
-    cloudTextures[ CLTexture_stratus ]->ref();
+    // OSGFIXME
+//     cloudTextures[ CLTexture_stratus ] = new ssgTexture( cloud_path.str().c_str(), false, false, false );
+    cloudTextures[ CLTexture_stratus ] = new osg::Texture2D;
 
 }
 
@@ -243,7 +248,7 @@ void SGNewCloud::addSprite(float x, float y, float z, float r, CLbox_type type,
        sgSubVec3( deltaPos, newSpriteDef.pos, thisBox->pos );
        sgAddVec3( thisBox->center, deltaPos );
 
-       r = r * 0.65f;  // 0.5 * 1.xxx
+       r = r * 0.70f;  // 0.5 * 1.xxx
     if( x - r < minx )
                minx = x - r;
     if( y - r < miny )
@@ -486,7 +491,8 @@ void SGNewCloud::Render3Dcloud( bool drawBB, sgVec3 FakeEyePos, sgVec3 deltaPos,
                // in practice there is no texture switch (atm)
                if( previousTexture != thisTexture ) {
                        previousTexture = thisTexture;
-                       glBindTexture(GL_TEXTURE_2D, cloudTextures[thisTexture]->getHandle());
+                        // OSGFIXME
+//                     glBindTexture(GL_TEXTURE_2D, cloudTextures[thisTexture]->getHandle());
                }
 
                        sgVec3 translate;
@@ -555,23 +561,18 @@ void SGNewCloud::Render3Dcloud( bool drawBB, sgVec3 FakeEyePos, sgVec3 deltaPos,
                        sgVec3 pos;
                        sgSetVec3( pos, translate[SG_X], translate[SG_Z], translate[SG_Y] );
                        sgCopyVec3( translate, pos );
-                       sgNormaliseVec3( translate );
-#if 0
-                       // change view angle when near a sprite
-                       sgVec3 trans={translate[0], translate[2], translate[1]};
-                       float angle = sgScalarProductVec3( SGCloudField::view_vec, trans );
-                       if( fabs(angle) < 0.85f ) {
-                               // view not ok from under
-                               sgSetVec3( translate, -SGCloudField::view_vec[0],-SGCloudField::view_vec[2],-SGCloudField::view_vec[1] );
-//                             sgSetVec3( l0,1,0,0 );
-//                             sgSetVec3( l1,1,0,0 );
-//                             sgSetVec3( l2,1,0,0 );
-//                             sgSetVec3( l3,1,0,0 );
-                       }
-#endif
+                       translate[2] -= FakeEyePos[1];
+//                     sgNormaliseVec3( translate );
+                       float dist_sprite = sgLengthVec3 ( translate );
+                       sgScaleVec3 ( translate, SG_ONE / dist_sprite ) ;
                        sgVec3 x, y, up = {0.0f, 0.0f, 1.0f};
-                       sgVectorProductVec3(x, translate, up);
-                       sgVectorProductVec3(y, x, translate);
+                       if( dist_sprite > 2*r ) {
+                               sgVectorProductVec3(x, translate, up);
+                               sgVectorProductVec3(y, x, translate);
+                       } else {
+                               sgCopyVec3( x, SGCloudField::view_X );
+                               sgCopyVec3( y, SGCloudField::view_Y );
+                       }
                        sgScaleVec3(x, r);
                        sgScaleVec3(y, r);
  
@@ -665,6 +666,8 @@ void SGNewCloud::RenderBB(sgVec3 deltaPos, bool first_time, float dist_center) {
                sgVec3 pos;
                sgSetVec3( pos, translate[SG_X], translate[SG_Z], translate[SG_Y] );
                sgCopyVec3( translate, pos );
+               pos[2] += deltaPos[1];
+
                sgNormaliseVec3( translate );
                sgVec3 x, y, up = {0.0f, 0.0f, 1.0f};
                sgVectorProductVec3(x, translate, up);
@@ -745,6 +748,7 @@ void SGNewCloud::Render(sgVec3 FakeEyePos) {
 
        sgVec3 deltaPos;
        sgCopyVec3( deltaPos, FakeEyePos);
+       deltaPos[1] = 0.0;
     sgSubVec3( dist, center, FakeEyePos);
     float dist_center = sgLengthVec3(dist);
 
@@ -804,7 +808,7 @@ void SGNewCloud::Render(sgVec3 FakeEyePos) {
                                }
                 // draw the newly built BB or an old one
                 glBindTexture(GL_TEXTURE_2D, texID);
-                RenderBB(deltaPos, first_time, dist_center);
+                RenderBB(FakeEyePos, first_time, dist_center);
                        }
        }