我正在使用ArCore构建适用于Android(使用Java)的简单导航应用。我开始在Google(https://github.com/google-ar/sceneform-android-sdk/tree/master/samples/hellosceneform)的场景演示中构建我的应用。
当前,应用正在扫描环境中的定位点。用户可以通过点击将对象放置在锚点上。是否可以使用这些找到的锚点自动将例如导航箭头放置在用户面前?箭头应该在用户前方3m-5m处,如果用户要关闭则移动。
我知道如何浏览锚点,并始终删除最后一个锚点。但是我不确定如何将下一个对象自动放置在用户面前。有没有办法做到这一点?
编辑:有没有办法做到这一点?也许从锚点读出位置并寻找所需的距离?
boolean placed = false;
//在onCreate函数中添加更新更新侦听器,因为应用程序需要一到两秒钟才能获取相机的姿势,并且如果您尝试从空姿势构成锚点,则应用程序可能会崩溃。
arFragment.getArSceneView().getScene().addOnUpdateListener(this::onUpdateFrame);
//您可以在更新功能中获得照相机的姿势,从而在照相机前面相应地定位。
private void onUpdateFrame(FrameTime frameTime) {
Frame frame = arFragment.getArSceneView().getArFrame();
// If there is no frame, just return.
if (frame == null) {
return;
}
//Making sure ARCore is tracking some feature points, makes the augmentation little stable.
if(frame.getCamera().getTrackingState()==TrackingState.TRACKING && !placed) {
Pose pos = frame.getCamera().getPose().compose(Pose.makeTranslation(0, 0, -0.3f));
Anchor anchor = arFragment.getArSceneView().getSession().createAnchor(pos);
AnchorNode anchorNode = new AnchorNode(anchor);
anchorNode.setParent(arFragment.getArSceneView().getScene());
// Create the arrow node and add it to the anchor.
Node arrow = new Node();
arrow.setParent(anchorNode);
arrow.setRenderable(arrowRenderable);
placed = true; //to place the arrow just once.
}
}
您将不得不更改箭头的转换方式,以将其准确地设置在相机前面的中央并以正确的方向放置。我希望这可以帮助您入门。干杯!