Ensure Build Bounding Box doesn't collapse

Previously the Bounding Box of a group of building was calculated
purely based on the position of each building.  Depending on the
geometry of the various buildings, this could result in a zero-volume
box, which would be culled away.

This change ensures that the BB is at least a 20x20x20 volume, by
increasing the convex hull size.

Fixes https://sourceforge.net/p/flightgear/codetickets/2542/
This commit is contained in:
Stuart Buchanan 2022-10-08 22:41:48 +01:00
parent 836ee9a3f0
commit e50337e36a

View File

@ -79,6 +79,24 @@ struct BuildingBoundingBoxCallback : public Drawable::ComputeBoundingBoxCallback
Vec3 pt = (*pos)[v];
bb.expandBy(pt);
}
// This BB is the convex hull of the building position - which are a set of points defining the front, center of
// the building. We therefore need to expand the BB to account for the buildings have width, depth and height.
float BUILDING_RADIUS = 10.0;
bb.expandBy(bb.xMin() - BUILDING_RADIUS, bb.yMin() - BUILDING_RADIUS, bb.zMin() - BUILDING_RADIUS);
bb.expandBy(bb.xMin() - BUILDING_RADIUS, bb.yMin() - BUILDING_RADIUS, bb.zMax() + BUILDING_RADIUS);
bb.expandBy(bb.xMin() - BUILDING_RADIUS, bb.yMax() + BUILDING_RADIUS, bb.zMin() - BUILDING_RADIUS);
bb.expandBy(bb.xMin() - BUILDING_RADIUS, bb.yMax() + BUILDING_RADIUS, bb.zMax() + BUILDING_RADIUS);
bb.expandBy(bb.xMax() + BUILDING_RADIUS, bb.yMin() - BUILDING_RADIUS, bb.zMin() - BUILDING_RADIUS);
bb.expandBy(bb.xMax() + BUILDING_RADIUS, bb.yMin() - BUILDING_RADIUS, bb.zMax() + BUILDING_RADIUS);
bb.expandBy(bb.xMax() + BUILDING_RADIUS, bb.yMax() + BUILDING_RADIUS, bb.zMin() - BUILDING_RADIUS);
bb.expandBy(bb.xMax() + BUILDING_RADIUS, bb.yMax() + BUILDING_RADIUS, bb.zMax() + BUILDING_RADIUS);
return bb;
}
};