]> git.mxchange.org Git - simgear.git/commitdiff
Norman's most recent 3d clouds code tweaks.
authorcurt <curt>
Wed, 18 Sep 2002 14:24:19 +0000 (14:24 +0000)
committercurt <curt>
Wed, 18 Sep 2002 14:24:19 +0000 (14:24 +0000)
13 files changed:
configure.ac
simgear/scene/sky/clouds3d/Makefile.am
simgear/scene/sky/clouds3d/SkyArchive.cpp
simgear/scene/sky/clouds3d/SkyCloud.cpp
simgear/scene/sky/clouds3d/SkyCloud.hpp
simgear/scene/sky/clouds3d/SkyContext.cpp
simgear/scene/sky/clouds3d/SkyContext.hpp
simgear/scene/sky/clouds3d/SkyLight.cpp
simgear/scene/sky/clouds3d/SkyRenderableInstanceCloud.cpp
simgear/scene/sky/clouds3d/SkyRenderableInstanceGroup.cpp
simgear/scene/sky/clouds3d/SkySceneLoader.cpp
simgear/scene/sky/clouds3d/SkySceneManager.cpp
simgear/scene/sky/clouds3d/SkyTextureManager.cpp

index 037ef77fb92212c81afea3a627c75278ebca7656..d6e8c80e6de9b5bc26b421eb397b4c5d0830ff48 100644 (file)
@@ -167,6 +167,8 @@ fi
 
 dnl check for OpenGL related libraries
 
+AM_CONDITIONAL(EXTGL_NEEDED, test "x$ac_cv_header_windows_h" = "xyes")
+
 if test "x$HOSTTYPE" = "xmacintosh" ; then
     dnl Macintosh OSX
     LIBS="$LIBS -framework OpenGL -framework GLUT"
index 9b492a4ad7d4d05d458e1faad333dcd0d580e0dd..566f3ee701e09c98abcc7ad7a25d3f6bfaf92ae4 100644 (file)
@@ -1,5 +1,12 @@
 includedir = @includedir@/sky/clouds3d
 
+EXTRA_DIST = extlg.c
+if EXTGL_NEEDED
+  EXTGL_SOURCE = extgl.c
+else
+  EXTGL_SOURCE = 
+endif
+
 lib_LIBRARIES = libsgclouds3d.a
 
 include_HEADERS = \
@@ -7,6 +14,7 @@ include_HEADERS = \
        SkyUtil.hpp
 
 libsgclouds3d_a_SOURCES = \
+        $(EXTRA_SOURCE) \
        vec3fv.cpp \
        mat16fv.cpp \
        tri.cpp \
index 30344f374c03bc3da25f08ce4bdcacd6950302a7..4b52e1998d21bb382746504e4bffd654e889ca64 100644 (file)
@@ -963,6 +963,10 @@ SKYRESULT SkyArchive::Load(const char* pFileName)
     FAIL_RETURN_MSG(SKYRESULT_FAIL, "Error: SkyArchive::Load(): file name is NULL.");
        }
   FILE* pSrcFile = NULL;
+  
+  char buf[512];
+  sprintf(buf,"SkyArchive::Load(%s)",pFileName);
+  SkyTrace(buf);
   if (NULL == (pSrcFile = fopen(pFileName, "rb"))) // file opened successfully   
   {
     SkyTrace("Error: SkyArchive::Load(): failed to open file for reading.");
index cf3574f8dac45573fd865c89be264285d9f3874c..48275bb321092a862e8818f06267a7032b1f7f51 100644 (file)
@@ -225,7 +225,7 @@ SKYRESULT SkyCloud::Display(const Camera &camera, SkyRenderableInstance *pInstan
     color = p->GetBaseColor();
     
     if (_bUsePhaseFunction) // use the phase function for anisotropic scattering.
-    {\r 
+    { 
       eyeDir = cam.Orig;
       eyeDir -= p->GetPosition();     
       eyeDir.Normalize();
@@ -629,6 +629,78 @@ SkyMinMaxBox* SkyCloud::CopyBoundingVolume() const
  * 
  * If @a rScale does not equal 1.0, then the cloud is scaled by an amount rScale.
  */ 
+SKYRESULT SkyCloud::Load(const SkyArchive &archive,
+                         const sgVec4 *mat,
+                         float rScale /* = 1.0f */, 
+                         bool bLocal /* = false */)
+{
+    unsigned int iNumParticles;
+    Vec3f vecCenter = Vec3f::ZERO;
+  //Vec3f vecCenter;
+  //float rRadius;
+  //archive.FindVec3f("CldCenter", &vecCenter);
+  //archive.FindFloat32("CldRadius", &rRadius);
+
+  //_boundingBox.SetMin(vecCenter - Vec3f(rRadius, rRadius, rRadius));
+  //_boundingBox.SetMax(vecCenter + Vec3f(rRadius, rRadius, rRadius));
+
+    archive.FindUInt32("CldNumParticles", &iNumParticles);
+    if (!bLocal)
+        archive.FindVec3f("CldCenter", &vecCenter);
+
+    Vec3f *pParticlePositions = new Vec3f[iNumParticles];
+    float *pParticleRadii     = new float[iNumParticles];
+    Vec4f *pParticleColors    = new Vec4f[iNumParticles];
+
+    unsigned int iNumBytes;
+    archive.FindData("CldParticlePositions", ANY_TYPE, (void**const)&pParticlePositions, &iNumBytes);
+    archive.FindData("CldParticleRadii",     ANY_TYPE, (void**const)&pParticleRadii,     &iNumBytes);
+    archive.FindData("CldParticleColors",    ANY_TYPE, (void**const)&pParticleColors,    &iNumBytes);
+
+    for (unsigned int i = 0; i < iNumParticles; ++i)
+    {
+        SkyCloudParticle *pParticle = new SkyCloudParticle((pParticlePositions[i] + vecCenter) * rScale,
+            pParticleRadii[i] * rScale,
+            pParticleColors[i]);
+        _boundingBox.AddPoint(pParticle->GetPosition());
+
+        _particles.push_back(pParticle);
+    }
+  // this is just a bad hack to align cloud field from skyworks with local horizon at KSFO
+  // this "almost" works not quite the right solution okay to get some up and running
+  // we need to develop our own scheme for loading and positioning clouds
+    Mat33f rot_mat;
+    Vec3f  moveit;
+
+    rot_mat.Set( 1, 0, 0,
+                 0, 0, -1,
+                 0, 1, 0);
+  // flip the y and z axis, clouds now sit in the x-y plane
+    Rotate( rot_mat ); 
+//  rot_mat.Set(mat[0][0], mat[0][1],mat[0][2],
+//              mat[1][0], mat[1][1],mat[1][2],
+//              mat[2][0], mat[2][1],mat[2][2] );
+   // adjust for lon af KSFO plus              -122.357                                 
+//  rot_mat.Set( -0.84473f, 0.53519f, 0.0f,
+//                                              -0.53519f, -0.84473f, 0.0f,
+//                                              0.0f, 0.0f, 1.0f);
+
+  //Rotate( rot_mat );
+
+   // and about x for latitude 37.6135
+//  rot_mat.Set( 1.0f, 0.0, 0.0f,
+//                                              0.0f, 0.7921f, -0.6103f,
+//                                              0.0f, 0.6103f, 0.7921f);               
+
+//  Rotate( rot_mat );
+
+    moveit.Set( 1000.0, 0.0, 4050.0  );
+
+    Translate( moveit );
+
+    return SKYRESULT_OK;
+}
+
 SKYRESULT SkyCloud::Load(const SkyArchive &archive, 
                          float rScale /* = 1.0f */, 
                          bool bLocal /* = false */)
index 24b2d3a69d9ffb864d2e883c0dca0303ff9c0be7..de7332c871a448f7f28b8228c96241007204e70e 100644 (file)
@@ -33,6 +33,8 @@
 #include "SkyArchive.hpp"
 #include "mat33.hpp"
 
+#include <plib/sg.h>
+
 class SkyMaterial;
 class SkyLight;
 class SkyRenderableInstance;
@@ -97,6 +99,8 @@ public:
   
   SKYRESULT                   Save(SkyArchive &archive) const;
   SKYRESULT                   Load(const SkyArchive &archive, float rScale = 1.0f, bool bLocal = false);
+  SKYRESULT                   Load(const SkyArchive &archive, const sgVec4 *mat,
+                                   float rScale = 1.0f, bool bLocal = false);
   
   void                        Rotate(const Mat33f& rot);
   void                        Translate(const Vec3f& trans);
index b8727f0747fe00f1c4482c3c881152f805e09e33..499ed478f47f26d39ab8de09f85da6da53c6f021 100644 (file)
  * 
  * Graphics Context Interface.  Initializes GL extensions, etc.
  */
+
+#ifdef HAVE_CONFIG_H
+#  include <simgear_config.h>
+#endif
+
 #include <GL/glut.h>
+#ifndef WIN32
 #include <GL/glx.h>
+#endif
 
 //#include "extgl.h"
 
@@ -46,7 +53,7 @@ SkyContext::SkyContext()
   // materials and structure classes
   AddCurrentGLContext();
   // Initialize all the extensions and load the functions - JW (file is extgl.c)
-  #ifdef _WIN32
+  #ifdef WIN32
   glInitialize();
   InitializeExtension("GL_ARB_multitexture");
   #endif
@@ -122,7 +129,11 @@ SKYRESULT SkyContext::InitializeExtension(const char *pExtensionName)
 */ 
 SkyMaterial* SkyContext::GetCurrentMaterial()
 {
-  ContextMaterialIterator cmi = _currentMaterials.find(glXGetCurrentContext());
+#ifdef WIN32
+    ContextMaterialIterator cmi = _currentMaterials.find(wglGetCurrentContext());
+#else
+    ContextMaterialIterator cmi = _currentMaterials.find(glXGetCurrentContext());
+#endif
   if (_currentMaterials.end() != cmi)
     return cmi->second;
   else
@@ -146,7 +157,11 @@ SkyMaterial* SkyContext::GetCurrentMaterial()
  */ 
 SkyTextureState* SkyContext::GetCurrentTextureState()
 {
-  ContextTextureStateIterator ctsi = _currentTextureState.find(glXGetCurrentContext());
+#ifdef WIN32
+    ContextTextureStateIterator ctsi = _currentTextureState.find(wglGetCurrentContext());
+#else
+    ContextTextureStateIterator ctsi = _currentTextureState.find(glXGetCurrentContext());
+#endif
   if (_currentTextureState.end() != ctsi)
     return ctsi->second;
   else
@@ -169,14 +184,21 @@ SkyTextureState* SkyContext::GetCurrentTextureState()
  */ 
 SKYRESULT SkyContext::AddCurrentGLContext()
 {
-  SkyMaterial *pCurrentMaterial = new SkyMaterial;
-  _currentMaterials.insert(std::make_pair(glXGetCurrentContext(), pCurrentMaterial));
-  SkyTextureState *pCurrentTS = new SkyTextureState;
-  _currentTextureState.insert(std::make_pair(glXGetCurrentContext() , pCurrentTS));
-  return SKYRESULT_OK;
-}
+    SkyMaterial *pCurrentMaterial = new SkyMaterial;
+#ifdef WIN32
+    _currentMaterials.insert(std::make_pair(wglGetCurrentContext(), pCurrentMaterial));
+#else
+    _currentMaterials.insert(std::make_pair(glXGetCurrentContext(), pCurrentMaterial));
+#endif
 
+    SkyTextureState *pCurrentTS = new SkyTextureState;
+#ifdef WIN32
+    _currentTextureState.insert(std::make_pair(wglGetCurrentContext() , pCurrentTS));
+#else
+    _currentTextureState.insert(std::make_pair(glXGetCurrentContext() , pCurrentTS));
+#endif
+    return SKYRESULT_OK;
+}
 
 //------------------------------------------------------------------------------
 // Function              : SkyContext::Register
index fcf0d18f9bfbf97a5cbff80537beb8b656ae7748..160906fffdb3e2341c31b49191a5f33d4a3c07e5 100644 (file)
 #ifndef __SKYCONTEXT_HPP__
 #define __SKYCONTEXT_HPP__
 
+#ifdef HAVE_CONFIG_H
+#  include <simgear_config.h>
+#endif
+
 // warning for truncation of template name for browse info
-#pragma warning( disable : 4786)
+// #pragma warning( disable : 4786)
 
 #include "SkySingleton.hpp"
 
 
-#ifdef _WIN32
-#include "extgl.h"
-#endif
-
 #include <list>
 #include <map>
 #include <algorithm>
 
-//  ifdef to replace windows stuff for handles-JW
+#ifdef WIN32
+# include "extgl.h"
+#else
 typedef void *HANDLE;
 typedef HANDLE *PHANDLE;
 #define DECLARE_HANDLE(n)  typedef HANDLE n
-
 DECLARE_HANDLE(HGLRC);
-// end of ifdef
+#endif
 
 class SkyContext;
 class SkyMaterial;
index 0c0ca0aac3ed6776fcf3502a35f9486bbd94995c..6281da8e42379afb8613502b045a4093410ca24a 100644 (file)
  * 
  * Implementation of a class that maintains the state and operation of a light.
  */
-// #pragma warning( disable : 4786)
+
+#ifdef HAVE_CONFIG_H
+#  include <simgear_config.h>
+#endif
+
+#ifdef WIN32
+# ifdef _MSC_VER
+#  pragma warning( disable : 4786)
+# endif
+# include "extgl.h"
+#endif
 
 #include "SkyLight.hpp"
 #include "SkyMaterial.hpp"
index b83f0f12dd30248e812067b058957ae3312c78e7..df4650e1c022cb9f97c9dab6dee0e58f7a083f5e 100644 (file)
@@ -238,7 +238,7 @@ SKYRESULT SkyRenderableInstanceCloud::Display(bool bDisplayFrontOfSplit /* = fal
     FAIL_RETURN(DisplayWithoutImpostor(Camera::Camera()));
   }
   else
-  {\r//cout << "Using impostor image\n";
+  {//cout << "Using impostor image\n";
     if (!_pBackTexture || (bDisplayFrontOfSplit && !_pFrontTexture))
       FAIL_RETURN_MSG(SKYRESULT_FAIL, "SkyRenderableInstanceCloud::Display(): missing texture!");
 
@@ -268,7 +268,7 @@ SKYRESULT SkyRenderableInstanceCloud::Display(bool bDisplayFrontOfSplit /* = fal
     Vec3f x, y, z;
     
     if (!_bScreenImpostor)
-    {\r//cout << "Outside the cloud\n";
+    {//cout << "Outside the cloud\n";
       z  =    _vecPosition; 
       z -=    _impostorCam.Orig;
       z.Normalize();
index 2fa497a82f348f70d82ad1a14a216204f891bf8a..0764ddcfa464fcdf013dd755c9c87ab5e3a70d5d 100644 (file)
@@ -115,7 +115,7 @@ SKYRESULT SkyRenderableInstanceGroup::Display()
   {
     FAIL_RETURN((*ii)->Display());
   }
-\r***/
+***/
   _pObjectSpaceBV->Display();
 
   glMatrixMode(GL_MODELVIEW);
index ad9af54671ab519c6c31bc0c5aecd63c0f71792d..356a8de50fd1343190e74c7688a0b334b74a283a 100644 (file)
@@ -102,15 +102,21 @@ SkySceneLoader::~SkySceneLoader()
 bool SkySceneLoader::Load(std::string filename)
 { 
   SkyArchive archive;
+  cout << "SkySceneLoader::Load( " << filename << " )" << endl;
   if (SKYFAILED(archive.Load(filename.c_str()))) {
        cout << "Archive file not found\n";
-    return false; }
+    return false;
+  }
   char *pFilename;
   
   // Need to create the managers
+  cout << "GraphicsContext::Instantiate();" << endl;
   GraphicsContext::Instantiate();
+  cout << "  TextureManager::Instantiate();" << endl;
   TextureManager::Instantiate();
+  cout << "  DynamicTextureManager::Instantiate();" << endl;
   DynamicTextureManager::Instantiate();
+  cout << "  SceneManager::Instantiate();" << endl;
   SceneManager::Instantiate();
 
   unsigned int iNumFiles;
@@ -118,7 +124,7 @@ bool SkySceneLoader::Load(std::string filename)
   {
     for (unsigned int i = 0; i < iNumFiles; ++i)
     {
-      FAIL_RETURN(archive.FindString("CloudFile", &pFilename, i));\r  
+      FAIL_RETURN(archive.FindString("CloudFile", &pFilename, i));  
       float rScale = 1.0;
       FAIL_RETURN(archive.FindFloat32("CloudScale", &rScale, i));
       rScale = 30.0;
index 26af872b6c01281c8f64b7a1702e4c03151a358e..45316f959330f94ff4d184c327e476bc814664e4 100644 (file)
@@ -47,7 +47,7 @@
  */ 
 SkySceneManager::SkySceneManager()
 : /*_pSkyBox(NULL),
-  _pTerrain(NULL),\r*/
+  _pTerrain(NULL),*/
   _bDrawLights(false),
   _bDrawTree(false),
   _bReshadeClouds(true)
@@ -408,7 +408,7 @@ SKYRESULT SkySceneManager::Display( const Camera &cam )
     //li->second->Display();
   }
  
-  //if (_bDrawTree)\r// force the issue and draw
+  //if (_bDrawTree)// force the issue and draw
     //_VisualizeCloudBVTree(cam, _cloudBVTree.GetRoot());
     
   glLineWidth(2.0);
@@ -516,7 +516,7 @@ SKYRESULT SkySceneManager::LoadClouds(SkyArchive& cloudArchive, float rScale /*
   SkyArchive subArchive;
        //iNumClouds = 5;  //set this value to reduce cloud field for debugging
   for (int i = 0; i < iNumClouds; ++i)
-  {\rprintf("Loading # %d of %d clouds\n", i+1, iNumClouds);
+  {printf("Loading # %d of %d clouds\n", i+1, iNumClouds);
     cloudArchive.FindArchive("Cloud", &subArchive, i);
     SkyCloud *pCloud = new SkyCloud();
     pCloud->Load(subArchive, rScale);
@@ -596,7 +596,7 @@ void SkySceneManager::_ViewFrustumCullClouds(const Camera& cam, const CloudBVTre
   int i;
   int iResult = CamMinMaxBoxOverlap(&cam, pNode->GetNodeBV().GetMin(), pNode->GetNodeBV().GetMax());
   
-\r //iResult = COMPLETEIN; // just a hack to force the issue
+ //iResult = COMPLETEIN; // just a hack to force the issue
   if (COMPLETEIN == iResult)
   {
     // trivially add all instances 
index 92f017973e8e3ae39b46eb6ec3b8f6589d917af3..1844a9904d117a91f82682de7d8001b10a83de1a 100644 (file)
@@ -214,7 +214,7 @@ SKYRESULT SkyTextureManager::Clone2DTexture(const string &filename,
     IMAGE_TGA
   };
   ImageType eType;
-\r/****
+/****
   // first get the image type from its extension.
   if (filename.find(".tga") != string.npos || filename.find(".TGA") != string.npos)
     eType = IMAGE_TGA;
@@ -222,7 +222,7 @@ SKYRESULT SkyTextureManager::Clone2DTexture(const string &filename,
     eType = IMAGE_PPM;
   else 
     FAIL_RETURN_MSG(SKYRESULT_FAIL, "SkyTextureManager error: invalid image format");
-  \r****/
+  ****/
   // first try the filename sent in in case it includes a path.
   //if (FileUtils::FileExists(filename.c_str()))
   //{
@@ -239,7 +239,7 @@ SKYRESULT SkyTextureManager::Clone2DTexture(const string &filename,
       break;
     default:
       break;
-    }\r*/
+    }*/
     
   //}
   
@@ -274,7 +274,7 @@ SKYRESULT SkyTextureManager::Clone2DTexture(const string &filename,
           break;
         default:
           break;
-        }\r*/
+        }*/
         
         //if (pImageData)
           //break;