为了将物体放在相机前面,我看到有两种方法:使用 camera.transform
和 pointOfView
camera.transform 来自 SCNView
和 scnView.session.currentFrame.camera.transform
https://developer.apple.com/documentation/arkit/arcamera
The position and orientation of the camera in world coordinate space.
下面是使用方法
var translation = matrix_identity_float4x4
translation.columns.3.z = -2
node.simdTransform = matrix_multiply(currentFrame.camera.transform, translation)
pointOfView 来自 SCNView
和 scnView.pointOfView
https://developer.apple.com/documentation/scenekit/scnscenerenderer/1523982-pointofview
The node from which the scene’s contents are viewed for rendering
下面是使用方法,使用convertPosition
转换为世界坐标
let camera = scnView.pointOfView!
let position = SCNVector3(x: 0, y: 0, z: -2)
node.position = camera.convertPosition(position, to: nil)
这两个有什么区别?两者似乎都指的是相机
最佳答案
session
属性由 ARSCNView
公开,而不是直接通过 SCNView
。 ARKit 使用其 session 的相机转换来驱动 SceneKit 场景的视角,因此在这种情况下它们是匹配的。但并非每个 SceneKit 应用程序都使用 ARKit,在这种情况下,定位视角是开发人员的责任。
关于ios - camera.transform 和 pointOfView 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49432817/