From e50337e36a6895111004476016244b6904dc71cc Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Sat, 8 Oct 2022 22:41:48 +0100 Subject: [PATCH] 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/ --- simgear/scene/tgdb/SGBuildingBin.hxx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/simgear/scene/tgdb/SGBuildingBin.hxx b/simgear/scene/tgdb/SGBuildingBin.hxx index 27c24c64..dcddcb7d 100644 --- a/simgear/scene/tgdb/SGBuildingBin.hxx +++ b/simgear/scene/tgdb/SGBuildingBin.hxx @@ -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; } };