我正在尝试围绕世界轴旋转一个对象。 我发现了这个问题: 如何在轴世界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); }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); }只要物体处于垂直或水平位置,它就会正确旋转,但是如果它与x轴成45度角,它会非常缓慢地旋转并沿着与咔哒声相反的方向旋转。
I am trying to rotate an object around the world axis. I've found this question: How to rotate a object on axis world three.js?
But it didn't solve the problem by using this function:
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); }multiplySelf and getRotationFromMatrix are not defined (I'm getting a console error). How to fix the problem?
Update
I tried to use Quaternion, but it doesn't seem to behave correctly. I'm trying to rotate an object according to the user click, this is the function that I've written:
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); }It rotates correctly as long as the object is in vertical or horizontal position, but if it's for example at 45 degrees from the x axis, it rotates very slowly and in the opposite direction of the click.
最满意答案
只要对象没有旋转的父对象,就可以围绕世界坐标轴旋转对象,如下所示:
object.rotateOnWorldAxis( axis, angle );axis必须标准化(有单位长度); angle以弧度表示。
三.js r.92
As long as the object does not have a rotated parent, you can rotate the object around a world axis like so:
object.rotateOnWorldAxis( axis, angle );axis must be normalized (have unit length); angle is in radians.
three.js r.92
更多推荐
发布评论