[Ardor3d] Exact bounding boxes

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

[Ardor3d] Exact bounding boxes

Stefan
Hi,

is there a way to determine the exact bounding box of a node in Ardor3d? The provided "getWorldBounds" method does not return the expected result.

Imagine you have a sphere with radius 0.5. If you compute the axis-aligned world bounding box you get size 1 in all three dimensions.

Now, imagine you have the same sphere and rotate it around x by 45 degrees. You would expect the same bounding box but "getWorldBounds" returns a different result. It seems like there is a invisible box around the sphere which gets rotated and the bounds are computed for that box.

Is there a way to avoid this behavior? I couldn't find a solution for it.

This is the code:

BoundingVolume worldBounds = sphereNode.getWorldBound();
BoundingBox worldBoundingBox = (BoundingBox)worldBounds.asType(Type.AABB);

Regards,

Stefan
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3d] Exact bounding boxes

Stefan
Hi,

I think I found it. I had to use the OrientedBoundingBox and update its axis after retrieving the world bounds like this:

final OrientedBoundingBox boundingBox = (OrientedBoundingBox)spatial.getWorldBound().asType(Type.OBB);
boundingBox.setXAxis(new Vector3(1, 0, 0));
boundingBox.setYAxis(new Vector3(0, 1, 0));
boundingBox.setZAxis(new Vector3(0, 0, 1));
                       
(BoundingBox)boundingBox.asType(Type.AABB);

Regards,

Stefan
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3d] Exact bounding boxes

gouessej
Administrator
In reply to this post by Stefan
Hi

Are you sure that your bounding box has been updated after rotating it?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3d] Exact bounding boxes

Stefan
Hi Julien,

sorry, I haven't seen your post.

I just realized that the problem still exists. Weird. I was sure that I solved it.

Do you know more about this topic? This problem applies to all kinds of geometry (e.g. meshes).

Regards,

Stefan
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3d] Exact bounding boxes

gouessej
Administrator
Hi

What do you do to indicate to JogAmp's Ardor3D Continuation that it needs to recompute the bounding volumes?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3d] Exact bounding boxes

Stefan
Hi,

I want to compute the extent of the object and draw a box around it.

Regards,

Stefan
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3d] Exact bounding boxes

gouessej
Administrator
I'd like you to tell me whether you call Mesh.updateWorldBound(boolean) or Spatial.updateGeometricState(double, boolean) or Spatial.updateGeometricState(double).

When you rotate a Spatial, the engine updates both the transform and the bounding.

You can use setModelBound with autoCompute too.

The extent of the object is stored into the bounding box.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3d] Exact bounding boxes

gouessej
Administrator
In reply to this post by Stefan
Moreover, use a BoundingSphere as a bounding volume of a sphere instead of tinkering a BoundingBox. Call getRadius() on it, use that to draw an orthogonal box around the sphere.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3d] Exact bounding boxes

Stefan
This would work, but imagine the sphere is defined in a geometry file as a pile of triangles that is not known to be a sphere (no primitive). Then it breaks again.

I recognized something: at the time when the code was working correctly, the OrientedBoundingBox's internal attributes "_xAxis", "_yAxis", and "_zAxis" were different from (1,0,0) (0,1,0) (0,0,1) - according to the rotation.

The code

boundingBox.setXAxis(new Vector3(1, 0, 0));
boundingBox.setYAxis(new Vector3(0, 1, 0));
boundingBox.setZAxis(new Vector3(0, 0, 1));

fixed this issue and the bounding box was axis-aligned again. Everything was fine.

At the moment, the internal variables "_xAxis", "_yAxis", and "_zAxis" still have default direction (1,0,0) (0,1,0) (0,0,1) after the call to "spatial.getWorldBound().asType(Type.OBB);".

It seems like the rotation has no influence on the axis of the OrientedBoundingBox anymore - no idea why. I am sure that it had an influence before. Up to now, I could not reproduce the previous behavior.

Regards,

Stefan
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3d] Exact bounding boxes

Stefan
Hi,

I think I found it: you have to initialize the bounding box of the sphere using an OrientedBoundingBox like this:

               
OrientedBoundingBox boundingBox = new OrientedBoundingBox();
boundingBox.correctCorners = true;
                       
sphere.setModelBound(boundingBox, true);



The problem was that I had initialized the bounding box of the sphere with an ordinary BoundingBox. Now, it looks good again.

Regards,

Stefan
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3d] Exact bounding boxes

gouessej
Administrator
Actually, I had some difficulties to understand what you expected.

If you call computeFromPoints(), it will be reset to "false".
Julien Gouesse | Personal blog | Website