}
osg::Node*
-SGMatModel::get_random_model( SGPropertyNode *prop_root )
+SGMatModel::get_random_model( SGPropertyNode *prop_root, mt seed )
{
load_models( prop_root ); // comment this out if preloading models
int nModels = _models.size();
- // int index = int(sg_random() * nModels);
- static int index = -1;
- if (++index >= nModels)
- index = 0;
- return _models[index].get();
+ return _models[mt_rand(&seed) * nModels].get();
}
double
*
* @return A randomly select model from the variants.
*/
- osg::Node *get_random_model( SGPropertyNode *prop_root );
+ osg::Node *get_random_model( SGPropertyNode *prop_root, mt seed );
/**
i < tileGeometryBin.randomModels.getNumModels(); i++) {
SGMatModelBin::MatModel obj
= tileGeometryBin.randomModels.getMatModel(i);
- osg::Node* node = sgGetRandomModel(obj.model);
+ osg::Node* node = sgGetRandomModel(obj.model, seed);
// Create a matrix to place the object in the correct
// location, and then apply the rotation matrix created
root_props = p;
}
-osg::Node* sgGetRandomModel(SGMatModel *obj) {
- return obj->get_random_model( root_props );
+osg::Node* sgGetRandomModel(SGMatModel *obj, mt seed) {
+ return obj->get_random_model( root_props, seed );
}
namespace simgear
#define _SG_USERDATA_HXX
#include <simgear/compiler.h>
+#include <simgear/math/sg_random.h>
#include <osg/Node>
/**
* Get a random model.
*/
-osg::Node* sgGetRandomModel(SGMatModel *obj);
+osg::Node* sgGetRandomModel(SGMatModel *obj, mt seed);
namespace simgear
{