是否可以用一条线连接两个标记位置?我有两个位置标记:
LocationMarker point1 = new LocationMarker(
20.501925,
44.792181,
new AnnotationRenderer("point1 ")
);
LocationMarker point2 = new LocationMarker(
20.502972,
44.790873,
new AnnotationRenderer("point2 ")
);
有什么例子吗?我使用ArCore Location
答案 0 :(得分:0)
下面的代码将在两点之间绘制一条线-这些点与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);
}
);
}