通过使用以下代码,textView始终面向相机。但是,textview对象始终保持不稳定状态。是否可以在下面的代码中添加锚点,以在旋转手机时保持textview对象稳定和静态?
我试图在场景中渲染textview对象,并始终面对相机。
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);
}
我的预期结果是面对照相机的textview对象没有晃动。