From: Stuart Buchanan Date: Fri, 7 Nov 2014 22:22:55 +0000 (+0000) Subject: Limit number of random objects per triangle X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=365ddb84a755e69986c3b9480840d693d499032e;p=simgear.git Limit number of random objects per triangle --- diff --git a/simgear/scene/tgdb/SGTexturedTriangleBin.hxx b/simgear/scene/tgdb/SGTexturedTriangleBin.hxx index 67b8e980..0b96a1ff 100644 --- a/simgear/scene/tgdb/SGTexturedTriangleBin.hxx +++ b/simgear/scene/tgdb/SGTexturedTriangleBin.hxx @@ -22,6 +22,8 @@ #ifndef SG_TEXTURED_TRIANGLE_BIN_HXX #define SG_TEXTURED_TRIANGLE_BIN_HXX +#define MAX_RANDOM_OBJECTS 100.0 + #include #include #include @@ -291,8 +293,8 @@ public: osg::Texture2D* object_mask, std::vector >& 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);