Three.js - 围绕特定轴旋转对象 [英] Three.js - Rotating a object around certain axis

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

问题描述

我使用了 THREE={REVISION:"68"}

I've used THREE={REVISION:"68"}

我已经通过轴"z"http://jsfiddle.net/eVkgs/39/

当我改变位置 OBJECT_X: CubeGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 20,Cube_height/2, 0 ) ); http://jsfiddle.net/eVkgs/40/

When I change position OBJECT_X: CubeGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 20,Cube_height/2, 0 ) ); http://jsfiddle.net/eVkgs/40/

对象仍然按轴z"旋转,因为我设置了:OBJECT_X.rotation.z += 0.3*Math.PI/30;

Object is still rotate by axis "z" becouse I setup : OBJECT_X.rotation.z += 0.3*Math.PI/30;

问题:允许围绕放置此对象的轴旋转的代码应该如何看?

Question : how should look code that allow to rotate around axis which this object is placed ?

推荐答案

一个对象将在其本地坐标系中围绕其原点旋转.如果要移动原点,则必须平移几何体本身.这是要遵循的模式:

An object will rotate around its origin in its local coordinate system. If you want to shift the origin, then you have to translate the geometry itself. Here is the pattern to follow:

geometry.translate( dx, dy, dz );

您现在可以从几何体创建网格,并设置网格位置:

You can now create a mesh from the geometry, and set the mesh position:

mesh.position.set( x, y, z );

如果旋转网格,它将围绕新原点旋转,网格将位于点 (x, y, z).

If you rotate the mesh, it will rotate around its new origin, and the mesh will be located at the point ( x, y, z ).

three.js r.84

three.js r.84

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

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