如何在轴世界上旋转一个物体three.js? [英] How to rotate a object on axis world three.js?
问题描述
是否可以旋转世界的轴而不是物体?
Is it possible to do rotations taking axis of the world and not of the object?
我需要对物体进行一些旋转,但在第一次旋转后,我不能做我想要的其他旋转。
I need to do some rotations of an object, but after the first rotation, I can't do other rotations like i want.
如果无法在世界轴上进行旋转,我的第二个选择是在之后重置轴第一次轮换。这有什么功能吗?
If it's not possible to do rotation on the axis of the world, my second option is to reset the axis after the first rotation. Is there some function for this?
我不能使用 object.eulerOrder
因为它改变了我的方向我在一些轮换后设置 object.eulerOrder =YZX
的对象。
I can't use object.eulerOrder
because it changes the orientation of my object when I set object.eulerOrder="YZX"
after some rotations.
推荐答案
是的,您可以使用在three.js github问题上提供的功能来执行此操作:
Yes you can do it with a function which was supplied on three.js github issues:
var rotWorldMatrix;
// Rotate an object around an arbitrary axis in world space
function rotateAroundWorldAxis(object, axis, radians) {
rotWorldMatrix = new THREE.Matrix4();
rotWorldMatrix.makeRotationAxis(axis.normalize(), radians);
rotWorldMatrix.multiplySelf(object.matrix); // pre-multiply
object.matrix = rotWorldMatrix;
object.rotation.getRotationFromMatrix(object.matrix, object.scale);
}
然后
//rotate 30 degrees on world X
rotateAroundWorldAxis(cube, new THREE.Vector3(1,0,0), 30 * Math.PI/180);
参见我的例子 - http://jsfiddle.net/SCXNQ/156/
See my example - http://jsfiddle.net/SCXNQ/156/
这篇关于如何在轴世界上旋转一个物体three.js?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!