I\'m experimenting with the vertical plane, and I\'m trying to place a node on a wall with the correct rotation based on that vertical plane.
here\'s the ARHitTest
Is this what your looking for? Here I am using the screen center for the CGPoint value, but you can use touch etc:
func addObjectToScreen() {
if let hit = self.sceneView?.hitTest(self.viewCenter, types: [.existingPlaneUsingExtent]).last {
let hitTestTransform = SCNMatrix4(hit.worldTransform)
let vector = SCNVector3Make(hitTestTransform.m41, hitTestTransform.m42, hitTestTransform.m43)
node.position = vector
return
}
}
Update: If you want to rotation of the node associated with the Plane couldn't you could get it like so:
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
print(node.rotation)
}
Then use it as you need?
Further Update:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
/*
1. Get The Current Touch Location
2. Check That We Have Touched A Valid Node
3. Check That Our Touched Object Is An ARPlane Anchor
*/
guard let touchLocation = touches.first?.location(in: augmentedRealityView),
let hitTest = augmentedRealityView.hitTest(touchLocation, types: .existingPlaneUsingExtent).first,
let planeAnchor = hitTest.anchor as? ARPlaneAnchor
else {
// No Valid Plane Has Been Detected So Hide The Plane Information Label
return
}
//We Have A Valid Plane So Display It's Current Info
guard let anchoredNode = augmentedRealityView.node(for: planeAnchor) else { return }
print(anchoredNode.rotation)
}