Skip to content Skip to sidebar Skip to footer

Draw Line Between Location Markers In Arcore?

Is there a possibility to connect two marker locations with a line? I have two location marker: LocationMarker point1 = new LocationMarker( 20.501925, 44.792181, new An

Solution 1:

The code below will draw a line between two points - the points are associated with anchors in Sceneform - this is adapted from the answer here https://stackoverflow.com/a/52816504/334402:

private voiddrawLine(AnchorNode node1, AnchorNode node2) {
      //Draw a line between two AnchorNodesLog.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(), newColor(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(
                                    newVector3(.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 = newNode();
                            nodeForLine.setParent(node1);
                            nodeForLine.setRenderable(model);
                            nodeForLine.setWorldPosition(Vector3.add(point1, point2).scaled(.5f));
                            nodeForLine.setWorldRotation(rotationFromAToB);
                        }
                );

    }

Update: Full working example available here:

Post a Comment for "Draw Line Between Location Markers In Arcore?"