Quaternion rotation flips axis

I am streaming data into unreal from an inertial sensor. It outputs UnNrmalized quaternion data in the format:

X = 6561.00000
Y = 6691.00000
Z = 2118.00000
W = 2078.00000

I am applying this to an actor, in c++, using:

this->SetActorRelativeRotation(rotsQ);

And it gives me strange gimbal issues.

When i rotate pitch 90 degrees, it rotates in Pitch.

I rotate 90 degrees in Yaw.

When i rotate pitch 90 degrees, it rotates in Roll.

I have tried Converting it to a FRotator and flipping axes, applying axes one at a time and switching the rotation order. I have tried setting the Actor to 0,0,0 every tick then adding the rotation value. No matter what I do, I see the same thing. Any help here would be very much appreciated!

Could it be a handedness problem? What can i try here?

Thanks! This is becoming proper tear-my-hair-out stuff.

I think if you want to use a quaternion for a rotation you need to normalise it first, else it doesnt just represents a rotation around an arbitrary axis but a uniform scale as well. but be aware that normalising on every frame is an expensive thing to do thanks to the square root.

Hi antithing, did you discover a solution for your problem? I think I’m facing a similar issue (also bringing in data from an IMU sensor). Thanks!

@planimalHello, I am going to do a similar project recently, using quaternion to control bone rotation, but the first step, how to access the skeleton in my skeleton tree in c++ code, I can’t do it. How to solve this problem? It is urgent.thank you