我想在当前摄像机视图的边界中放置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)
答案 0 :(得分:0)
您可以使用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
...
}