I’ve been working on this problem for the afternoon and I think I’m probably missing something easy.
I’m getting the rotation quaternion from the Input.gyro.attitude on iOS. All I want to do is keep track of the player moving around and know when the player has spun around in a circle.
This is a different axis depending on the way the user is holding the device (and we really don’t care if someone just spins in their hands) so I want to know when any axis has been rotated 360.
Any suggestions?
each frame add the delta from the last rotation to this rotation to a variable, accounting for wrap if necessary.
Is this the Dot product of the two Quaternions or does “QuatDelta = QuatA - QuatB” work?
I’d have used dot but I haven’t checked quaternions like this.
Quaternion only has a multiplication ( * ) arithmetic operator defined.
If you want the angle between two quats, there’s a method defined (which does partially use the dot product).
Quaternion.Angle
Just track the ‘last rotation’ every frame so you can compare the delta (change) every frame. Get the angle between last and current. And sum those up as you go.
You’ll have to decide when to start summing them up though. May that be when they go from not moving to moving, or when they click a button, or something.
Quaternion.Angle is any angle so it includes all 3 axis and is always a positive number; ie its the difference between the two angles with no signed direction value.
I have been attempting to use Mathf.DeltaAngle( LastFrameQuat.eulerAngles.x, ThisFrameQuat.eulerAngles.x ), but I seem to get gimbal lock (or something like it).