Posts

Showing posts with the label Arkit
Answer : Set yourself as the ARSession.delegate . Than you can implement session(_:didUpdate:) which will give you an ARFrame for every frame processed in your session. The frame has an camera property that holds information on the cameras transform, rotation and position. func session(_ session: ARSession, didUpdate frame: ARFrame) { // Do something with the new transform let currentTransform = frame.camera.transform doSomething(with: currentTransform) } As rickster pointed out you always can get the current ARFrame and the camera position through it by calling session.currentFrame . This is useful if you need the position just once, eg to move a node where the camera has been but you should use the delegate method if you want to get updates on the camera's position. I know it had been solved but i have a little neat solution for it .. I would prefere adding a renderer delegate method.. it's a method in ARSCNViewDelegate func renderer(_ renderer: ...
Answer : You can use the ARCamera.transform property to get the current transform of your camera. The following code is from Introducing ARKit at WWDC 2017 which you probably want to watch as an introduction. We are using the transform to place a node 10 cm in front of the camera. In Swift: var translation = matrix_identity_float4x4 translation.columns.3.z = -0.1 // Translate 10 cm in front of the camera node.simdTransform = matrix_multiply(currentFrame.camera.transform, translation) In Objective-C matrix_float4x4 translation = matrix_identity_float4x4; translation.columns[3][2] = -0.1; // Translate 10 cm in front of the camera node.simdTransform = matrix_multiply(currentFrame.camera.transform, translation)