put a separate LOD node in front of ever random object so we can randomize
the exact pop in location of each object ... this allows us to put some objects further out and perhaps hide the popping just a tiny bit?
This commit is contained in:
parent
84fcb479f6
commit
8dc38a5198
3 changed files with 45 additions and 11 deletions
|
@ -91,7 +91,7 @@ FGNewMat::FGNewMat (ssgSimpleState * s)
|
|||
|
||||
FGNewMat::~FGNewMat (void)
|
||||
{
|
||||
for (int i = 0; i < objects.size(); i++)
|
||||
for (unsigned int i = 0; i < objects.size(); i++)
|
||||
objects[i].model->deRef();
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ FGNewMat::read_properties (const SGPropertyNode * props)
|
|||
|
||||
vector<SGPropertyNode_ptr> object_nodes =
|
||||
((SGPropertyNode *)props)->getChildren("object");
|
||||
for (int i = 0; i < object_nodes.size(); i++) {
|
||||
for (unsigned int i = 0; i < object_nodes.size(); i++) {
|
||||
const SGPropertyNode * object_node = object_nodes[i];
|
||||
if (object_node->hasChild("path")) {
|
||||
Object object;
|
||||
|
@ -154,19 +154,22 @@ FGNewMat::read_properties (const SGPropertyNode * props)
|
|||
ssgTexturePath((char *)path.dir().c_str());
|
||||
ssgEntity * model = ssgLoad((char *)path.c_str());
|
||||
if (model != 0) {
|
||||
float ranges[] = {0, object_node->getDoubleValue("range-m", 2000)};
|
||||
object.model = new ssgRangeSelector;
|
||||
((ssgRangeSelector *)object.model)->setRanges(ranges, 2);
|
||||
// float ranges[] = {0, object_node->getDoubleValue("range-m", 2000)};
|
||||
// object.model = new ssgRangeSelector;
|
||||
// ((ssgRangeSelector *)object.model)->setRanges(ranges, 2);
|
||||
if (object_node->getBoolValue("billboard", false)) {
|
||||
ssgCutout * cutout = new ssgCutout(false);
|
||||
cutout->addKid(model);
|
||||
((ssgBranch *)object.model)->addKid(cutout);
|
||||
// ((ssgBranch *)object.model)->addKid(cutout);
|
||||
object.model = cutout;
|
||||
} else {
|
||||
((ssgBranch *)object.model)->addKid(model);
|
||||
// ((ssgBranch *)object.model)->addKid(model);
|
||||
object.model = model;
|
||||
}
|
||||
object.model->ref();
|
||||
object.coverage = object_node->getDoubleValue("coverage", 100000);
|
||||
object.group_lod = object_node->getDoubleValue("group-range-m", 5000);
|
||||
object.lod = object_node->getDoubleValue("range-m", 2000);
|
||||
objects.push_back(object);
|
||||
} else {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "Failed to load object " << path.str());
|
||||
|
|
|
@ -175,6 +175,14 @@ public:
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the target LOD range for a dynamic object for this material.
|
||||
*/
|
||||
virtual double get_object_lod (int i) const {
|
||||
return objects[i].lod;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the current state.
|
||||
*/
|
||||
|
@ -254,6 +262,7 @@ private:
|
|||
ssgEntity * model;
|
||||
double coverage;
|
||||
double group_lod;
|
||||
double lod;
|
||||
};
|
||||
|
||||
vector<Object> objects;
|
||||
|
|
|
@ -391,7 +391,18 @@ gen_random_surface_objects (ssgLeaf *leaf,
|
|||
sgPostMultMat4(OBJ, OBJ_pos);
|
||||
ssgTransform * pos = new ssgTransform;
|
||||
pos->setTransform(OBJ);
|
||||
pos->addKid(mat->get_object(j));
|
||||
float obj_range = mat->get_object_lod(j);
|
||||
float range_div = (sg_random() * obj_range);
|
||||
if (range_div < 0.0000001) {
|
||||
// avoid a divide by zero error
|
||||
range_div = 1.0;
|
||||
}
|
||||
float random_range = 160.0 * obj_range / range_div + obj_range;
|
||||
float ranges[] = {0, random_range};
|
||||
ssgRangeSelector *range = new ssgRangeSelector;
|
||||
range->setRanges(ranges, 2);
|
||||
range->addKid(mat->get_object(j));
|
||||
pos->addKid(range);
|
||||
location->addKid(pos);
|
||||
num -= 1.0;
|
||||
}
|
||||
|
@ -409,7 +420,18 @@ gen_random_surface_objects (ssgLeaf *leaf,
|
|||
sgPostMultMat4(OBJ, OBJ_pos);
|
||||
ssgTransform * pos = new ssgTransform;
|
||||
pos->setTransform(OBJ);
|
||||
pos->addKid(mat->get_object(j));
|
||||
float obj_range = mat->get_object_lod(j);
|
||||
float range_div = (sg_random() * obj_range);
|
||||
if (range_div < 0.0000001) {
|
||||
// avoid a divide by zero error
|
||||
range_div = 1.0;
|
||||
}
|
||||
float random_range = 160.0 * obj_range / range_div + obj_range;
|
||||
float ranges[] = {0, random_range};
|
||||
ssgRangeSelector *range = new ssgRangeSelector;
|
||||
range->setRanges(ranges, 2);
|
||||
range->addKid(mat->get_object(j));
|
||||
pos->addKid(range);
|
||||
location->addKid(pos);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue