我在ARSKView中创建我的锚点和2d节点,如下所示:
func displayToken(distance: Float) {
print("token dropped at: \(distance)")
guard let sceneView = self.view as? ARSKView else {
return
}
// Create anchor using the camera's current position
if let currentFrame = sceneView.session.currentFrame {
removeToken()
// Create a transform with a translation of x meters in front of the camera
var translation = matrix_identity_float4x4
translation.columns.3.z = -distance
let transform = simd_mul(currentFrame.camera.transform, translation)
// Add a new anchor to the session
let anchor = ARAnchor(transform: transform)
sceneView.session.add(anchor: anchor)
}
}
func view(_ view: ARSKView, nodeFor anchor: ARAnchor) -> SKNode? {
// Create and configure a node for the anchor added to the view's session.
if let image = tokenImage {
let texture = SKTexture(image: image)
let tokenImageNode = SKSpriteNode(texture: texture)
tokenImageNode.name = "token"
return tokenImageNode
} else {
return nil
}
}
这将它准确地放置在相机前面的给定距离(z) . 我还想做的是为物体取一个纬度/经度,以度为单位计算角度或航向,并最初从相机中以此角度放下锚点/节点 . 我目前通过使用GMSGeometryHeading方法获取 Headers ,该方法获取用户当前位置,以及目标位置以确定 Headers . 因此,当放下锚点时,我想将其朝向目标位置的纬度/经度朝向正确的方向 . 如何使用SpriteKit / ARKit实现这一目标?
1 回答
你能澄清一下你的问题吗?
也许以下几行可以帮助你作为例子 . 在那里,cameraNode使用基本几何公式移动,根据x和y坐标中的角度(以欧拉为单位)倾斜移动
如果您希望物体落在相机前面,并且坠落的长度取决于度数,只需计算几何公式“Tan A = a / b”中的“a”值并更新节点的“演示” . position.y”
我希望这有帮助