Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Three.js立方体-旋转到随机侧_Javascript_Three.js_Cube - Fatal编程技术网

Javascript Three.js立方体-旋转到随机侧

Javascript Three.js立方体-旋转到随机侧,javascript,three.js,cube,Javascript,Three.js,Cube,我有一个3.js立方体,有六个不同的边 我写了一个随机数生成器,希奇生成一个介于1-6之间的数字。 点击一个按钮,我想将立方体旋转到一边(数字) Stallion()的小提琴看起来不错,但对我来说不管用,因为我不知道我需要在立方体的某个特定面上漫游多少 我的尝试是: mesh.rotation.x =0; mesh.rotation.y =0; //face2 mesh.rotation.x =0; mesh.rotation.y =1.571;

我有一个3.js立方体,有六个不同的边

我写了一个随机数生成器,希奇生成一个介于1-6之间的数字。 点击一个按钮,我想将立方体旋转到一边(数字)

Stallion()的小提琴看起来不错,但对我来说不管用,因为我不知道我需要在立方体的某个特定面上漫游多少

我的尝试是:

   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+),需要很长时间才能到达面

我能做什么? 这是小提琴:

更新: 我认为有误解。。。 单击开始按钮,立方体开始旋转。 在“停止”按钮上,立方体应位于1-6的一侧(随机)。 上面我写的面部表情

现在我可以使用for
(mesh.rotation.x==want.rotation.x;mesh.rotation.x-=0.02)


问题是,如果mesh.rotation-value非常高,立方体需要经过一段时间和大量旋转才能旋转到该位置…

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


还要确保你的x和y值保持在
0的范围内我不确定我是否理解你的意思。。。您提供的小提琴(随机旋转)工作正常。你说几轮后花的时间太长是什么意思?