I'm currently working on Indoor navigation with ARCore from source to destination place. So i want to load navigation arrows from source to destination place on a horizontal surface(land) parallelly with zero height(not in the air) from surface. I tried many solutions and documentation of ARCore but didn't get the proper and accurate output.
I want to place navigation arrow parallelly to the bottom horizontal surface with accuracy like this enter image description here, but sometimes it's loads inside the surface or not accurate. enter image description here
Can anyone please help me in this case? Here is my function for place object,
public int placeItem(Renderable r, double dist, float angle, float rotation, float height, boolean rotate) {
Session session = fragment.getArSceneView().getSession();
Frame frame = fragment.getArSceneView().getArFrame();
//Get some anchors to anchor our item to
//Get the phone's pose in ARCore
Pose deviceOrientedPose = frame.getCamera().getPose().compose(
Pose.makeTranslation(0.0f, -0.1f, 0.0f));
//Get the phone's pose in relation to the real world
float heading = visualAnchorCompass.getHeading(session, frame, false);
float cameraFrame = VisualAnchorCompass.getAngleFromPose(deviceOrientedPose);
//Rotate around y axis...
float offset_by = (heading + cameraFrame) % 360;
float from_camera = (rotation - offset_by + 360) % 360;
float rotAngle = (-from_camera + 360) % 360;
Quaternion qt = Quaternion.axisAngle(Vector3.up(), rotAngle);
//Build the node
Anchor anchor = session.createAnchor(deviceOrientedPose);
AnchorNode anchorNode = new AnchorNode(anchor);
anchorNode.setParent(fragment.getArSceneView().getScene());
Node node = new Node();
node.setParent(anchorNode);
node.setRenderable(r);
//Set rotation
if (rotate)
node.setLocalRotation(qt);
//Set angle
float from_camera1 = (angle - offset_by + 360) % 360;
float angrad = ((-from_camera1 + 360) % 360);
Log.d(TAG, "drawing... " + rotation + " intended angle:" + angle + " angrad:" + heading + ",campose" + cameraFrame);
Vector3 pos = new Vector3(-(float) dist * (float) Math.sin(Math.toRadians(angrad)),
0, -(float) dist * (float) Math.cos(Math.toRadians(angrad)));
float[] vec = deviceOrientedPose.getTranslation();
Vector3 camPos = new Vector3(vec[0], vec[1], vec[2]);
Log.d(TAG, "xyz: " + pos.x + "," + pos.z);
pos = Vector3.add(camPos, pos);
node.setLocalPosition(pos);
item_counter++;
items.put(item_counter, node);
return item_counter;
}