I\'m using ARKit and trying to get the position of the camera as a rotation and (x,y,z) coordinates in real world space. All I can manage to get is a matrix_float4x4
A good way to figure this out is to learn about 4x4 matrices as they are really the basis for all 3D visualization and mathematics.
Some resources to get you started:
Two ways you can get the position of the camera:
By using the currentFrame property of session you can get the transform of the camera and then use that to get the position:
matrix_float4x4 cameraTransform = self.sceneView.session.currentFrame.camera.transform;
SCNVector3 cameraPosition = SCNVector3Make(cameraTransform.columns[3].x,
cameraTransform.columns[3].y, cameraTransform.columns[3].z);
Or get the position of the camera using the pointOfView property of the sceneView:
SCNVector3 cameraPosition = self.sceneView.pointOfView.worldPosition;
I'm using matrix_float4x4 extension for that:
extension matrix_float4x4 {
func position() -> SCNVector3 {
return SCNVector3(columns.3.x, columns.3.y, columns.3.z)
}
}
Using:
let position = transform.position()
Or you can convert position directly in code:
let position = SCNVector3(
transform.columns.3.x,
transform.columns.3.y,
transform.columns.3.z
)