Question regarding bounding boxes and local rotations

I'm sure I'm just missing something obvious here, but I seem to be having a simple case where a bounding box gets out of sync with the mesh it is bounding.  Here is the test code for my scenario:



import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.scene.shape.Box;

public class ErrorTest extends SimpleGame {
   
   protected void simpleInitGame() {
      cam.setLocation(new Vector3f(-10, 20, -10));
      cam.lookAt(new Vector3f(50, 0, 50), new Vector3f(0, 1, 0));      
      
      Box b = new Box("box", new Vector3f(-0.5f, -0.5f, -0.5f), new Vector3f(0.5f, 0.5f, 0.5f));
      b.setLocalScale(new Vector3f(100, 100, 20));
      b.setLocalTranslation(new Vector3f(150, -90, 150));
      Quaternion quat = new Quaternion();
      quat.fromAngleAxis(1f, new Vector3f(0, 1, 0));
      b.setLocalRotation(quat);      
      
      b.setModelBound(new BoundingBox());
      b.updateModelBound();
      b.updateCollisionTree();   
      
      
      rootNode.attachChild(b);
   }
   
   public static void main(String argv[]) {
      ErrorTest game = new ErrorTest();
      
      game.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
      game.start();
   }

}



If you run this, and press 'B' to show the wireframes, you will notice that the mesh and the wireframe do not match up.  Am I doing something in the wrong order, or not updating the correct states?

Thanks,

--Ruab

Forgot to mention:  removing the rotation, everything works fine.  It seems to be the rotation which is causing my problem.



–Ruab

You might try setModelBound(new BoundingBox()) before you change the local rotation.



darkfrog

BoundingBox is axis aligned, so no, it won't stay in synch with rotation as it is designed to stay axis aligned.  Sounds like you want to use OrientedBoundBox.

Ah… I assumed if it was an AABB, then is would resize, so that it still bound the entire mesh.  It seems like an odd behavior to me that under certain circumstances, the bounding volume doesnt actually bound the mesh.  Perhaps the AABB computeFromBounds method should transform each point before it creates the bounding volume?  I understand that in this particular case, the AABB would have quite a bit of "empty" space, but it still seems like an unexpected result.



For my project, an OBB (or sphere) should fix the problem… I'll test this later to confirm.



–Ruab

Well, no it should be resizing to fit…  just not rotating.  I'll look into it.

Great… thanks for looking into it renanse!



–Ruab

Ok…  BoundingBox appears to have a bug in its transform method.  I will fix that and post when done.

Please pull from cvs and check the BoundingBox results again.  They should be right on the money now.

That looks like it did the trick.  Thanks renanse!



–Ruab

Good to hear.  Thanks for bringing it to our attention and more importantly thanks for putting together a test case to show the problem…  That always makes our life a million times easier!