2

I will like to place 2 lines in the bounds of the current camera view as flow:

enter image description here

Source - SceneKit docs

From the ARKit docs, I understand that I need the projectionMatrix, but how can I calculate the diff from "zNear" to "zFar" and x\y?

I'm starting with this code:

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

and for the left one i will probably need

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

But I failed when trying calculating rightboxNode.position:

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

enter image description here

Elydasian
  • 2,016
  • 5
  • 23
  • 41
Bar
  • 603
  • 1
  • 7
  • 19

1 Answers1

1

You can use a SCNSceneRenderer to unproject the bounds of your screen in the camera space:

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
  ...
}
Guig
  • 9,891
  • 7
  • 64
  • 126