【问题标题】:Rotate object around world axis with tween.js使用 tween.js 围绕世界轴旋转对象
【发布时间】:2016-09-02 23:40:23
【问题描述】:

我想使用补间在世界轴上旋转立方体。我可以在不使用补间的情况下围绕世界轴旋转立方体

rotateAroundWorldAxis(cube[1], new THREE.Vector3(0,1,0),degreeToRadians(90)); 

但我想慢慢发生,所以我想将它与补间一起使用。

我正在使用

var start = {x:cube[1].rotation.x, y:cube[1].rotation.y,    z:cube[1].rotation.z};
var end = {x:cube[1].rotation.x , y:cube[1].rotation.y+degreeToRadians(90) ,
          z:cube[1].rotation.z};

var tween = new TWEEN.Tween(start)
  .to(end, 1000)
  .easing( TWEEN.Easing.Exponential.InOut )
  .onUpdate(function(){
     cube[1].rotation.x = this.x;
     cube[1].rotation.y = this.y;
     cube[1].rotation.z = this.z;
   })
.start()

之前,但它是围绕对象轴旋转立方体。所以,我切换到

rotateAroundWorldAxis(cube[1], new THREE.Vector3(0,1,0),degreeToRadians(90));

但是如何在补间中使用呢?

【问题讨论】:

    标签: javascript 3d three.js rotation tween.js


    【解决方案1】:

    您可以使用 tween 将通用值从 0 更改为 90,然后在更新中使用 rotateAroundWorldAxis 函数

    var cubeAngle = 0; // use this global variable if you want to rotate more than one time
    

    在补间初始化中

    var start = {angle: cubeAngle};
    var end = {angle: cubeAngle + 90};
    

    在更新中

    cubeAngle=this.angle;    
    rotateAroundWorldAxis(cube[1], new THREE.Vector3(0,1,0),degreeToRadians(cubeAngle));
    

    【讨论】:

    • 非常感谢,它解决了我的问题,只是一个小问题,因为它旋转立方体不是 90 度而是 4-5 轮,所以它有点没有得到正确的角度,但没关系,我会自己解决。再次感谢!
    • 我不知道你的问题,但你可以尝试在补间开始之前重置 cubeAngle,比如cubeAngle=cubeAngle % 360,看看这个怪胎是否仍然存在。
    猜你喜欢
    • 2016-02-29
    • 2015-07-23
    • 1970-01-01
    • 2019-10-18
    • 2019-03-06
    • 2014-04-18
    • 2015-04-11
    • 2016-09-09
    相关资源
    最近更新 更多