【问题标题】:ARkit - placing objects inside the camera filed of viewARkit - 将物体放置在相机视野内
【发布时间】:2017-11-20 22:20:48
【问题描述】:

我想在当前相机视图的边界中放置 2 条线作为流:

来源 - SceneKit docs

从 ARKit 文档中,我了解到我需要 projectionMatrix,但是如何计算从“zNear”到“zFar”和 x\y 的差异?

我从这段代码开始:

let cameraProjectionMatrix = session.currentFrame?.camera.projectionMatrix 
let cameraPosition = SCNVector3.positionFromTransform(cameraProjectionMatrix)
let rightBoxNode = SCNNode(geometry: SCNBox(...))
rightBoxNode.position = SCNVector3(???)
sceneView.scene.rootNode.addChildNode(rightBoxNode)

对于左边的我可能需要

var leftPos = rightboxNode.position
leftPos.x = rightboxNode.position.x * -1
leftBoxNode.position = leftPos

但我在尝试计算 rightboxNode.position 时失败了:

rightBoxNode.position = SCNVector3(x: x1 ,y: y1 z: zNear)

【问题讨论】:

    标签: swift augmented-reality scenekit projection-matrix arkit


    【解决方案1】:

    您可以使用SCNSceneRenderer 在相机空间中取消投影屏幕边界:

    func renderer(_ sender: SCNSceneRenderer,  updateAtTime time: TimeInterval) {
      let position = sender.unprojectPoint(SCNVector3(0, 0, 0))
      // x, y in screen coordinate space, z in [0, 1] corresponds to [zNear, zFar] in a way that I don't think is proportional
      let node = SCNNode()
      node.position = position
      ...
    }
    

    【讨论】:

    • 使用 projectionPoint 将 3D 点转为 2D 是否有效?
    猜你喜欢
    • 2018-05-12
    • 1970-01-01
    • 1970-01-01
    • 2018-04-03
    • 2015-06-27
    • 1970-01-01
    • 2018-01-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多