All objects have two AABB (Axis Aligned Bounding Box), one in local space and one another in world space. The box in local space is calculated while importing scene from external source, and the box in world space is transformed version of local one

The AABB of scene is combined of all child AABB boxes. I'm using the center of scene's AABB as center of scene. This is where my problems begins.

I'm using the center point to rotate scene using a trackball. After scene is rotated around center of AABB, then new node transforms are applied to each AABB and new AABB for scene is re-computed by combining/joining all AABB boxes.

Problem: After rotation applied and new AABB is computed, then the new AABB's center is not same as previous one. So after rotation, center and scene is moving a little.

There is no problem in these cases:

  • If there is only one object in scene then new center is not changing so scene doesn't move after rotation. Everything looks good here. Object/Model/Primitive may have local transform, this doesn't affect the result
  • for instance if there are two cube without rotations then center is not moving too, except if one of cube has rotation or there are three cube then center is moving.

If my rotating-around-object codes are wrong then it wouldn't work for single object too, right?

Here how I compute center of box,

center = (box.min + box.max) * 0.5

this is not actual code, because I'm using C.

Is it normal to have moving center after rotation? How do you get center of scene? Using center of AABB like I did?? Any suggestions?

Maybe it must work and maybe I have a weird bug is some place I don't know, I tried to find it but I had to ask because maybe it is wrong to get center of scene via AABB boxes :(

up vote 0 down vote accepted

Solution:

Instead of re-calculating center, pre-defined center is used for primitives. The pre-defined center is center of AABB if other value is not supplied. Averaging all center of mesh primitives gives mesh center and averaging all center of meshes gives scene center. After a mesh is transformed, center also gets transformed.

Now center is not moving after rotations. Using center of scene's AABB seems not good idea. Because each shape of child AABB is changing after transformations.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.