]> git.mxchange.org Git - simgear.git/commitdiff
Limit number of random objects per triangle
authorStuart Buchanan <stuart_d_buchanan@yahoo.co.uk>
Fri, 7 Nov 2014 22:22:55 +0000 (22:22 +0000)
committerStuart Buchanan <stuart_d_buchanan@yahoo.co.uk>
Fri, 7 Nov 2014 22:22:55 +0000 (22:22 +0000)
simgear/scene/tgdb/SGTexturedTriangleBin.hxx

index 67b8e98025d985841bf1c5ccbebeb0f71911c729..0b96a1fff3dd3ffe8ba418643bb5ea4b9285e206 100644 (file)
@@ -22,6 +22,8 @@
 #ifndef SG_TEXTURED_TRIANGLE_BIN_HXX
 #define SG_TEXTURED_TRIANGLE_BIN_HXX
 
+#define MAX_RANDOM_OBJECTS 100.0
+
 #include <osg/Array>
 #include <osg/Geometry>
 #include <osg/PrimitiveSet>
@@ -291,8 +293,8 @@ public:
                         osg::Texture2D* object_mask,
                         std::vector<std::pair<SGVec3f, float> >& points)
   {
-    unsigned num = getNumTriangles();
-    for (unsigned i = 0; i < num; ++i) {
+    unsigned numtriangles = getNumTriangles();
+    for (unsigned i = 0; i < numtriangles; ++i) {
       triangle_ref triangleRef = getTriangleRef(i);
       SGVec3f v0 = getVertex(triangleRef[0]).GetVertex();
       SGVec3f v1 = getVertex(triangleRef[1]).GetVertex();
@@ -312,6 +314,13 @@ public:
       // for this triangle.
       double num = area / coverage + mt_rand(&seed);
 
+      if (num > MAX_RANDOM_OBJECTS) {
+          SG_LOG(SG_TERRAIN, SG_ALERT,
+                 "Per-triangle random object count exceeded limits ("
+                         << MAX_RANDOM_OBJECTS << ") " << num);
+          num = MAX_RANDOM_OBJECTS;
+      }
+
       // place an object each unit of area
       while ( num > 1.0 ) {
         float a = mt_rand(&seed);