From 8dc38a5198e2e99d25ffd9040d21e77442ef2382 Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 16 Jul 2002 20:43:40 +0000 Subject: [PATCH] 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? --- src/Objects/newmat.cxx | 17 ++++++++++------- src/Objects/newmat.hxx | 9 +++++++++ src/Objects/obj.cxx | 30 ++++++++++++++++++++++++++---- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/Objects/newmat.cxx b/src/Objects/newmat.cxx index c2f32754f..c15c9849d 100644 --- a/src/Objects/newmat.cxx +++ b/src/Objects/newmat.cxx @@ -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 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()); diff --git a/src/Objects/newmat.hxx b/src/Objects/newmat.hxx index 57a9e9df9..fedfda1d4 100644 --- a/src/Objects/newmat.hxx +++ b/src/Objects/newmat.hxx @@ -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 objects; diff --git a/src/Objects/obj.cxx b/src/Objects/obj.cxx index 479e5a56a..ff7e5ed72 100644 --- a/src/Objects/obj.cxx +++ b/src/Objects/obj.cxx @@ -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; } @@ -407,9 +418,20 @@ gen_random_surface_objects (ssgLeaf *leaf, sgMakeTransMat4(OBJ_pos, result); sgCopyMat4(OBJ, ROT); sgPostMultMat4(OBJ, OBJ_pos); - ssgTransform * pos = new ssgTransform; - pos->setTransform(OBJ); - pos->addKid(mat->get_object(j)); + ssgTransform * pos = new ssgTransform; + pos->setTransform(OBJ); + 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); } }