hitTest

Hi,


what is the difference between ARSCNView.hitTest and ARFrame.hitTest? I try to compare the two using a code like this:


guard let currentFrame = self.sceneView.session.currentFrame else { return }

let npos = CGPoint(x: position.x / (self.sceneView.bounds.width - 1), y: position.y / (self.sceneView.bounds.height - 1))

for r in currentFrame.hitTest(npos, types: .existingPlaneUsingExtent) {

print("A: ", r.localTransform.translation, r.anchor!.identifier)

}

for r in sceneView.hitTest(position, types: .existingPlaneUsingExtent) {

print("B: ", r.localTransform.translation, r.anchor!.identifier)

}


The result is e.g.:

A: float3(-0.238115, 0.0, 0.419882) 51B89AB3-0100-0000-AE47-654CFEFFFFFF

B: float3(0.123911, 0.0, 0.0762889) 51B89AB3-0100-0000-AE47-654CFEFFFFFF

or

A: float3(0.0538981, 0.0, -0.46789) 51B89AB3-0100-0000-AE47-654CFEFFFFFF

B: float3(-0.377929, 0.0, -0.0795063) 51B89AB3-0100-0000-AE47-654CFEFFFFFF


So, the anchor is the same, but the points differ. The translation between the two is not a constant vector, so it is not just a shift of the origin of the coordinate system. So, in what coordinate system are these results? Why are they different? A similar difference appear if I write out worldTransform instead of localTransform. So which result gives me the correct position in the world?


Another issue is that the 3D point found by hitTest and its anchor should have the same y coordinate, as the point is on the plane. It is the case when ARWorldTrackingConfiguration.worldAlignment is set to .gravity. However, if I change it to .gravityAndHeading, the y coordinate of the 3D point found differs from the plane anchor's y coordinate, and the difference can be several cm-s. Can someone explains what's the reason of it?


Thanks.