在墙上对齐模型

时间:2018-09-13 20:20:07

标签: rotation arcore

我有一个相对于检测到的飞机的hitResult:

arFragment.setOnTapArPlaneListener(
    (HitResult hitResult, Plane plane, MotionEvent motionEvent) -> {...})

我想将模型锚定到平面上并使其始终朝上(天花板):

Anchor anchor = plane.createAnchor(plane.getCenterPose());
AnchorNode anchorNode = new AnchorNode(anchor);
anchorNode.setRenderable(model);

问题在于模型有时会随机旋转。有时,它不会指向天花板:它会旋转180度,90度或随机旋转。

(至少所有这些在模拟器中)。

1 个答案:

答案 0 :(得分:0)

您可以使用

之类的东西
boolean isVerticalPlane = plane.getType() == Plane.Type.VERTICAL;

setOnTapArPlaneListener中进入ArFragment

最终代码为:

ArFragment arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.ux_fragment);

arFragment.setOnTapArPlaneListener(new BaseArFragment.OnTapArPlaneListener() {
            @Override
            public void onTapPlane(HitResult hitResult, Plane plane, MotionEvent motionEvent) {
                boolean isVerticalPlane = plane.getType() == Plane.Type.VERTICAL;
            }
        });