使用 tween.js 围绕世界轴旋转对象 [英] Rotate object around world axis with tween.js

查看:80
本文介绍了使用 tween.js 围绕世界轴旋转对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 tween 在世界轴上旋转立方体.我可以使用 tween 在不使用 tween 的情况下绕世界轴旋转立方体

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.

我正在使用

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?

推荐答案

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

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

在补间初始化

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

在更新中

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

这篇关于使用 tween.js 围绕世界轴旋转对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆