In my AR app, I rotate my node around some position in the real world. In order to do that, I use the pivot or simdPivot attribute of the node to rotate around that position. Otherwise it would rotate around the node's center which is elsewhere and the whole node would move around instead of just rotating in place. Up to here all is fine.
The problem is that in ARKit, using a pivot also moves the camera to the pivot's location. I can compensate by changing the node's position in the opposite direction. But then, if I continue this way, the user will never be in the correct "real" position inside the node, but in some "other" location and only due to the pivot he will "see" the correct location.
This is a problem, because later on I will need to catch collisions between the user and elements in the scene. I could continue compensating for the pivot's location, but that's a real pain and not so elegant.
I thought that I could use the pivot, rotate, and then reset the pivot. But it turns out that doing so will not keep the rotation that I set before. Rather, the rotation will behave as if the pivot was never created and will give me the exact behavior I didn't want to achieve.
So let's say I do this in my code:
let translation = simd_float4x4(SCNMatrix4MakeTranslation(0,0,-2))
node?.simdPivot = translation
let rotationMatrix = simd_float4x4(SCNMatrix4MakeRotation(.pi/4, 0, 1, 0))
node?.simdTransform = rotationMatrix
(I found that setting the simdRotation attribute didn't rotate the node so I set the simdTransform instead).
The above code will correctly rotate the node at position (0, 0, -2) But then if I reset the pivot as such:
node?.simdPivot = matrix_identity_float4x4
Now the node will be rotated around (0, 0, 0).
Is there any other way to resolve this? Can I move my node in any other way without having to always compensate for the pivot's location so that the user's location will always correspond to his real location inside the node?
Or is there another way to remove the pivot, but leave the rotation that I accomplished with the pivot and freeze the node in its new position/rotation?
Thanks!