【发布时间】:2018-02-01 16:00:10
【问题描述】:
在 ARKit/SceneKit 中,当用户点击按钮时,我想对我的节点施加一个脉冲。我希望冲动来自当前用户的角度。这意味着节点将远离用户的视角。由于这段代码,我能够获得当前的方向/方向:
func getUserVector() -> (SCNVector3, SCNVector3) { // (direction, position)
if let frame = self.sceneView.session.currentFrame {
let mat = SCNMatrix4(frame.camera.transform) // 4x4 transform matrix describing camera in world space
let dir = SCNVector3(-1 * mat.m31, -1 * mat.m32, -1 * mat.m33) // orientation of camera in world space
let pos = SCNVector3(mat.m41, mat.m42, mat.m43) // location of camera in world space
return (dir, pos)
}
return (SCNVector3(0, 0, -1), SCNVector3(0, 0, -0.2))
}
通过https://github.com/farice/ARShooter/blob/master/ARViewer/ViewController.swift#L191
我创建了一个任意的 SCNVector。它包含关于多高(Y 轴)、向左或向右多少以及应用于节点的向前多少的信息。
我想将我的 SCNVector3 转换/翻译为来自相机的方向/方向。
意思是,我有
let (direction, position) = self.getUserVector()
let force = SCNVector3(x: 1.67, y: 13.83, z: -18.3)
如何从direction 的位置/来源应用force?
【问题讨论】:
标签: ios swift 3d scenekit arkit