Question about quaternion rotation

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By smekras

I have an IMU sensor, interfacing with Godot, sending a quaternion (x, y, z, w). The model behaves as if the Y and Z axes are swapped, rolling when it should yaw. I’m using the following code:

func track_cube(x, y, z, w):
  var t = get_transform()
  var myRot = Quat(x, y, z, w)
  var m = Basis(myRot)
  var n = Transform(m.x.normalized(), m.y.normalized(), m.z.normalized(), t.origin)
  cube.set_transform(n)

I also tried getting the Euler angles from the quaternion, swapping Y and Z, then creating a quaternion from that to apply the rotation. When I did that, the model would turn properly, but as yaw approached 90 degrees on either side, pitch would get reversed.

I’m sure I am missing something basic but I would appreciate the help.

Have you figured this out? I’m in the same situation right now…

Michal Seta | 2020-02-08 00:21

:bust_in_silhouette: Reply From: Mason6742

Hey dude ,
I’m trying to something like your project ,
I hope you solved all your issues.
I gonna leave my email address below , please mail me cause I’m having some real problem.
Thanks again.
meisamsafavi5@gmail.com