你如何使用 ARKit Swift 将物体附加到你的相机位置? [英] How do you attach an object to your camera position with ARKit Swift?

查看:42
本文介绍了你如何使用 ARKit Swift 将物体附加到你的相机位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有移动的物体,我希望它们能够与玩家发生碰撞.我有能力通过当时获得我当前的位置/方向来从我身上发射物体,但我不明白如何将一个物体附加到我身上,它会一直跟随我的位置.

I have moving objects which I want to have be able to collide with me the player. I have the ability to launch objects from me by getting my current position/direction at that time, but I do not understand how to attach an object to me which will follow my positioning at all times.

推荐答案

在 SceneKit 中,可以在场景中拥有位置的一切都是(附加到)一个节点.这不仅包括可见物体,还包括光源和相机.当你使用 ARSCNView 时,仍然有一个 SceneKit 相机,但 ARKit 控制它的位置/方向.

In SceneKit, everything that can have a position in the scene is (attached to) a node. That includes not just visible objects, but also light sources and cameras. When you use ARSCNView, there's still a SceneKit camera, but ARKit controls its position/orientation.

SceneKit 节点创建一个层次结构:每个节点的位置(和方向等)都相对于其父节点.如果父节点在场景内移动,它的子节点也会随之移动,以便它们保持相同的父节点相对位置.因此,如果您希望某些内容始终相对于相机保持相同的位置,则应该将该内容设为相机节点的子节点.

SceneKit nodes create a hierarchy: every node's position (and orientation etc) are relative to its parent node. If the parent node moves within the scene, its children move along with it so that they keep the same parent-relative positions. So, if you want something to always keep the same position relative to the camera, you should make that content a child of the camera node.

即使在你不自己创建相机的场景中——比如当 SceneKit 和 ARKit 为你管理相机时——你可以使用视图的 pointOfView 属性.(注意:ARSCNViewSCNView 的子类,其大部分有用的 API 由 SCNSceneRenderer 协议.)

Even in scenes where you don't create a camera yourself — such as when SceneKit and ARKit manage the camera for you — you can get the node containing the current camera with the view's pointOfView property. (Note: ARSCNView is a subclass of SCNView, most of whose useful API is defined by the SCNSceneRenderer protocol.)

您可能需要等到会话开始运行才能访问 ARKit 管理的相机节点.

You may have to wait until the session starts running to access the ARKit-managed camera node.

这篇关于你如何使用 ARKit Swift 将物体附加到你的相机位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆