Reputation: 477
I have a node in ARKit for which I've registered its rotation at some point. Later on, I'm registering the node's current rotation once again and I need to know the difference between those two.
I need this in the simdRotation
format because I'll need to inject it to the simdPivot
to then turn my node accordingly. So I need the angle and the vector of axis of rotation. (So I will turn this simdRotation into a rotation matrix and along with the translation, feed it to the simdPivot - this I know how to do).
I've been trying so many different things and I can't find how to calculate this difference nor do I find any documentation or site explaining how to accomplish this.
I tried maybe using the simdEulerAngles
or the simdOrientation
.
I found a method to convert the eulerAngles into an orientation quaternion. But from here I don't know how to convert it back to the rotation format.
I need to do this in 2 places in my code. In one place I'll need the difference of rotation in all 3 directions and in the 2nd place I'll just need the difference of rotation around the y-axis.
So what's the correct way to find the difference between 2 rotations? I feel like it must be much simpler than how it currently looks to me. Maybe I can convert both to rotation matrices and from here there's a clear formula?
Any help would be much appreciated! Thanks.
Upvotes: 0
Views: 285
Reputation: 477
So I ultimately figured this out. I turn each rotation into a rotation matrix - in my case I use a simd_float4x4 because I later combine it with a translation (as 4th column) into a transform matrix. I do something like this:
let newRotationInTransformMatrix = simd_float4x4(SCNMatrix4MakeRotation(currentRotation!.w, currentRotation!.x, currentRotation!.y, currentRotation!.z))
(If anyone knows how to create such a matrix directly in the simd world, please comment. I didn't know so I first created it in the SCN notation and then converted to the sims format).
I do the same with the other rotation. Then to find the difference between the two, I multiply one matrix by the transpose of the other:
let pivotRotationMatrix = lastMazeRotationInTransformMatirx * newRotationInTransformMatrix.transpose
This worked for me. I hope it can help others as well!
Upvotes: 1