绕世界轴旋转 [英] Rotate around World Axis

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

问题描述

我尝试使用

myObject.rotateOnWorldAxis(new THREE.Vector3(0,1,0),THREE.Math.degToRad(1));

但结果是,对象仅在对象空间中旋转.

but the result was, that the object is only rotated in object space.

为了确保我使用了正确的方法,我查看了 documentation 发现旋转对象有3种方法:

To be sure that I used the correct method I looked into the documentation and found that there are three methods to rotate an object:

.RotateY(rad)//在局部空间旋转

.rotateOnAxis(axis,rad)//在对象空间中旋转

.rotateOnWorldAxis(axis,rad)//在世界空间中旋转

看来我使用了正确的方法.
这是我这边的错误还是理解问题?

It seems that I used the correct method.
Is this a bug or an understanding problem on my side?

这是一个 JSFiddle 说明了我的问题(蓝色立方体应该绕世界轴旋转).
这是第二个Fiddle,其中青色立方体是另一个对象的子对象.

Here is a JSFiddle which illustrates my problem (the blue cube should rotate around the world axis).
Here is a second Fiddle where thy cyan cube is a child of another object.

推荐答案

在我看来,您真正的问题与世界空间或对象空间旋转无关,因为它们在您的示例中按预期工作.

It looks to me like your real question isn't regarding world space or object space rotations, cause those are working as expected in your examples.

您可能的意思是,如何更改对象的旋转点.如果是这种情况,您有两个选择,您可以翻译 相对于旋转轴心点的所有几何顶点.这样,您的枢轴将以 (0,0,0) 为中心,并且您的顶点将以此为中心旋转.

You probably meant, how to change the point of rotation of an object. If that is the case, you have two options, you can either translate all your geometry vertices in respect to a pivot point of rotation. That way, your pivot will be centered at (0,0,0) and your vertices will rotate in respect to that.

mesh.geometry.translate( x, y, z );

或者您可以使您的对象成为不同 Object3D(枢轴)的子对象,按照上述方式定位原始网格并旋转枢轴网格.

Or you can make your object a child of a different Object3D (pivot), position your original mesh similarly to what was described above and rotate your pivot mesh.

var cube = new THREE.Mesh( geometry, material );
var pivot = new THREE.Object3D();

cube.position.set( 0, 12, 30 ); // offset from center

pivot.add( cube );
scene.add( pivot );

//...

pivot.rotation.y += Math.PI/2;

JSFiddle

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

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