0

I implement an app which place AR labels at specific gps location with ARCore-Location(https://github.com/appoly/ARCore-Location).The logic is that create anchor Node based on the gps location and the location of camera:

`

            double rotationRadian = Math.toRadians(rotation); //rotation is the angle between the bearing of the specific gps location and camera's location and the azimuth of the camera.

            float zRotated = (float) (z * Math.cos(rotationRadian));
            float xRotated = (float) -(z * Math.sin(rotationRadian));
            float y = frame.getCamera().getDisplayOrientedPose().ty() + (float) heightAdjustment;    
            Pose translation = Pose.makeTranslation(xRotated, y, zRotated);         
            Anchor newAnchor = mSession.createAnchor(
                frame.getCamera()
                        .getDisplayOrientedPose()
                        .compose(translation)
                        .extractTranslation()
            );

           marker.anchorNode = new LocationNode(newAnchor, marker, this);
           marker.anchorNode.setScalingMode(LocationMarker.ScalingMode.GRADUAL_FIXED_SIZE);
           marker.anchorNode.setParent(mArSceneView.getScene());
           marker.anchorNode.addChild(mLocationMarkers.get(i).node); //add the node presenting the AR labels.
           marker.node.setLocalPosition(Vector3.zero()); 

`

then in the Update() of the anchorNode,scale and rotate the node presenting the ar label:

`

        final Vector3 cameraPosition = getScene().getCamera().getWorldPosition();
        Vector3 direction = Vector3.subtract(cameraPosition, n.getWorldPosition());
        n.setWorldPosition(new Vector3(n.getWorldPosition().x, getHeight(), n.getWorldPosition().z));
        Quaternion lookRotation = Quaternion.lookRotation(direction, Vector3.up());
        n.setWorldRotation(lookRotation);
        n.setWorldScale(new Vector3(scale, scale, scale));

`

The code set an interval(which defaults as 5 seconds) after which the session will refresh the anchorNode(detach the old and create the new).

I log out the world positions of anchorNode and node, and find that during the interval,these values do not change,but when i move the phone(do not change the pose and just hold the phone and walk straight on the path) the AR labels move parallel with the phone(it seems that the labels walk as well but are not sticked on the screen).

While the world position of the anchorNode change(maybe after the interval),it is obvious that the labels pop on the screen(not move parallel with the phone).

I want to achieve the performance that when I hold the phone and walk,the ar label does not move parallel with the camera but stays where it should be and looks like it is right here in the real world(it does not change the position relative to the real object in the real world).

I guess the reason why the ar label moves parallel with the camera when the world positions of the anchorNode do not change is that the anchor is created based on the camera,and when the AR session understands the surrounding environment,the node moves parallel with the camera to keep the relationship between the anchor and the camera.But when i try to create the anchorNode at an absolute world position,it has the same situation.

Then I find a description like this: Adding ARAnchor objects to a session is effectively about "labeling" a point in real-world space so that you can refer to it later. The point (1,1,1) (for example) is always the point (1,1,1) — you can't move it someplace else because then it's not the point (1,1,1) anymore.in How do I programmatically move an ARAnchor? So I understand the anchorNode as it is put at the location just as other real object in the real world, then I use the setLocationPosition to add the node to the anchor(the anchor stay static,then the node shold stay static too), or if I use the anchorNode instead of node attached to anchorNode to present the AR labels,maybe i can get what i want.But I try these test,it fails.

I have the question about what's on earth the anchor mean and how I can get what i want to implement. Thanks for any help.

Lily
  • 79
  • 5

1 Answers1

0

I have tried more tests and found that during the interval,the anchors are not updated,while the children move parallel with the camera.While for those anchors created associated with the trackable objects such as plane,the child nodes are static.Also I find some description like this: placing an anchor that is not associated with a Trackable object is usually not a good experience. The trackable object (planes, augmented images, oriented points) are update by ARCore to represent the connections between the real world image and the augmented, virtual images. If you place an anchor in the "air", it will drift and move relative to the real world. (https://github.com/google-ar/sceneform-android-sdk/issues/185)

I try to place ar object based on the anchors associated with the plane and created by hitTest,the rendering node works fine.

I guess this is just the reason,I need more experiments and if it is right,I want to know how to solve the problem.

Lily
  • 79
  • 5