]> git.mxchange.org Git - flightgear.git/commitdiff
Make objects appear more smoothly and reliably.
authordavid <david>
Thu, 18 Jul 2002 19:16:47 +0000 (19:16 +0000)
committerdavid <david>
Thu, 18 Jul 2002 19:16:47 +0000 (19:16 +0000)
src/Objects/newmat.cxx
src/Objects/obj.cxx

index 67d4fba2a7b85ccbcfde29ab9c0a22221651276f..919039293735621ebecdb781e1187af8f3d70837 100644 (file)
@@ -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);
index 1b95d967e023c2862bbebadc20b6f8ebeb9fe866..40302f92bb6a8d47da37682881c018b0253fab57 100644 (file)
@@ -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);