]> git.lizzy.rs Git - irrlicht.git/commitdiff
Fix: Make CBillboardSceneNode bounding-box large enough to fit the billboard inside.
authorcutealien <cutealien@dfc29bdd-3216-0410-991c-e03cc46cb475>
Thu, 29 Sep 2022 14:12:12 +0000 (14:12 +0000)
committersfan5 <sfan5@live.de>
Fri, 24 Mar 2023 16:09:11 +0000 (17:09 +0100)
It still won't work yet for scaled boundingboxes (or parents being scaled).
But at least it's now large enough for typical unscaled boundingboxes.
Before it was always too small - even for the simplest quadratic billboard case seen without rotation.
Now it's always a bit too large, but that's way less of a problem (collisions still work and culling simply happens a bit less often, but not too often which is way worse)

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6431 dfc29bdd-3216-0410-991c-e03cc46cb475

source/Irrlicht/CBillboardSceneNode.cpp

index da90c3a15774a409e3344827f53e90fcd0df4108..c1776d4d13d9bfdb65f679952c20a030087be519 100644 (file)
@@ -141,7 +141,7 @@ void CBillboardSceneNode::updateMesh(const irr::scene::ICameraSceneNode* camera)
 //! returns the axis aligned bounding box of this node\r
 const core::aabbox3d<f32>& CBillboardSceneNode::getBoundingBox() const\r
 {\r
-       // Really wrong when scaled.\r
+       // Really wrong when scaled (as the node does not scale it's vertices - maybe it should?)\r
        return BBoxSafe;\r
 }\r
 \r
@@ -162,9 +162,9 @@ void CBillboardSceneNode::setSize(const core::dimension2d<f32>& size)
        if (core::equals(Size.Height, 0.0f))\r
                Size.Height = 1.0f;\r
 \r
-       const f32 avg = (Size.Width + Size.Height)/6;\r
-       BBoxSafe.MinEdge.set(-avg,-avg,-avg);\r
-       BBoxSafe.MaxEdge.set(avg,avg,avg);\r
+       const f32 extent = 0.5f*sqrt(Size.Width*Size.Width + Size.Height*Size.Height);\r
+       BBoxSafe.MinEdge.set(-extent,-extent,-extent);\r
+       BBoxSafe.MaxEdge.set(extent,extent,extent);\r
 }\r
 \r
 \r
@@ -182,9 +182,9 @@ void CBillboardSceneNode::setSize(f32 height, f32 bottomEdgeWidth, f32 topEdgeWi
                TopEdgeWidth = 1.0f;\r
        }\r
 \r
-       const f32 avg = (core::max_(Size.Width,TopEdgeWidth) + Size.Height)/6;\r
-       BBoxSafe.MinEdge.set(-avg,-avg,-avg);\r
-       BBoxSafe.MaxEdge.set(avg,avg,avg);\r
+       const f32 extent = 0.5f*sqrt(Size.Width*Size.Width + Size.Height*Size.Height);\r
+       BBoxSafe.MinEdge.set(-extent,-extent,-extent);\r
+       BBoxSafe.MaxEdge.set(extent,extent,extent);\r
 }\r
 \r
 \r