三个js 3D旋转 [英] Three js 3D rotation
问题描述
我有 2 个网格物体.锚和杆.锚围绕 z 轴旋转,如图所示.杆应该只能前后移动.这是图片:http://imageshack.us/photo/my-images/841/7a83.png/.
I have 2 mesh objects. Anchor and Rod. The Anchor rotates around z-axis, as illustrated by the image. The rod is supposed to move only backward and forwards. Here is the image: http://imageshack.us/photo/my-images/841/7a83.png/.
但我一直在试图找出矩阵计算.例如,如果锚旋转 45 度,所以它面向 x 轴,我怎样才能让杆仍然前后移动?
But i am stuck with trying to figure out the matrix calculation. For example if the anchor rotates 45degrees, so its facing the x-axis, how can i make the rod still move backwards and forwards?
推荐答案
对于绕 z 轴的旋转:
For the rotation around z axis :
var rotation = new THREE.Matrix4().makeRotationZ(Math.PI/2);
对于翻译,其中 z 是您的增量:
For the translation, where z is your delta :
var translation = new THREE.Matrix4().makeTranslation(0, 0, z);
您可以在开始时将两种转换与翻译结合起来:
You can combine the two transformations in beginning with the translation :
var 转换 = new THREE.Matrix4().makeTranslation(0, 0, z).makeRotationZ(Math.PI/2);
var transformation = rotation.multiply(translation);
然后将变换应用于您的几何体:
Then apply transformation to your geometry :
geometry.applyMatrix(transformation);
这篇关于三个js 3D旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!