在屏幕中心的 AR 中创建锚点,并像魔术计划一样将其相对于相机移近或移远

问题描述

我想创建一个与magicplan一样的应用程序,并想绘制与magicplan一样的连续绿色垂直管道,随着相机移动而变近和变远。

我尝试了下面的代码,但它使节点保持在屏幕中心。 请帮助我如何实现这一目标。

                Ray ray = arFragment.getArSceneView().getScene().getCamera().screenPointToRay(arFragment.getArSceneView().getWidth() / 2,arFragment.getArSceneView().getHeight() / 2);
                Vector3 localpos = ray.getPoint(1f);
                Quaternion localRotation = arFragment.getArSceneView().getScene().getCamera().getLocalRotation();
                Vector3 localScale = new Vector3(0.3f,0.3f,0.3f);
                Frame frame = arFragment.getArSceneView().getArFrame();
                Vector3 pos;
                pos = Vector3.add(ray.getorigin(),ray.getDirection());

                Pose pose = Pose.makeTranslation(pos.x,pos.y,pos.z);

                anchor = arFragment.getArSceneView().getSession().createAnchor(pose);
                anchorNode = new AnchorNode(anchor);
                anchorNode.setParent(arFragment.getArSceneView().getScene());
                TransformationSystem transformationSystem = arFragment.getTransformationSystem();
                node = new TransformableNode(transformationSystem);
                node.setRenderable(cylinderRenderable2);
                node.setParent(anchorNode);
                node.setLocalPosition(localpos);
                node.setLocalRotation(localRotation);
                node.setLocalScale(localScale);
                node.select();

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)