building_large_max_width = props->getFloatValue("building-large-max-width-m", 75.0);
building_large_min_depth = props->getFloatValue("building-large-min-depth-m", 50.0);
building_large_max_depth = props->getFloatValue("building-large-max-depth-m", 75.0);
+
+ building_range = props->getDoubleValue("building-range-m", 10000.0);
cos_object_max_density_slope_angle = cos(props->getFloatValue("object-max-density-angle-deg", 20.0) * osg::PI/180.0);
cos_object_zero_density_slope_angle = cos(props->getFloatValue("object-zero-density-angle-deg", 30.0) * osg::PI/180.0);
inline double get_building_large_min_depth () const { return building_large_min_depth; }
inline double get_building_large_max_depth () const { return building_large_max_depth; }
+ inline double get_building_range () const { return building_range; }
+
inline double get_cos_object_max_density_slope_angle () const { return cos_object_max_density_slope_angle; }
inline double get_cos_object_zero_density_slope_angle () const { return cos_object_zero_density_slope_angle; }
double building_large_min_depth;
double building_large_max_depth;
+ double building_range;
+
// Cosine of the angle of maximum and zero density,
// used to stop buildings and random objects from being
// created on too steep a slope.
typedef std::map<std::string, osg::observer_ptr<osg::StateSet> > BuildingStateSetMap;
static BuildingStateSetMap statesetmap;
-static int numBuildings;
typedef std::map<std::string, osg::observer_ptr<Effect> > EffectMap;
static EffectMap buildingEffectMap;
smallBuildingFraction = mat->get_building_small_fraction();
mediumBuildingFraction = mat->get_building_medium_fraction();
+ buildingRange = mat->get_building_range();
+
SG_LOG(SG_TERRAIN, SG_DEBUG, "Building fractions " << smallBuildingFraction << " " << mediumBuildingFraction);
for (int i = 0; i < 3; i++)
{
+ // Create a quad tree. Only small and medium buildings are faded out.
BuildingGeometryQuadtree
quadbuilding(GetBuildingCoord(), AddBuildingLeafObject(),
SG_BUILDING_QUAD_TREE_DEPTH,
- MakeBuildingLeaf(20000.0, effect));
+ MakeBuildingLeaf(buildingRange, effect, (i != 2)));
// Transform building positions from the "geocentric" positions we
// get from the scenery polys into the local Z-up coordinate
BuildingInstanceTransformer(transInv));
quadbuilding.buildQuadTree(rotatedBuildings.begin(), rotatedBuildings.end());
- for (size_t i = 0; i < quadbuilding.getRoot()->getNumChildren(); ++i)
- group->addChild(quadbuilding.getRoot()->getChild(i));
+ for (size_t j = 0; j < quadbuilding.getRoot()->getNumChildren(); ++j)
+ group->addChild(quadbuilding.getRoot()->getChild(j));
}
return group;
MatrixTransform* mt = new MatrixTransform(transform);
SGBuildingBin* bin = NULL;
-
+
BOOST_FOREACH(bin, buildings)
{
- numBuildings = numBuildings + bin->getNumBuildings();
ref_ptr<Group> group = bin->createBuildingsGroup(transInv, options);
for (size_t i = 0; i < group->getNumChildren(); ++i)
#include <simgear/scene/util/StateAttributeFactory.hxx>
#include <simgear/structure/OSGUtils.hxx>
-#define SG_BUILDING_QUAD_TREE_DEPTH 2
+#define SG_BUILDING_QUAD_TREE_DEPTH 4
#define SG_BUILDING_FADE_OUT_LEVELS 4
using namespace osg;
float mediumBuildingMaxDepth;
float largeBuildingMaxDepth;
+ // Visibility range for buildings
+ float buildingRange;
+
// Shared geometries of the building set
ref_ptr<Geometry> smallSharedGeometry;
ref_ptr<Geometry> mediumSharedGeometry;
// Helper classes for creating the quad tree
struct MakeBuildingLeaf
{
- MakeBuildingLeaf(float range, Effect* effect) :
- _range(range), _effect(effect) {}
+ MakeBuildingLeaf(float range, Effect* effect, bool fade) :
+ _range(range), _effect(effect), _fade_out(fade) {}
MakeBuildingLeaf(const MakeBuildingLeaf& rhs) :
- _range(rhs._range), _effect(rhs._effect)
+ _range(rhs._range), _effect(rhs._effect), _fade_out(rhs._fade_out)
{}
LOD* operator() () const
{
LOD* result = new LOD;
- // Create a series of LOD nodes so trees cover decreases slightly
- // gradually with distance from _range to 2*_range
- for (float i = 0.0; i < SG_BUILDING_FADE_OUT_LEVELS; i++)
- {
+ if (_fade_out) {
+ // Create a series of LOD nodes so buidling cover decreases
+ // gradually with distance from _range to 2*_range
+ for (float i = 0.0; i < SG_BUILDING_FADE_OUT_LEVELS; i++)
+ {
+ EffectGeode* geode = new EffectGeode;
+ geode->setEffect(_effect.get());
+ result->addChild(geode, 0, _range * (1.0 + i / (SG_BUILDING_FADE_OUT_LEVELS - 1.0)));
+ }
+ } else {
+ // No fade-out, so all are visible for 2X range
EffectGeode* geode = new EffectGeode;
geode->setEffect(_effect.get());
- result->addChild(geode, 0, _range * (1.0 + i / (SG_BUILDING_FADE_OUT_LEVELS - 1.0)));
+ result->addChild(geode, 0, 2.0 * _range);
}
return result;
}
float _range;
ref_ptr<Effect> _effect;
+ bool _fade_out;
};
struct AddBuildingLeafObject