Rotate object around world axis with tween.js

无人久伴 提交于 2020-02-06 07:28:46

问题


I want to rotate a cube on world axis by using tween.I am able to rotate the cube around world axis without using tween by using

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

but I want to happen this slowly so I want to use it with tween.

I was using

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()

before, but it was rotating the cube around object axis.So,I switched to

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

but how to use it with tween?


回答1:


You can use tween to change a generic value from 0 to 90 and then in the update use the rotateAroundWorldAxis function

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

in tween initialization

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

in onUpdate

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


来源:https://stackoverflow.com/questions/37097101/rotate-object-around-world-axis-with-tween-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!