围绕世界轴旋转对象

Ram*_*uri 1 javascript rotation three.js

我试图围绕世界轴旋转一个物体.我发现了这个问题:如何在轴世界上旋转一个物体three.js?

但它没有通过使用此功能解决问题:

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);
}
Run Code Online (Sandbox Code Playgroud)

multiplySelf并且getRotationFromMatrix没有定义(我收到控制台错误).如何解决问题?

更新

我尝试使用Quaternion,但似乎行为不正确.我正在尝试根据用户点击旋转对象,这是我写的函数:

function mouseUp(event) {
    var x= event.clientX;
    var y= event.clientY;
    var dx= (x - xBegin);
    var dy= (y - yBegin);

    var quaternion= new THREE.Quaternion();
    quaternion.setFromAxisAngle(new THREE.Quaternion(dy,dx,0).normalize(),Math.sqrt(dx*dx+dy*dy)/250.0);
    object.quaternion.multiplyQuaternions(quaternion,object.quaternion);
}
Run Code Online (Sandbox Code Playgroud)

只要物体处于垂直或水平位置,它就可以正确旋转,但如果它与x轴成45度角,则旋转速度非常慢,并且与咔嗒声的方向相反.

Wes*_*ley 6

只要对象没有旋转的父对象,就可以围绕世界轴旋转对象,如下所示:

object.rotateOnWorldAxis( axis, angle );
Run Code Online (Sandbox Code Playgroud)

axis必须标准化(有单位长度); angle是弧度.

three.js r.92