Three.js - 围绕某个轴旋转球体 [英] Three.js - Rotating a sphere around a certain axis

查看:885
本文介绍了Three.js - 围绕某个轴旋转球体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题。在Three.js中,我想围绕轴旋转一个球体(地球),倾斜23.5度。我找到了sphere.rotation.x,sphere.rotation.y和sphere.rotation.z,但是当我以正确的比例组合它们时,球体的旋转非常奇怪 - 它没有永久旋转轴。我想我需要像sphere.rotation.vector(1,0,-1)这样的函数。有谁知道如何调用这个函数以及正确的语法是什么?

I have a problem. In Three.js, I want to rotate a sphere (Earth) around axis tilted by 23.5 degs. I found sphere.rotation.x, sphere.rotation.y and sphere.rotation.z, but when I combine them in the correct ratio, the sphere's rotation is quite weird - it has no permanent rotation axis. I think I need a function like sphere.rotation.vector(1,0,-1). Does anyone know how this function is called and how the correct syntax is?

非常感谢您的回答!

推荐答案

您需要使用四元数此视频说明了四元数以及它们在3D图形中的使用方式。

You need to use quaternions for this. This video explains what quaternions are and how they are used in 3D graphics.

你可以像这样构造一个四元数:

You can construct a quaternion like this:

quaternion = new THREE.Quaternion().setFromAxisAngle( axisOfRotation, angleOfRotation );

然后通过以下方式将其应用于您的对象:

Then you apply it to your object by:

object.rotation.setEulerFromQuaternion( quaternion );

您也可以使用对象层次结构来实现此目的。例如,您可以创建 Object3D()实例并将其倾斜23.5 degs,然后创建一个球体(地球)并将其添加到倾斜对象。然后球体将围绕倾斜的Y轴旋转。然而,四元数是解决这个问题的最佳工具。

You can also achieve this by using object hierarchies. For example, you can make an Object3D() instance and tilt it by 23.5 degs, then create a sphere (Earth) and add it to the tilted object. The sphere will then rotate around the tilted Y axis. Quaternions however, are the best tool for solving this.

这篇关于Three.js - 围绕某个轴旋转球体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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