本文介绍了理解ARKit中的坐标空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读有关的所有Apple指南,并观看。但我无法理解如何绑定系统:

I've read all Apple guides about ARKit, and watched a WWDC video. But I can't understand how do coordinate systems which are bind to:


  1. 真实世界

  2. 设备

  3. 3D场景

相互连接。

我可以添加一个对象,例如 SCNPlane

I can add an object, for example a SCNPlane:

let stripe = SCNPlane(width: 0.005, height: 0.1)
let stripeNode = SCNNode(geometry: stripe)
scene.rootNode.addChildNode(stripeNode)

这将产生一个白色条纹,无论当时设备如何定向,它都将垂直定向。这意味着坐标系以某种方式受到引力的束缚!但是,如果我尝试打印 upAxis 属性都是一样的。我还尝试打印 stripeNode.worldTransform ,它也不会改变。

This will produce a white stripe, which will be oriented vertically, no matter how the device will be oriented at that moment. That means the coordinate system is somehow bound to the gravity! But if I try to print upAxis attribute of the SCNScene per frame, it will be the same, no matter how I rotate the iPhone. I also tried to print stripeNode.worldTransform and it also doesn't change.

理解<$的任何帮助c $ c> ARKit 欢迎坐标。

推荐答案

默认情况下,ARKit中的世界坐标系基于ARKit对您设备周围真实世界的理解。 (是的,由于该设备的运动感应硬件,它是。 )

By default, the world coordinate system in ARKit is based on ARKit's understanding of the real world around your device. (And yes, it's oriented to gravity, thanks to the device's motion sensing hardware.)

同样默认情况下,使用 ARSCNView 在ARKit会话中显示SceneKit内容时,坐标系为场景的 rootNode 与ARKit世界坐标系匹配。这意味着无论您如何移动设备,场景空间中的向上始终与真实世界中的向上相同。

Also by default, when you use ARSCNView to display SceneKit content in an ARKit session, the coordinate system of the scene's rootNode is matched to the ARKit world coordinate system. That means that "up" in scene space is always the same as "up" in real-world space, no matter how you move your device.

这种坐标系匹配的好处在于你可以非常轻松地将SceneKit的东西放在真实的空间中。您的代码在 0,0,0 处放置一个白色条纹,因为您没有明确地给它一个位置。在ARKit会话中, 0,0,0 是您启动会话时设备的位置...因此您应该能够运行该代码然后执行向后退一步,查看您的。

The great thing about this matching of coordinate systems is that you can put SceneKit things in real-world space very easily. Your code places a white stripe at 0, 0, 0 because you didn't explicitly give it a position. In an ARKit session, 0, 0, 0 is the position of your device when you started the session... so you should be able to run that code and then take a step backwards to see your white stripe.

简而言之,ARKit的坐标系模型如下: 世界已修复,您的设备/摄像机在其中移动。

In short, the coordinate system model for ARKit is this: The world is fixed, and your device/camera moves within it.

这意味着如果你想对设备的当前位置/方向做任何事情,你需要转换到相机空间。

This means that if you want to do anything relative to the current position/orientation of the device, you need a conversion to camera space.

如果您正在使用SceneKit,那很简单: view.pointOfView 为您提供SceneKit摄像机节点,因此您可以... 。

If you're working with SceneKit, that's easy: view.pointOfView gives you the SceneKit camera node, so you can...


  • 将子节点添加到该节点,并且当它移动时它们将保持连接到相机(例如HUD元素,或者如果你正在制作类似Minecraft的话,可能是镐)

  • 使用相机节点作为目标以使场景中的其他内容在移动时与相机交互(例如让游戏角色看相机)

  • 使用相机节点的变换(或用于访问变换部分的各种便利属性)来定位场景中的其他内容(例如 node.position = view.pointOfView.simdWorldFront + float3(0,0,-0.5)将一个节点放在摄像机所在的前方50厘米处。)

  • add child nodes to that node, and they'll stay "attached" to the camera as you move it (e.g. HUD elements, or maybe a pickaxe if you're making a Minecraft-alike)
  • use the camera node as the target of a constraint to make other content in the scene interact with the camera as you move it (e.g. make a game character look at the camera)
  • use the camera node's transform (or the various convenience properties for accessing parts of the transform) to position other content in your scene (e.g. node.position = view.pointOfView.simdWorldFront + float3(0, 0, -0.5) to drop a node 50 cm in front of where the camera is right now)

这篇关于理解ARKit中的坐标空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 01:21