From c814eb3a1ee4490369a06ae93aea8187705ad69d Mon Sep 17 00:00:00 2001 From: david Date: Thu, 18 Jul 2002 19:16:47 +0000 Subject: [PATCH] Make objects appear more smoothly and reliably. --- src/Objects/newmat.cxx | 7 +++++-- src/Objects/obj.cxx | 40 +++++++++++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/Objects/newmat.cxx b/src/Objects/newmat.cxx index 67d4fba2a..919039293 100644 --- a/src/Objects/newmat.cxx +++ b/src/Objects/newmat.cxx @@ -181,12 +181,15 @@ FGNewMat::read_properties (const SGPropertyNode * props) ssgTexturePath((char *)path.dir().c_str()); ssgEntity * model = load_object((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); if (object_node->getBoolValue("billboard", false)) { ssgCutout * cutout = new ssgCutout(false); cutout->addKid(model); - object.model = cutout; + ((ssgBranch *)object.model)->addKid(cutout); } else { - object.model = model; + ((ssgBranch *)object.model)->addKid(model); } object.model->ref(); object.coverage = object_node->getDoubleValue("coverage", 100000); diff --git a/src/Objects/obj.cxx b/src/Objects/obj.cxx index 1b95d967e..40302f92b 100644 --- a/src/Objects/obj.cxx +++ b/src/Objects/obj.cxx @@ -502,6 +502,29 @@ DummyBSphereEntity::get_entity () } +/** + * Calculate the bounding radius of a triangle from its center. + * + * @param center The triangle center. + * @param p1 The first point in the triangle. + * @param p2 The second point in the triangle. + * @param p3 The third point in the triangle. + * @return The greatest distance any point lies from the center. + */ +static float +get_bounding_radius (sgVec3 center, float *p1, float *p2, float *p3) +{ + float result = sgDistanceVec3(center, p1); + float length = sgDistanceVec3(center, p2); + if (length > result) + result = length; + length = sgDistanceVec3(center, p3); + if (length > result) + result = length; + return result; +} + + /** * Set up a triangle for randomly-placed objects. * @@ -526,6 +549,9 @@ setup_triangle (float * p1, float * p2, float * p3, (p1[1] + p2[1] + p3[1]) / 3.0, (p1[2] + p2[2] + p3[2]) / 3.0); + // maximum radius of an object from center. + double bounding_radius = get_bounding_radius(center, p1, p2, p3); + // Set up a transformation to the center // point, so that everything else can // be specified relative to it. @@ -535,17 +561,17 @@ setup_triangle (float * p1, float * p2, float * p3, location->setTransform(TRANS); branch->addKid(location); - // Calculate the triangle area. - double area = sgTriArea(p1, p2, p3); - // Iterate through all the object types. int num_objects = mat->get_object_count(); for (int i = 0; i < num_objects; i++) { - // Set up the range selector. Note that - // we provide only two ranges, so the - // upper limit will be infinity. - float ranges[] = {0, mat->get_object_lod(i), 9999999}; + // Set up the range selector for the entire + // triangle; note that we use the object + // range plus the bounding radius here, to + // allow for objects far from the center. + float ranges[] = {0, + mat->get_object_lod(i) + bounding_radius, + 500000}; ssgRangeSelector * lod = new ssgRangeSelector; lod->setRanges(ranges, 3); location->addKid(lod);