So I have successfully detected the planes. My goal is to measure distance of height between camera node and detected plane when phone is flat rotated (rotated like plane (horizontally)) but it is not accurate result because of phone angle i.e some time it is not flat like slightly up or down.
Here is what I tried.
guard let camera = self.sceneView.session.currentFrame?.camera, let plane = self.sceneView.hitTest(self.sceneView.center, types: [.existingPlaneUsingGeometry]).first else {
return
}
var anchorPosition = plane.anchor?.transform.columns.3
var cameraPosition = camera.transform.columns.3
anchorPosition?.x = cameraPosition.x
anchorPosition?.z = cameraPosition.z
let cameraToAnchor = cameraPosition - (anchorPosition ?? float4())
// and here’s just the scalar distance
let distance = length(cameraToAnchor)
Any one can help me to improve it. Or how can I take camera rotation in account. as Plane is rotated 90 degree in X. So I need to match that rotation to of camera to get exact value