<p><strong>Solution:</strong></p>

<p>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. </p>

<p>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. </p>

CC BY-SA 4.0
2018-05-27T11:45:49.417Z
2018-05-27T11:45:49.417Z
recp
<p>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</p>

<p>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.</p>

<p>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. </p>

<p><strong>Problem:</strong>
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. </p>

<p>There is no problem in these cases:</p>

<ul>
<li>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</li>
<li>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.</li>
</ul>

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

<p>Here how I compute center of box, </p>

<pre><code>center = (box.min + box.max) * 0.5
</code></pre>

<p>this is not actual code, because I'm using C.</p>

<p>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?</p>

<p>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 :(</p>

<transformations><scene-graph>
Rotating scene or complex object using center of AABB
recp
# Rotating scene or complex object using center of AABB

(Asked by: username_0 on 2018-05-22)

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 :(

**Tags:** transformations, scene-graph


---

## 1 answers

### Answer by username_0 on 2018-05-27. Score: 0 | Accepted answer

**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.


---

