简体   繁体   English

Object Three.js中的旋转/三图

[英]Object Rotation in Three.js / Threemap

I am trying to create a 3D Visualization of an RC airplane in Threebox.我正在尝试在 Threebox 中创建遥控飞机的 3D 可视化。 The RC plane sends live telemetry, including:遥控飞机发送实时遥测,包括:

  • GPS Coordinates GPS坐标
  • Gyro sensor data, showing the pitch, roll and heading of the plane.陀螺仪传感器数据,显示飞机的俯仰、横滚和航向。

I have now loaded a Model of an airplane in Threebox, no problems with that.我现在已经在 Threebox 中加载了一架飞机的 Model,没问题。 My problem comes down to the rotation of the plane.我的问题归结为飞机的旋转。 I want the plane object to represent the current orientation of the RC plane.我希望平面 object 代表 RC 平面的当前方向。 Since I have the live telemetry from the flight controller, this should be possible.由于我有来自航班 controller 的实时遥测,这应该是可能的。

In the Documentation, I have found this method, which seemed like exactly what i needed:在文档中,我找到了这种方法,这似乎正是我所需要的:

plane.setRotation({x: roll, y: pitch, z: yaw/heading})

And it basically works.它基本上有效。 I can rotate the Plane around its axes.我可以围绕其轴旋转平面。 But things get messed up when I combine the rotations.但是当我结合轮换时,事情变得一团糟。

For example: When I just update the roll axis, the Object behaves just like I want it to.例如:当我刚刚更新滚动轴时,Object 的行为就像我想要的那样。 However, when i change the heading of the plane by 90 degrees, the roll axis suddenly becomes the pitch axis.但是,当我将飞机的航向改变 90 度时,横滚轴突然变成俯仰轴。 It seems to me, that the axes of the Plane object don't rotate with the plane itself.在我看来,平面 object 的轴不随平面本身旋转。

I've prepared a recreation of the issue on jsfiddle .我已经准备好在 jsfiddle上重现这个问题。 You can change the heading of the plane using the slider in the bottom right.您可以使用右下角的 slider 更改飞机的航向。

I've been stuck on this for days, would be super happy for any help!我已经坚持了好几天了,如果有任何帮助,我会非常高兴!

There are lots of issues with your jsfiddle that prevent it from running.你的 jsfiddle 有很多问题阻止它运行。 To isolate an issue and make it easier to test you should eliminate as many variables as possible - you're using two third-party libraries that will play a big hand in how transformations behave, particularly threebox.为了隔离问题并使其更容易测试,您应该消除尽可能多的变量 - 您正在使用两个第三方库,它们将在转换行为方面发挥重要作用,尤其是三盒。

I would recommend sticking with three.js's built in transformation tools unless you specifically need some lat/lng transformations, or other transformations to move between a local cartesian space and a global coordinate system.我建议坚持使用 three.js 的内置转换工具,除非您特别需要一些纬度/经度转换,或其他转换以在局部笛卡尔空间和全局坐标系之间移动。 In this case, a very basic plane.setRotationFromEuler(new THREE.Euler(yaw, pitch, roll)) should do the trick.在这种情况下,一个非常基本的plane.setRotationFromEuler(new THREE.Euler(yaw, pitch, roll))应该可以解决问题。 Be aware of how much order in euler rotations can affect the outcome, and that three.js uses radians for all its rotations, not degrees.请注意欧拉旋转的顺序会影响结果,并且 three.js 对其所有旋转都使用弧度,而不是度数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM