在arcore中查找锚定节点与相机当前位置之间的角度

Find angle between anchored node and current position of camera in arcore

一旦 arcore 跟踪开始并发现计划,我想向安迪展示。在我将节点锚定在附近某处之后,我离开了安迪。

我在屏幕底部有一个箭头,我想 rotate/point 当我移开相机时箭头始终指向锚定节点。

我已经完成了剩下的事情,但无法找到我需要继续旋转箭头图像以使其始终指向锚定节点的角度。

我在 android studio 中使用 sceneform 框架,arcore sdk。

因此,根据您的评论,您必须做几件事,我会为您分解一下:
1.猫的轨迹位置(A点)
2. 摄像机(设备)的跟踪位置 - 这应该可以从 ARCore API 访问。 (B点)
3. 现在你必须得到方向,给定前面提到的两个点 A,B 当你从 B 中减去 A 时你得到方向矢量(可以归一化以便稍后简化,甚至你可以将它减少到只是 2d 矢量而不是 3d)。如果在 3d 中遇到问题,请自己在 2d 中想象一下。
4. 这部分是你的选择,你可以计算角度差或比较旋转并决定你的 arrow/pointer 到猫的样子。 Left/right指针或指南针样式的东西,由您选择。

以下是我用来实现预期目标的代码:

 Vector3 cameraPosition = arSceneView.getScene().getCamera().getWorldPosition();
 Vector3 catPosition = catNode.getWorldPosition();
 Vector3 direction = Vector3.subtract(cameraPosition, catPosition);
 Quaternion lookRotation = Quaternion.lookRotation(direction, Vector3.up());
 catNode.setWorldRotation(lookRotation);