How to monitor my current position in ARCore and Sceneform?

自古美人都是妖i 提交于 2020-03-26 03:17:09

问题


In application with ARCore and Sceneform I need somehow monitor my (device, really) movement in ARCore space?

As result I want to draw a ray from selected point (Anchor/AnchorNode) through my current position, or to calculate distance from selected point to here, and update them during movement. I have ideas, how to calculate or draw, but how to get updates?


回答1:


First setup an On Update listener

fragment.getArSceneView().getScene().addOnUpdateListener(frameTime -> {
        fragment.onUpdate(frameTime);
        onUpdate();
    });

In OnUpdate() call Camera.getDisplayOrientedPose()

Frame frame = fragment.getArSceneView().getArFrame();

    Camera camera = frame.getCamera();

    if (camera.getTrackingState() == TrackingState.TRACKING){
        Pose CameraPose = camera.getDisplayOrientedPose();
    }

As you move around your Camera Pose will keep getting updated.




回答2:


In the BaseArFragment#onUpdate() method you can acquire the Camera object by calling ArFragment#getArSceneView(), ArSceneView#getArFrame(), and Frame#getCamera().

override fun onUpdate(frameTime: FrameTime?) {
    super.onUpdate(frameTime)
    doSomething(arSceneView.arFrame?.camera?.pose)
}

This Camera is a Node object that tracks the position of the viewing device, and has a Pose object that contains the positional and rotational information you need.



来源:https://stackoverflow.com/questions/53707718/how-to-monitor-my-current-position-in-arcore-and-sceneform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!