]> git.mxchange.org Git - simgear.git/commitdiff
Updates to buildings and trees
authorStuart Buchanan <stuart_d_buchanan@yahoo.co.uk>
Thu, 10 May 2012 22:03:38 +0000 (23:03 +0100)
committerStuart Buchanan <stuart_d_buchanan@yahoo.co.uk>
Thu, 10 May 2012 22:03:38 +0000 (23:03 +0100)
1) Clean up after ourselves - remove memory leak
2) Face buildings the right way

simgear/scene/tgdb/SGBuildingBin.cxx
simgear/scene/tgdb/SGBuildingBin.hxx
simgear/scene/tgdb/TreeBin.cxx
simgear/scene/tgdb/TreeBin.hxx

index dca84aa9d7c03749361f7a5c54cdb5b6be61f5ba..8378a61396801086e288e375273b9f1f9bd38391 100644 (file)
@@ -137,74 +137,74 @@ void addBuildingToLeafGeode(Geode* geode, const SGBuildingBin::Building& buildin
       // BASEMENT
       // This exteds 10m below the main section
       // Front face        
-      v->push_back( osg::Vec3( 0,  cw, -10) * transformMat ); // bottom right
-      v->push_back( osg::Vec3( 0, -cw, -10) * transformMat ); // bottom left
-      v->push_back( osg::Vec3( 0, -cw,   0) * transformMat ); // top left
-      v->push_back( osg::Vec3( 0,  cw,   0) * transformMat ); // top right
+      v->push_back( osg::Vec3( 0, -cw, -10) * transformMat ); // bottom right
+      v->push_back( osg::Vec3( 0,  cw, -10) * transformMat ); // bottom left
+      v->push_back( osg::Vec3( 0,  cw,   0) * transformMat ); // top left
+      v->push_back( osg::Vec3( 0, -cw,   0) * transformMat ); // top right
       
       for (int i=0; i<4; ++i)
-        n->push_back( osg::Vec3(-1, 0, 0) * rotationMat ); // normal
+        n->push_back( osg::Vec3(1, 0, 0) * rotationMat ); // normal
       
       // Left face
-      v->push_back( osg::Vec3(  0, -cw, -10) * transformMat ); // bottom right
-      v->push_back( osg::Vec3( cd, -cw, -10) * transformMat ); // bottom left
-      v->push_back( osg::Vec3( cd, -cw,   0) * transformMat ); // top left
-      v->push_back( osg::Vec3(  0, -cw,   0) * transformMat ); // top right
+      v->push_back( osg::Vec3( -cd, -cw, -10) * transformMat ); // bottom right
+      v->push_back( osg::Vec3(   0, -cw, -10) * transformMat ); // bottom left
+      v->push_back( osg::Vec3(   0, -cw,   0) * transformMat ); // top left
+      v->push_back( osg::Vec3( -cd, -cw,   0) * transformMat ); // top right
 
       for (int i=0; i<4; ++i)
         n->push_back( osg::Vec3(0, -1, 0) * rotationMat ); // normal
 
       // Back face
-      v->push_back( osg::Vec3( cd, -cw, -10) * transformMat ); // bottom right
-      v->push_back( osg::Vec3( cd,  cw, -10) * transformMat ); // bottom left
-      v->push_back( osg::Vec3( cd,  cw,   0) * transformMat ); // top left
-      v->push_back( osg::Vec3( cd, -cw,   0) * transformMat ); // top right
+      v->push_back( osg::Vec3( -cd,  cw, -10) * transformMat ); // bottom right
+      v->push_back( osg::Vec3( -cd, -cw, -10) * transformMat ); // bottom left
+      v->push_back( osg::Vec3( -cd, -cw,   0) * transformMat ); // top left
+      v->push_back( osg::Vec3( -cd,  cw,   0) * transformMat ); // top right
       
       for (int i=0; i<4; ++i)
-        n->push_back( osg::Vec3(1, 0, 0) * rotationMat ); // normal
+        n->push_back( osg::Vec3(-1, 0, 0) * rotationMat ); // normal
       
       // Right face
-      v->push_back( osg::Vec3( cd, cw, -10) * transformMat ); // bottom right
-      v->push_back( osg::Vec3(  0, cw, -10) * transformMat ); // bottom left
-      v->push_back( osg::Vec3(  0, cw,   0) * transformMat ); // top left
-      v->push_back( osg::Vec3( cd, cw,   0) * transformMat ); // top right
+      v->push_back( osg::Vec3(   0, cw, -10) * transformMat ); // bottom right
+      v->push_back( osg::Vec3( -cd, cw, -10) * transformMat ); // bottom left
+      v->push_back( osg::Vec3( -cd, cw,   0) * transformMat ); // top left
+      v->push_back( osg::Vec3(   0, cw,   0) * transformMat ); // top right
 
       for (int i=0; i<4; ++i)
         n->push_back( osg::Vec3(0, 1, 0) * rotationMat ); // normal      
       
       // MAIN BODY
       // Front face        
-      v->push_back( osg::Vec3( 0,  cw,  0) * transformMat ); // bottom right
-      v->push_back( osg::Vec3( 0, -cw,  0) * transformMat ); // bottom left
-      v->push_back( osg::Vec3( 0, -cw, ch) * transformMat ); // top left
-      v->push_back( osg::Vec3( 0,  cw, ch) * transformMat ); // top right
+      v->push_back( osg::Vec3( 0, -cw,  0) * transformMat ); // bottom right
+      v->push_back( osg::Vec3( 0,  cw,  0) * transformMat ); // bottom left
+      v->push_back( osg::Vec3( 0,  cw, ch) * transformMat ); // top left
+      v->push_back( osg::Vec3( 0, -cw, ch) * transformMat ); // top right
       
       for (int i=0; i<4; ++i)
-        n->push_back( osg::Vec3(-1, 0, 0) * rotationMat ); // normal
+        n->push_back( osg::Vec3(1, 0, 0) * rotationMat ); // normal
       
       // Left face
-      v->push_back( osg::Vec3(  0, -cw,  0) * transformMat ); // bottom right
-      v->push_back( osg::Vec3( cd, -cw,  0) * transformMat ); // bottom left
-      v->push_back( osg::Vec3( cd, -cw, ch) * transformMat ); // top left
-      v->push_back( osg::Vec3(  0, -cw, ch) * transformMat ); // top right
+      v->push_back( osg::Vec3( -cd, -cw,  0) * transformMat ); // bottom right
+      v->push_back( osg::Vec3(   0, -cw,  0) * transformMat ); // bottom left
+      v->push_back( osg::Vec3(   0, -cw, ch) * transformMat ); // top left
+      v->push_back( osg::Vec3( -cd, -cw, ch) * transformMat ); // top right
 
       for (int i=0; i<4; ++i)
         n->push_back( osg::Vec3(0, -1, 0) * rotationMat ); // normal
 
       // Back face
-      v->push_back( osg::Vec3( cd, -cw,  0) * transformMat ); // bottom right
-      v->push_back( osg::Vec3( cd,  cw,  0) * transformMat ); // bottom left
-      v->push_back( osg::Vec3( cd,  cw, ch) * transformMat ); // top left
-      v->push_back( osg::Vec3( cd, -cw, ch) * transformMat ); // top right
+      v->push_back( osg::Vec3( -cd,  cw,  0) * transformMat ); // bottom right
+      v->push_back( osg::Vec3( -cd, -cw,  0) * transformMat ); // bottom left
+      v->push_back( osg::Vec3( -cd, -cw, ch) * transformMat ); // top left
+      v->push_back( osg::Vec3( -cd,  cw, ch) * transformMat ); // top right
       
       for (int i=0; i<4; ++i)
-        n->push_back( osg::Vec3(1, 0, 0) * rotationMat ); // normal
+        n->push_back( osg::Vec3(-1, 0, 0) * rotationMat ); // normal
       
       // Right face
-      v->push_back( osg::Vec3( cd, cw,  0) * transformMat ); // bottom right
-      v->push_back( osg::Vec3(  0, cw,  0) * transformMat ); // bottom left
-      v->push_back( osg::Vec3(  0, cw, ch) * transformMat ); // top left
-      v->push_back( osg::Vec3( cd, cw, ch) * transformMat ); // top right
+      v->push_back( osg::Vec3(   0, cw,  0) * transformMat ); // bottom right
+      v->push_back( osg::Vec3( -cd, cw,  0) * transformMat ); // bottom left
+      v->push_back( osg::Vec3( -cd, cw, ch) * transformMat ); // top left
+      v->push_back( osg::Vec3(   0, cw, ch) * transformMat ); // top right
 
       for (int i=0; i<4; ++i)
         n->push_back( osg::Vec3(0, 1, 0) * rotationMat ); // normal
@@ -213,46 +213,46 @@ void addBuildingToLeafGeode(Geode* geode, const SGBuildingBin::Building& buildin
       if (building.pitched) {      
         
         // Front pitched roof
-        v->push_back( osg::Vec3(     0,  cw,   ch) * transformMat ); // bottom right
-        v->push_back( osg::Vec3(     0, -cw,   ch) * transformMat ); // bottom left
-        v->push_back( osg::Vec3(0.5*cd, -cw, ch+3) * transformMat ); // top left
-        v->push_back( osg::Vec3(0.5*cd,  cw, ch+3) * transformMat ); // top right
+        v->push_back( osg::Vec3(    0, -cw,   ch) * transformMat ); // bottom right
+        v->push_back( osg::Vec3(    0,  cw,   ch) * transformMat ); // bottom left
+        v->push_back( osg::Vec3(-0.5*cd,  cw, ch+3) * transformMat ); // top left
+        v->push_back( osg::Vec3(-0.5*cd, -cw, ch+3) * transformMat ); // top right
         
         for (int i=0; i<4; ++i)
-          n->push_back( osg::Vec3(-0.707, 0, 0.707) * rotationMat ); // normal
+          n->push_back( osg::Vec3(0.707, 0, 0.707) * rotationMat ); // normal
         
         // Left pitched roof
-        v->push_back( osg::Vec3(     0, -cw,   ch) * transformMat ); // bottom right
-        v->push_back( osg::Vec3(    cd, -cw,   ch) * transformMat ); // bottom left
-        v->push_back( osg::Vec3(0.5*cd, -cw, ch+3) * transformMat ); // top left
-        v->push_back( osg::Vec3(0.5*cd, -cw, ch+3) * transformMat ); // top right
+        v->push_back( osg::Vec3(    -cd, -cw,   ch) * transformMat ); // bottom right
+        v->push_back( osg::Vec3(      0, -cw,   ch) * transformMat ); // bottom left
+        v->push_back( osg::Vec3(-0.5*cd, -cw, ch+3) * transformMat ); // top left
+        v->push_back( osg::Vec3(-0.5*cd, -cw, ch+3) * transformMat ); // top right
         
         for (int i=0; i<4; ++i)
           n->push_back( osg::Vec3(0, -1, 0) * rotationMat ); // normal
 
         // Back pitched roof
-        v->push_back( osg::Vec3(    cd, -cw,   ch) * transformMat ); // bottom right
-        v->push_back( osg::Vec3(    cd,  cw,   ch) * transformMat ); // bottom left
-        v->push_back( osg::Vec3(0.5*cd,  cw, ch+3) * transformMat ); // top left
-        v->push_back( osg::Vec3(0.5*cd, -cw, ch+3) * transformMat ); // top right
+        v->push_back( osg::Vec3(    -cd,  cw,   ch) * transformMat ); // bottom right
+        v->push_back( osg::Vec3(    -cd, -cw,   ch) * transformMat ); // bottom left
+        v->push_back( osg::Vec3(-0.5*cd, -cw, ch+3) * transformMat ); // top left
+        v->push_back( osg::Vec3(-0.5*cd,  cw, ch+3) * transformMat ); // top right
         
         for (int i=0; i<4; ++i)
-          n->push_back( osg::Vec3(0.707, 0, 0.707) * rotationMat ); // normal      
+          n->push_back( osg::Vec3(-0.707, 0, 0.707) * rotationMat ); // normal      
 
         // Right pitched roof
-        v->push_back( osg::Vec3(    cd, cw,   ch) * transformMat ); // bottom right
-        v->push_back( osg::Vec3(     0, cw,   ch) * transformMat ); // bottom left
-        v->push_back( osg::Vec3(0.5*cd, cw, ch+3) * transformMat ); // top left
-        v->push_back( osg::Vec3(0.5*cd, cw, ch+3) * transformMat ); // top right
+        v->push_back( osg::Vec3(      0, cw,   ch) * transformMat ); // bottom right
+        v->push_back( osg::Vec3(    -cd, cw,   ch) * transformMat ); // bottom left
+        v->push_back( osg::Vec3(-0.5*cd, cw, ch+3) * transformMat ); // top left
+        v->push_back( osg::Vec3(-0.5*cd, cw, ch+3) * transformMat ); // top right
         
         for (int i=0; i<4; ++i)
           n->push_back( osg::Vec3(0, 1, 0) * rotationMat ); // normal
       } else {      
         // Top face
-        v->push_back( osg::Vec3(  0,  cw, ch) * transformMat ); // bottom right
-        v->push_back( osg::Vec3(  0, -cw, ch) * transformMat ); // bottom left
-        v->push_back( osg::Vec3( cd, -cw, ch) * transformMat ); // top left
-        v->push_back( osg::Vec3( cd,  cw, ch) * transformMat ); // top right
+        v->push_back( osg::Vec3(   0, -cw, ch) * transformMat ); // bottom right
+        v->push_back( osg::Vec3(   0,  cw, ch) * transformMat ); // bottom left
+        v->push_back( osg::Vec3( -cd,  cw, ch) * transformMat ); // top left
+        v->push_back( osg::Vec3( -cd, -cw, ch) * transformMat ); // top right
         
         for (int i=0; i<4; ++i)
           n->push_back( osg::Vec3( 0, 0, 1) * rotationMat ); // normal
@@ -270,8 +270,8 @@ void addBuildingToLeafGeode(Geode* geode, const SGBuildingBin::Building& buildin
         float top_y = base_y + 16.0 * (float) building.floors / 1024.0;
         float left_x = 32.0 / 1024.0 * round((float) building.width / 6.0f);
         float right_x = 0.0f;
-        float front_x = 384.0/1024.0 + 32.0 / 1024.0 * round((float) building.depth/ 6.0f);
-        float back_x = 384.0/1024.0;
+        float front_x = 384.0/1024.0;
+        float back_x = 384.0/1024.0 + 32.0 / 1024.0 * round((float) building.depth/ 6.0f);
 
         // BASEMENT - uses the baseline texture
         for (unsigned int i = 0; i < 16; i++) {          
@@ -308,8 +308,8 @@ void addBuildingToLeafGeode(Geode* geode, const SGBuildingBin::Building& buildin
           top_y = base_y + 16.0 * 3.0 / 1024.0;     
           left_x = 512/1024.0 + 32.0 / 1024.0 * round(building.width / 6.0f);
           right_x = 512/1024.0;
-          front_x = 512.0/1024.0;
-          back_x = 480.0/1024.0;
+          front_x = 480.0/1024.0;
+          back_x = 512.0/1024.0;
           
           // Front
           t->push_back( osg::Vec2( right_x, base_y) ); // bottom right
@@ -391,8 +391,9 @@ void addBuildingToLeafGeode(Geode* geode, const SGBuildingBin::Building& buildin
         if (building.pitched) {      
           base_y = 288.0/1024.0;
           top_y = 576.0/1024.0;
-          left_x = 1.0;
-          right_x = 960.0/1024.0;
+          left_x = 960.0/1024.0;
+          right_x = 1.0;
+          
           // Front
           t->push_back( osg::Vec2( right_x, base_y) ); // bottom right
           t->push_back( osg::Vec2( left_x,  base_y) ); // bottom left
@@ -420,9 +421,8 @@ void addBuildingToLeafGeode(Geode* geode, const SGBuildingBin::Building& buildin
           // Flat roof
           base_y = 416/1024.0;
           top_y = 576.0/1024.0;
-          left_x = (column + 1)* 192.0 /1024.0;
-          right_x = column * 192.0 /1024.0;
-          //right_x = left_x + 32.0 / 1024.0 * 6.0;
+          left_x = column * 192.0 /1024.0;
+          right_x = (column + 1)* 192.0 /1024.0;
           
           t->push_back( osg::Vec2( right_x, base_y) ); // bottom right
           t->push_back( osg::Vec2( left_x,  base_y) ); // bottom left
@@ -645,9 +645,12 @@ osg::Group* createRandomBuildings(SGBuildingBinList buildings, const osg::Matrix
         
         ref_ptr<Group> group = quadbuilding.getRoot();
         
-        mt->addChild(group);        
+        mt->addChild(group);  
+        delete bin;      
     }
     
+    buildings.clear();
+    
     return mt;
 }
 
index 3dfb3c38b7258a590a76153adeb0ba71db3c0817..1fc64cbd72d4d9781ee59a4e9e60ea241160c528 100644 (file)
@@ -100,6 +100,10 @@ public:
   { return buildings.size(); }
   const Building& getBuilding(unsigned i) const
   { return buildings[i]; }  
+  
+  ~SGBuildingBin() {
+    buildings.clear();    
+  }
 };
 
 // List of buildings
index b0ca2e02b31488ee7b7e453061cbb878af653ade..15085d6dcef9fd1a16748c04080deea0a80ac809 100644 (file)
@@ -337,8 +337,12 @@ osg::Group* createForest(SGTreeBinList& forestList, const osg::Matrix& transform
 
         for (size_t i = 0; i < group->getNumChildren(); ++i)
             mt->addChild(group->getChild(i));
+            
+        delete forest;
     }
     
+    forestList.clear();
+    
     return mt;
 }
 
index d49e2fbe33c25e1492f6688fb98f8975b05acab1..9b9c3bc91a2e5466bce318d7ed2026b655993a57 100644 (file)
@@ -60,9 +60,12 @@ public:
     const Tree& getTree(unsigned i) const
     { return _trees[i]; }
     TreeList _trees;
+    
+    ~TreeBin() {
+      _trees.clear();
+    }    
 };
 
-
 typedef std::list<TreeBin*> SGTreeBinList;
 
 osg::Group* createForest(SGTreeBinList& forestList, const osg::Matrix& transform,