问题
我希望以下函数返回由轻按手势处理的点的世界坐标。我已经正确地实现了它(使用一些在线资源)来处理框架的中心点,但是我无法在屏幕上移动这个点。
试图
这是 的完整注释和工作代码getScreenCoordinates
,它返回一个元组,其中包含 (0) 屏幕坐标的方向向量和 (1) 屏幕坐标的位置向量。screenCoord
问题是通过参数传入的中心以外的点进行这项工作。
private func getScreenCoordinates(screenCoord:CGPoint) -> (SCNVector3, SCNVector3) { // (direction, position)
if let frame = self.canvasView.session.currentFrame {
let mat = SCNMatrix4(frame.camera.transform) // 4x4 transform matrix describing camera in world space
let direction = SCNVector3(-1 * mat.m31, -1 * mat.m32, -1 * mat.m33) // orientation of camera in world space
let position = SCNVector3(mat.m41, mat.m42, mat.m43) // location of camera in world space
return (dir, position)
}
return (SCNVector3(0, 0, -1), SCNVector3(0, 0, -0.2))
}
所需的解决方案
提供一个修改后的getScreenCoordinates
函数,该函数返回相同的数据类型,但它不是获取相机框架中心点的世界坐标,而是获取screenCoord
.