By using the code below, the textView is always face the camera. However, the textview object is keeping shaky all the time. Is that possible to add anchor with the code below to keep the textview object steady and static while rotating the phone?

I have tried to render a textview object in the scene and always facing to camera.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.sceneform_arfragment);
    arFragment.getPlaneDiscoveryController().hide();
    arFragment.getPlaneDiscoveryController().setInstructionView(null);
    arFragment.getArSceneView().getPlaneRenderer().setEnabled(false);

    node = new Node();
    node.setParent(arFragment.getArSceneView().getScene());
    node.setLocalPosition(new Vector3(0f, 0f, -1f));

    ViewRenderable.builder()
            .setView(this, R.layout.card)
            .build()
            .thenAccept(renderable -> {
                node.setRenderable(renderable);
                TextView textView = (TextView) renderable.getView();
                textView.setText("Hello Sceneform");
            });
  arFragment.getArSceneView().getScene().addOnUpdateListener(this::onSceneUpdate);}

private void onSceneUpdate(FrameTime frameTime) {

arFragment.onUpdate(frameTime);
Vector3 cameraPosition = arFragment.getArSceneView().getScene().getCamera().getWorldPosition();
Vector3 cardPosition = node.getWorldPosition();
Vector3 direction = Vector3.subtract(cameraPosition, cardPosition);
Quaternion lookRotation = Quaternion.lookRotation(direction, Vector3.up());
node.setWorldRotation(lookRotation);

}

My expected result is the textview object facing to camera without shaky .

0 Answers