tse
tse

Reputation: 6069

How to monitor my current position in ARCore and Sceneform?

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?

Upvotes: 1

Views: 3557

Answers (2)

Ebad Syed
Ebad Syed

Reputation: 78

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.

Upvotes: 3

AlgoRyan
AlgoRyan

Reputation: 548

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.

Upvotes: 0

Related Questions