I'm looking to calculate the distance from the camera to a bounding box. I can calculate the distance to the center, but I really need the distance to the closest edge. The bounding box is defined as (MaxEdge, MinEdge); how does this define a box? Is it, Center+MaxEdge defines a sphere around the box? Sorry, it's late
Distance from BoundingBox
Distance from BoundingBox
Hi,
I'm looking to calculate the distance from the camera to a bounding box. I can calculate the distance to the center, but I really need the distance to the closest edge. The bounding box is defined as (MaxEdge, MinEdge); how does this define a box? Is it, Center+MaxEdge defines a sphere around the box? Sorry, it's late
I'm looking to calculate the distance from the camera to a bounding box. I can calculate the distance to the center, but I really need the distance to the closest edge. The bounding box is defined as (MaxEdge, MinEdge); how does this define a box? Is it, Center+MaxEdge defines a sphere around the box? Sorry, it's late
-
rogerborg
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Yup, that's how it's done in CSceneCollisionManager.
Note the use of getDistanceFromSQ() for the comparison checks.
Code: Select all
if (box.intersectsWithLine(line))
{
box.getEdges(edges);
f32 distance = 0.0f;
for (s32 e=0; e<8; ++e)
{
f32 t = edges[e].getDistanceFromSQ(line.start);
if (t > distance)
distance = t;
}
if (distance < outbestdistance)
....
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Thinking of creating a sphere from the boundingbox then determining the distance to it. Should work, unless someone can see a fault in my cunning plan.
I know it doesn't strictly give me the distance to the box, but it does allow me to roughly sort objects based on distance.
Code: Select all
vector3d middle = BB.getCenter();
vector3d diag = middle - BB.maxEdge;
float radius = diag.getLength();
Distance = max_(0.0, (point-middle).getLength() - radius)