Object Rotation in Three.js / Threemap

324 views Asked by At

I am trying to create a 3D Visualization of an RC airplane in Threebox. The RC plane sends live telemetry, including:

  • GPS Coordinates
  • 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. My problem comes down to the rotation of the plane. I want the plane object to represent the current orientation of the RC plane. Since I have the live telemetry from the flight controller, this should be possible.

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. However, when i change the heading of the plane by 90 degrees, the roll axis suddenly becomes the pitch axis. It seems to me, that the axes of the Plane object don't rotate with the plane itself.

I've prepared a recreation of the issue on jsfiddle. You can change the heading of the plane using the slider in the bottom right.

I've been stuck on this for days, would be super happy for any help!

1

There are 1 answers

0
Hobo Joe On

There are lots of issues with your jsfiddle that prevent it from running. 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. In this case, a very basic plane.setRotationFromEuler(new THREE.Euler(yaw, pitch, roll)) should do the trick. 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.