Three.js 在它自己的轴上旋转 [英] Three.js rotation over it's own axis

查看:78
本文介绍了Three.js 在它自己的轴上旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在 3D 空间中创建一艘宇宙飞船.它直接飞过去.您可以通过滚动飞船和上下倾斜机头来改变方向.

I've been trying to create a spaceship in a 3D space. It flies straight forward. You can change direction by rolling the spaceship and tip the nose up and down.

当我改变飞船的 Z 角时,它会按预期滚动.当我改变飞船的 X 角时,机头会上下倾斜.当我同时执行这两项操作时,没有按预期工作.

When I change the Z angle of the spaceship, it rolls as expected. When I change the X angle of the spaceship, the nose is tipped up and down. When I do both it doesn't work as expected.

看来我的宇宙飞船正在围绕世界的轴旋转,而不是我的宇宙飞船的轴.我的意思是,当一个物体旋转时,它的轴是对的吗?显然不是.

It appears my spaceship is being rotated over the world's axis, rather than the axes of my spaceship. I mean, when an object gets rotated, so does it's axis' right? Well apparently not.

像往常一样,非常感谢您的帮助.

As usual, help is much appreciated.

以下是显然不起作用的演示:http://www.timseverien.nl/随机/ohnoez/

Here is the demo that clearly doesn't work: http://www.timseverien.nl/random/ohnoez/

推荐答案

查看四元数.在 ThreeJS 中,你要查看的类是 THREE.Quaternion.

Check out Quaternions. In ThreeJS, the class you want to look at is THREE.Quaternion.

四元数通常用于飞行模拟风格的游戏,并允许您在飞行器的局部空间中旋转,而不会获得万向节锁定".(那是当你的两个轴平行时,你失去了一个自由度.)

Quaternions are generally used in flight simulation style games, and allow you to rotate in the local space of the craft, without getting "gimbal lock". ( That's when two of your axes become parallel, and you lose a degree of freedom. )

这是对四元数的一个很好的,也很有趣的解释:http://www.isner.com/tutorials/quatSpells/quaternion_spells_14.htm

This is a pretty good, and quite funny, explanation of quaternions: http://www.isner.com/tutorials/quatSpells/quaternion_spells_14.htm

我希望这能让你走上正轨......

I hope that puts you on the right track...

Isner.com 早就下线了,但是我在 Wayback Machine 上找到了上面的教程:https://web.archive.org/web/20120601095457/http://www.isner.com/tutorials/quatSpells/quaternion_spells_14.htm/a>

Isner.com has long been offline, but I found the above tutorial on the Wayback Machine: https://web.archive.org/web/20120601095457/http://www.isner.com/tutorials/quatSpells/quaternion_spells_14.htm

这篇关于Three.js 在它自己的轴上旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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