Rotation of entire AR session coordinate system

I am trying to do something that sounds simple enough to me, but apparently is not. I keep Googling to try to find some discussion or some help on it but I must not be using the correct words or phrases to search on. Any help is greatly appreciated. I am also unsure where I should actually post this to be less annoying and to get proper help.

Basically I am trying to apply a rotation to my entire AR session so that the AR session world coordinates line up with north-west-up of the real world.

I have a function that takes in real-world latitude/longitude/altitude coordinates and returns X-Y-Z. These X-Y-Z values seem to work correctly. That is, when a lat/lon is north of me the sphere I draw is on the positive X-axis (of the session world axis), and a lot/lon to the west of me is on the positive Y-axis. So far, so good.

The next step is to get the AR Session world coordinate axes to line up with the real world north-west-up axes. From the seeing the coordinate system when the session starts (X and Z in the horizontal plane, Y up) it seems like I should just do two simple rotations: -pi/2 around X to get Y in the horizontal plane and Z up, followed by some rotation about the new Z to get X pointing north.

I have an ARSCNView inside of my UIViewController. I have a configuration:
private let configuration = ARWorldTrackingConfiguration()
And in viewDidLoad() I set debug options to show the session’s coordinates
self.asSceneView.debugOptions = [ARSCNDebugOptions.showWorldOrigin, … ]

Later, via a button tap, I call a func that 1) gets the camera transform, 2) applies a rotation to the transform, and 3) uses the resultant rotated transform to set the new world origin.
guard let transform = self.arSceneView.session.currentFrame?.camera.transform else {… }
let newMat = SCNMatrix4Rotate( SCNMatrix4( transform ), minus90, 1, 0, 0) // minus90 is in radians
self.arSceneView.session.setWorldOrigin( relativeTransform: sind_float4x4( newMat) )

Question 1: camera.transform vs setWorldOrigin?
Besides the fact that I get some weirdly rotated/translated world axes I don’t get the connection/relationship between the camera transform and the worldOrigin? I get and print the camera.transform throughout this process and it doesn’t change — even after setting the worldOrigin with a different transformation matrix. What is the connection and is there a different way to apply a rotation?

Question 2: When is camera transform set and how do you know?
All the way through viewWillLoad(0 and through viewDidLoad() I check on …camera.transform it is always nil. I added a button to check it (and rotate it) after the session starts. I’m sure there is a better way. When is it set and what is the correct way to know when it is set?

Question 3: Any other advice on rotation the AR session?

Thank you

This topic was automatically closed after 166 days. New replies are no longer allowed.