问题
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