【问题标题】:Draw line between location markers in ArCore?在ArCore中的位置标记之间画线?
【发布时间】:2018-11-19 09:24:14
【问题描述】:

是否有可能用一条线连接两个标记位置?我有两个位置标记:

LocationMarker point1 = new LocationMarker(
    20.501925,
    44.792181,
    new AnnotationRenderer("point1 ")
);

LocationMarker point2 = new LocationMarker(
        20.502972,
        44.790873,
        new AnnotationRenderer("point2 ")
);

有什么例子吗?我用ArCore Location

【问题讨论】:

    标签: java android location arcore


    【解决方案1】:

    下面的代码将在两点之间画一条线——这些点与 Sceneform 中的锚点相关联——这改编自这里的答案https://stackoverflow.com/a/52816504/334402

    private void drawLine(AnchorNode node1, AnchorNode node2) {
          //Draw a line between two AnchorNodes
            Log.d(TAG,"drawLine");
            Vector3 point1, point2;
            point1 = node1.getWorldPosition();
            point2 = node2.getWorldPosition();
    
    
            //First, find the vector extending between the two points and define a look rotation
            //in terms of this Vector.
            final Vector3 difference = Vector3.subtract(point1, point2);
            final Vector3 directionFromTopToBottom = difference.normalized();
            final Quaternion rotationFromAToB =
                    Quaternion.lookRotation(directionFromTopToBottom, Vector3.up());
            MaterialFactory.makeOpaqueWithColor(getApplicationContext(), new Color(0, 255, 244))
                    .thenAccept(
                            material -> {
                                /* Then, create a rectangular prism, using ShapeFactory.makeCube() and use the difference vector
                                       to extend to the necessary length.  */
                                Log.d(TAG,"drawLine insie .thenAccept");
                                ModelRenderable model = ShapeFactory.makeCube(
                                        new Vector3(.01f, .01f, difference.length()),
                                        Vector3.zero(), material);
                                /* Last, set the world rotation of the node to the rotation calculated earlier and set the world position to
                                       the midpoint between the given points . */
                                Anchor lineAnchor = node2.getAnchor();
                                nodeForLine = new Node();
                                nodeForLine.setParent(node1);
                                nodeForLine.setRenderable(model);
                                nodeForLine.setWorldPosition(Vector3.add(point1, point2).scaled(.5f));
                                nodeForLine.setWorldRotation(rotationFromAToB);
                            }
                    );
    
        }
    

    更新:此处提供完整的工作示例:

    【讨论】:

    • 谢谢,如何将位置标记转换为锚模式?
    • @FilipKojic - 你能解释一下你的意思吗,我不确定我理解你的评论问题吗?
    • 我使用了这个代码sn-p,我没有错误。节点存在的值如下:Node(com.google.ar.sceneform.AnchorNode@a8c1dff)。但是看不到线条。提示?
    猜你喜欢
    • 1970-01-01
    • 2018-07-02
    • 2016-02-01
    • 1970-01-01
    • 2014-03-13
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    • 1970-01-01
    相关资源
    最近更新 更多