webglxtk

Wrong volume bounding box


I'm using Xtk to make a widget to measure distances in a volume. In the scene there are four object: a volume, two spheres an a cube. the cube is placed at origin and the spheres are translated 30 units along X and Y axis, each in opposite direction, as shown below:

https://docs.google.com/file/d/0B2oRl7iWfVvTaXAyckNTOC04RlE/edit?usp=sharing

The cube and the spheres are placed in the right position, but the problem arises when the volume is included in the scene, changing the coordinate system and translating the origin:

https://docs.google.com/file/d/0B2oRl7iWfVvTR3BJdk13Zm9BdTQ/edit?usp=sharing

resetBoundingBox() function is called right after render() but it makes no difference. Even I have tried to add first the objects and then the volume to the renderer with no result.

The spheres also can be dragged, and this feature is also affected by the change of the corrdinate system because ath the moment of the beginning of the movement of the sphere, this is translated respect to mouse position.

Why is the origin being translated? It seems the volume affects the scene by nullifying resetBoundingBox().


Solution

  • I think this happens because you assume the volume is centered on (0, 0, 0), which is a wrong assumption.

    1- Compute the REAL volume center from the volume bounding box

    var volume = new X.volume();
    ...
    var center = [volume.bbox[0] + (volume.bbox[1]-volume.bbox[0])/2,
                  volume.bbox[2] + (volume.bbox[3]-volume.bbox[2])/2,
                  volume.bbox[4] + (volume.bbox[5]-volume.bbox[4])/2
                  ]
    ...
    

    2- Apply this center as translation to the objects of the scene

    Hope this helps