【问题标题】:Three.js Cube - Spin to random sideThree.js Cube - 随机旋转
【发布时间】: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


【解决方案1】:

根据this 看起来是正确的,但如果值不断增加,听起来您正在循环中重复调用此代码。确保在需要时只应用一次旋转。

还要确保您的 x 和 y 值保持在 0 <= value < Math.PI * 2 范围内。

【讨论】:

    猜你喜欢
    • 2014-03-11
    • 2015-12-01
    • 2019-06-01
    • 2021-08-23
    • 2012-10-24
    • 2013-07-15
    • 2016-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多