gpt4 book ai didi

ios - ARKit 如何根据地平线而不是相机方向定位节点?

转载 作者:行者123 更新时间:2023-11-28 05:41:28 26 4
gpt4 key购买 nike

当我使用 ARKit (ARSKView) 添加新节点时,对象基于设备相机定位。因此,如果您的手机面朝下或倾斜,物体也会朝那个方向。我怎样才能将物体放置在地平线上?

enter image description here

最佳答案

为此,在创建新节点后,立即使用 worldOrientation 实例属性来控制节点相对于场景世界坐标空间的方向。

var worldOrientation: SCNQuaternion { get set }

This quaternion isolates the rotational aspect of the node's worldTransform matrix, which in turn is the conversion of the node's transform from local space to the scene's world coordinate space. That is, it expresses the difference in axis and angle of rotation between the node and the scene's rootNode.

let worldOrientation = sceneView.scene.rootNode.worldOrientation

yourNode.rotation = worldOrientation /* X, Y, Z, W components */

附言(当你更新你的问题时) :

如果您使用 SpriteKit ,您在 ARSKView 中生成的 2D Sprite 始终面向相机。因此,如果相机围绕真实场景中的某个确定点移动,则所有 Sprite 都必须围绕其枢轴点旋转,仍然面向相机。

没有什么能阻止您同时使用 SceneKit 和 SpriteKit

关于ios - ARKit 如何根据地平线而不是相机方向定位节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56588218/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com