【发布时间】:2016-07-20 10:45:45
【问题描述】:
我有一个 Three.js 立方体,有六个不同的面。
我写了一个随机数生成器,它生成一个介于 1-6 之间的数字。 单击按钮时,我想将立方体旋转到侧面(数字)。
Stallion(http://jsfiddle.net/majman/6vrH8/) 的小提琴看起来不错,但不适用于我,因为我不知道我必须将多维数据集旋转到特定的一侧......
我的尝试是这样的:
mesh.rotation.x =0;
mesh.rotation.y =0;
//face2
mesh.rotation.x =0;
mesh.rotation.y =1.571;
//face3
mesh.rotation.x =0;
mesh.rotation.y =3.142;
...
mesh.rotation.x =0;
mesh.rotation.y =4.714;
...
mesh.rotation.x =1.571;
mesh.rotation.y =0;
...
mesh.rotation.x =-1.571;
mesh.rotation.y =0;
然后我想 += 或 -= 旋转到上述数字。 问题是经过几轮之后,mesh.rotation.x/y 太高(100+),需要很长时间才能到达面。
我能做什么? 这是小提琴:https://jsfiddle.net/crinca15/2o8n3xox/
更新: 我觉得有误解... 单击开始按钮后,立方体开始旋转。 在停止按钮上,立方体应该从 1-6(随机)转到一侧。 我上面写的脸型。
现在我可以使用(mesh.rotation.x == wanted.rotation.x; mesh.rotation.x -= 0.02)
问题是,如果 mesh.rotation-value 非常高,立方体需要经过时间和大量的旋转才能旋转到位置...
【问题讨论】:
-
我不确定我是否理解你......你提供的小提琴(随机旋转)工作正常。你是什么意思在几轮之后需要太长时间?
标签: javascript three.js cube