0
   if (frame.getCamera().getTrackingState() == TrackingState.TRACKING && anchorsts && !placed) {

                Session session = arFragment.getArSceneView().getSession();

                String type = "fwd";
                int distance = 0;
                int nextPoint = 1;
                String[] positions = {"u", "u","r", "r","r", "r", "r", "r", "r", "r"};
                if (turnStatus == null){


                    turnStatus = positions[distance];
                    Log.i("turnStatus", "pos " + positions[distance]);
                }
                float[] rotation = {0, 0, 0, 0};

                do {
                    if (positions[distance].equals("u")) {
                        turnStatus = "u";
                        placeNav(session, new float[]{dx, dy, dz}, rotation, positions[distance]);
                       


                        if (!turnStatus.equals(positions[nextPoint])) {
                            if (positions[nextPoint].equals("r")) {
                                turnDistance = distance;

                       
                            }
                        }
                    } else if (positions[distance].equals("r")){
                        turnDistance ++;
                        turnStatus = "r";
                       
                        placeNav(session, new float[]{turnDistance, -1.5f, -turnDistance}, rotation, positions[distance]);
                        if (!turnStatus.equals(positions[nextPoint])) {
                            if (positions[nextPoint].equals("u")) {
                       
                            }
                        }
                       }
                    distance++;
                    nextPoint ++;
                } while (distance <9);


                placed = true; //to place the arrow just once.

            }

private void placeNav(Session session, float[] pos, float[] rotation, String type) {
  AnchorNode anchorNode = new AnchorNode(anchor);
      
        currentAnchorNode = anchorNode;

        anchorNode.setParent(arFragment.getArSceneView().getScene());

        Node arrow = new Node();
        arrow.setParent(anchorNode);

        if (type.equals("u"))
            arrow.setRenderable(andyRenderable);
        else if (type.equals("r"))
            arrow.setRenderable(andyRenderable);


    }

the above code is used to render a loop of renderables into scene. I need to display only first two renderables and display next renderables while user is moving forward. here the positions array isnused to render objects into scene. Please to help me to implement this

Sancy Devassy
  • 11
  • 1
  • 6

1 Answers1

1

Just create the first two renderable in onCreate method. For creating the other renderable, when the person is moving forward, you should check if the new position of the camera is in front of the previous position of the camera.

Vector3 newCameraPosition = getScene().getCamera().getWorldPosition();
Vector3 direction = Vector3.subtract(newCameraPosition, oldCameraPosition);
Quaternion lookRotation = Quaternion.lookRotation(direction, Vector3.up());
double product = 
(newCameraPosition.x - oldCameraPosition.x) * direction.x + (newCameraPosition.y - oldCameraPosition.y) * direction.y + (newCameraPosition.z - oldCameraPosition.z) * direction.z;
if (product > 0.0) {
    // means camera moved forward
}