The code below places a SCNPlane onto the point touched, but the plane is oriented (rotated) to the position that the phone was in when the app started. I would ideally like to orient the Node to a physical wall or to the current orientation of the camera. How is this done with ARKit?
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else {return}
let result = sceneView.hitTest(touch.location(in: sceneView), types: [ARHitTestResult.ResultType.featurePoint])
guard let hitResult = result.last else {return}
let hitTransform = SCNMatrix4.init(hitResult.worldTransform)
let hitVector = SCNVector3Make(hitTransform.m41, hitTransform.m42, hitTransform.m43)
createPlane(position: hitVector)
}
func createPlane(position: SCNVector3) {
let background = SCNNode()
background.geometry = SCNPlane.init(width: 0.12, height: 0.10) // better set its size
background.geometry?.firstMaterial?.diffuse.contents = "odinBW2.jpeg"
background.position = position
sceneView.scene.rootNode.addChildNode(background)
}