三.js - 如何围绕特定点旋转圆柱体? [英] three.js - how do I rotate a cylinder around a specific point?

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

问题描述

我参考了以下有关对象旋转的问题.

I've referred following questions for object rotation.

但无法确切理解如何围绕特定点旋转圆柱体?

But could not understand exactly how do I rotate a cylinder around a specific point ?

推荐答案

我假设您的意思是您希望对象围绕其几何结构内的特定点旋转.

I am assuming that what you mean is that you want an object to rotate around a specific point within it's geometry.

例如,圆柱几何围绕它的中心旋转.假设您希望它围绕其末端旋转.

For example, the cylinderGeometry rotates around it's center. Suppose you want it to rotate around its end.

您需要做的是在创建圆柱几何体后立即对其进行平移,以便几何体中所需的点现在位于原点.

What you need to do is translate the cylinder geometry right after it is created so that the desired point within the geometry is now at the origin.

geometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, cylinderHeight/2, 0 ) );

您现在可以这样做:

geometry.translate( 0, cylinderHeight/2, 0 ); // three.js r.72

现在,当您旋转圆柱体时,它现在将围绕其末端而不是中间旋转.

Now, when you rotate the cylinder, it will now rotate around its end, rather than its middle.

它围绕旋转的一端也将位于您为圆柱体网格设置的位置.

The end that it is rotating around will also be located at the position you have set for the cylinder mesh.

显然,您可以对任何几何体执行此操作,而不仅仅是圆柱体.

Obviously, you can do this with any geometry, not just cylinders.

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

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