Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何在ARkit中获取场景的真实世界中心坐标_Swift_Arkit - Fatal编程技术网

Swift 如何在ARkit中获取场景的真实世界中心坐标

Swift 如何在ARkit中获取场景的真实世界中心坐标,swift,arkit,Swift,Arkit,在ARKit中,如果我有ARSCNView,如何获得当前场景的真实世界中心坐标?我正在使用Swift作为编程语言。您可以使用这样的手势来获得接触点 // 1. @objc func tapped(recognizer :UIGestureRecognizer) { // Get exact position where touch happened on screen of iPhone (2D coordinate) let touchPosition = recognizer

在ARKit中,如果我有ARSCNView,如何获得当前场景的真实世界中心坐标?我正在使用Swift作为编程语言。

您可以使用这样的手势来获得接触点

// 1.
@objc func tapped(recognizer :UIGestureRecognizer) {
    // Get exact position where touch happened on screen of iPhone (2D coordinate)
    let touchPosition = recognizer.location(in: sceneView)

    // 2.
    // Conduct a hit test based on a feature point that ARKit detected to find out what 3D point this 2D coordinate relates to
    let hitTestResult = sceneView.hitTest(touchPosition, types: .featurePoint)

    // 3.
    if !hitTestResult.isEmpty {
        guard let hitResult = hitTestResult.first else {
            return
        }
        print(hitResult.worldTransform.columns.3)
    }
}
您可以获得积分位置

将对象的位置设为add=SCInvector3(hitResult.worldTransform.columns.3.x,hitResult.wor

ldTransform.columns.3.y,hitResult.worldTransform.columns.3.z)

Dong Nguyen

希望你今天过得愉快:-)

我会尽力帮你(只是不确定你到底在找什么)…但我想我有一些线索;-)

我会给你一些提示,看看我能不能帮上忙:

问题是: “如何在arkit中获取场景的真实世界中心坐标?”

1) 如果您询问真实世界坐标系的中心: 以下是您的看法:

如何在代码中使用: 在viewDidLoad函数中

sceneView.debugOptions = [ARSCNDebugOptions.showWorldOrigin]
如何获得世界原点位置? 如果我理解您的要求,ARKit的真实世界中心是会话配置首次运行时设备的位置和方向。坐标是(0,0,0)。 [如果你觉得没有意义,请让我知道(我知道我跳过了很多,但在iPad上打字)。]

下面是如何在真实世界中心定位物体(我们知道世界中心位于坐标(0,0,0))

如何在代码中使用

func addBox() {
// create a SceneKit box shape
    let box = SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0)

// create a SceneKit node 
    let boxNode = SCNNode()
// attach the shape to the node
    boxNode.geometry = box
// give node a position ( this will be the real world center!
    boxNode.position = SCNVector3(0, 0, 0)

// SCNVector3 you can think of for now as SCNVector3(x,y,z)
//https://developer.apple.com/documentation/scenekit/scnvector3

// create a SceneKit scene 
    let scene = SCNScene()

// add the node as a child of the rootNode
// the root node defines the origin of the world coordinate systems for SceneKit.
//Apple Documentation states:"The world coordinate system of the view's    
//SceneKit scene directly responds to the AR world coordinate system    
//established by the session configuration."
// so ARKit and SceneKit world coordinate systems match :-)

    scene.rootNode.addChildNode(boxNode)

//add the SceneKit scene to sceneView
    sceneView.scene = scene
}
所以我的第一个答案是保持定位为一个变量。 如何在代码中使用:

let ARWorldOrigin = SCNVector3(0, 0, 0)
用这个来做你所有的测量

1) 你是说物理屏幕的中心吗

2) 你是说摄像机视锥的中心吗 (请尝试此stackflow页面以获取提示:

3) 请遵循此问题的所有链接:

我希望我能在某种程度上得到帮助并理解您的问题:

祝你今天愉快! 希望ARkit编程

我们都是通过了解我们所知道的来学习的


Smartdog

第一部分看起来像是来自的逐字复制品看看如何阅读别人写的参考资料。特别是,在你的答案中添加到原始来源的链接。我感兴趣的是场景的中心点,而不是用户点击的点。谢谢你的回答。想象一下AR世界起源简化为ARSCNView中心的位置。