错误的体积边界框 [英] Wrong volume bounding box

查看:26
本文介绍了错误的体积边界框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Xtk 制作一个小部件来测量体积中的距离.在场景中有四个对象:一个体积、两个球体和一个立方体.立方体放置在原点,球体沿 X 轴和 Y 轴平移 30 个单位,每个单位的方向相反,如下所示:

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() 函数在 render() 之后被调用,但没有区别.甚至我也尝试先添加对象,然后将体积添加到渲染器中,但没有结果.

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.

为什么要翻译原点?似乎音量通过使 resetBoundingBox() 无效来影响场景.

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

推荐答案

我认为发生这种情况是因为您假设体积以 (0, 0, 0) 为中心,这是一个错误的假设.

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

1- 从体积边界框计算真实体积中心

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- 将此中心作为对场景对象的平移

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

希望能帮到你

这篇关于错误的体积边界框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆