HomeiOS Developmentios - Easy methods to get world place coordinates from an ARImageAnchor?

ios – Easy methods to get world place coordinates from an ARImageAnchor?


I’ve a picture positioned as in ARAnchor in a ARKit scene. My requirement is to calculate the place of this ARImageAnchor relative to the actual world. At present what i get is the XYZ place of the ARImageAnchor relative to the gadget digital camera. So if i transfer the digital camera round, the XYZ values change. But when I can get the place relative to the actual world, the XYZ shouldn’t change even when I transfer the digital camera round. Beneath is my pattern code. Is that this potential ible with ARKit? or any workarounds could be actually appreciated.

override func viewDidLoad() {
    tremendous.viewDidLoad()
    
    // Set the view's delegate
    sceneView.delegate = self
    
    // Present statistics akin to fps and timing info
    sceneView.showsStatistics = false
    
    // Create a brand new scene
    let scene = SCNScene()
    
    // Set the scene to the view
    sceneView.scene = scene
}

override func viewWillAppear(_ animated: Bool) {
    tremendous.viewWillAppear(animated)
    
    // Create a session configuration
    let configuration = ARImageTrackingConfiguration()
    
    // Outline reference photos
    guard let referenceImages = ARReferenceImage.referenceImages(inGroupNamed: "AR Sources", bundle: Bundle.most important) else {
        fatalError("Did not load the reference photos")
    }
    
    // Specify the pictures to trace
    configuration.trackingImages = referenceImages
    
    // Run the view's session
    sceneView.session.run(configuration)
}

  func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
    
    guard let imageAnchor = anchor as? ARImageAnchor else {
        return
    }
    
    // Location of the picture in 3D area
    let hitLocation = SCNVector3(imageAnchor.rework.columns.3.x,
                                 imageAnchor.rework.columns.3.y,
                                 imageAnchor.rework.columns.3.z)

    print("preliminary Hit location: (hitLocation)")


}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments