绕世界轴旋转对象 [英] Rotate object around world axis

查看:56
本文介绍了绕世界轴旋转对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绕着世界轴旋转对象.我发现了以下问题:如何旋转对象在轴世界Three.js上?

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);
}

multiplySelfgetRotationFromMatrix未定义(我收到控制台错误).如何解决该问题?

multiplySelf and getRotationFromMatrix are not defined (I'm getting a console error). How to fix the problem?

更新

我尝试使用Quaternion,但是它似乎无法正常运行.我试图根据用户单击旋转对象,这是我编写的功能:

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);
}

只要对象处于垂直或水平位置,它就可以正确旋转,但是例如,如果它与x轴成45度角,则它会非常缓慢地旋转,并且方向与点击方向相反.

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.

推荐答案

只要对象没有旋转的父对象,就可以像这样围绕世界轴旋转对象:

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必须规范化(具有单位长度); angle以弧度为单位.

axis must be normalized (have unit length); angle is in radians.

three.js r.92

three.js r.92

这篇关于绕世界轴旋转对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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