ARKit 1.5 how to get the rotation of a vertical plane

后端 未结 1 684
野趣味
野趣味 2021-01-02 11:15

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

相关标签:
1条回答
  • 2021-01-02 11:32

    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)
    
     }
    
    0 讨论(0)
提交回复
热议问题