2

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

在此处输入图像描述

来源 - SceneKit文档

从 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)

在此处输入图像描述

4

1 回答 1

1

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

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
  ...
}
于 2017-06-18T21:06:10.570 回答