Android ArCore. How I can make a rotation for some object along a line










0















I develop an android application with ArCore library. I need make two points, draw a line between they and set a text labels near each line.



The text labels need to be rotated face-to-camera and have positions along the line.



1) Add a line between 2 points:



AnchorNode previousPoint = /* point 0 */
AnchorNode currentPoint = /* point 1 */

Vector3 previousPosition = previousPoint.getWorldPosition();
Vector3 currentPosition = currentPoint.getWorldPosition();

Quaternion rotation = currentPoint.getWorldRotation();

float f1 = new floatcurrentPosition.x, currentPosition.y, currentPosition.z;
float f2 = new floatrotation.x, rotation.y, rotation.z, rotation.w;

Vector3 difference = Vector3.subtract(previousPosition, currentPosition);
Vector3 directionFromTopToBottom = difference.normalized();
Quaternion rotationFromAToB = Quaternion.lookRotation(directionFromTopToBottom, Vector3.up());

ModelRenderable model = ShapeFactory.makeCube(new Vector3(.0025f, .0025f, difference.length()), Vector3.zero(), /* material */ );

Anchor anchor = getSession().createAnchor(new Pose(f1, f2));

AnchorNode anchorNode = new AnchorNode(anchor);
anchorNode.setParent(getScene());

Vector3 lineCenter = Vector3.add(previousPosition, currentPosition).scaled(.5f);
Node lineNode = new Node();
lineNode.setParent(anchorNode);
lineNode.setRenderable(model);
lineNode.setWorldPosition(lineCenter);
lineNode.setWorldRotation(rotationFromAToB);


  1. Add a text label


Quaternion cameraRotation = getCamera().getWorldRotation();

float distance = Vector3.subtract(cameraPosition, lineCenter).length();

String result = String.format(Locale.ENGLISH, "%.3f", difference.length()) + ".m";

ViewRenderable textRenderable = mArModelCreator.getTextView();
((TextView)textRenderable.getView()
.findViewById(R.id.textLabel)).setText(result);

Node textNode = new Node();
textNode.setParent(lineNode);
textNode.setRenderable(textRenderable);
textNode.setWorldScale(new Vector3(1f, 1f, 1f).scaled(distance));
textNode.setWorldRotation(Quaternion.multiply(rotationFromAToB, cameraRotation));


But I do not have correct result.



My current labels:



wrong labels



What I need:



what i need



Please help me.










share|improve this question




























    0















    I develop an android application with ArCore library. I need make two points, draw a line between they and set a text labels near each line.



    The text labels need to be rotated face-to-camera and have positions along the line.



    1) Add a line between 2 points:



    AnchorNode previousPoint = /* point 0 */
    AnchorNode currentPoint = /* point 1 */

    Vector3 previousPosition = previousPoint.getWorldPosition();
    Vector3 currentPosition = currentPoint.getWorldPosition();

    Quaternion rotation = currentPoint.getWorldRotation();

    float f1 = new floatcurrentPosition.x, currentPosition.y, currentPosition.z;
    float f2 = new floatrotation.x, rotation.y, rotation.z, rotation.w;

    Vector3 difference = Vector3.subtract(previousPosition, currentPosition);
    Vector3 directionFromTopToBottom = difference.normalized();
    Quaternion rotationFromAToB = Quaternion.lookRotation(directionFromTopToBottom, Vector3.up());

    ModelRenderable model = ShapeFactory.makeCube(new Vector3(.0025f, .0025f, difference.length()), Vector3.zero(), /* material */ );

    Anchor anchor = getSession().createAnchor(new Pose(f1, f2));

    AnchorNode anchorNode = new AnchorNode(anchor);
    anchorNode.setParent(getScene());

    Vector3 lineCenter = Vector3.add(previousPosition, currentPosition).scaled(.5f);
    Node lineNode = new Node();
    lineNode.setParent(anchorNode);
    lineNode.setRenderable(model);
    lineNode.setWorldPosition(lineCenter);
    lineNode.setWorldRotation(rotationFromAToB);


    1. Add a text label


    Quaternion cameraRotation = getCamera().getWorldRotation();

    float distance = Vector3.subtract(cameraPosition, lineCenter).length();

    String result = String.format(Locale.ENGLISH, "%.3f", difference.length()) + ".m";

    ViewRenderable textRenderable = mArModelCreator.getTextView();
    ((TextView)textRenderable.getView()
    .findViewById(R.id.textLabel)).setText(result);

    Node textNode = new Node();
    textNode.setParent(lineNode);
    textNode.setRenderable(textRenderable);
    textNode.setWorldScale(new Vector3(1f, 1f, 1f).scaled(distance));
    textNode.setWorldRotation(Quaternion.multiply(rotationFromAToB, cameraRotation));


    But I do not have correct result.



    My current labels:



    wrong labels



    What I need:



    what i need



    Please help me.










    share|improve this question


























      0












      0








      0








      I develop an android application with ArCore library. I need make two points, draw a line between they and set a text labels near each line.



      The text labels need to be rotated face-to-camera and have positions along the line.



      1) Add a line between 2 points:



      AnchorNode previousPoint = /* point 0 */
      AnchorNode currentPoint = /* point 1 */

      Vector3 previousPosition = previousPoint.getWorldPosition();
      Vector3 currentPosition = currentPoint.getWorldPosition();

      Quaternion rotation = currentPoint.getWorldRotation();

      float f1 = new floatcurrentPosition.x, currentPosition.y, currentPosition.z;
      float f2 = new floatrotation.x, rotation.y, rotation.z, rotation.w;

      Vector3 difference = Vector3.subtract(previousPosition, currentPosition);
      Vector3 directionFromTopToBottom = difference.normalized();
      Quaternion rotationFromAToB = Quaternion.lookRotation(directionFromTopToBottom, Vector3.up());

      ModelRenderable model = ShapeFactory.makeCube(new Vector3(.0025f, .0025f, difference.length()), Vector3.zero(), /* material */ );

      Anchor anchor = getSession().createAnchor(new Pose(f1, f2));

      AnchorNode anchorNode = new AnchorNode(anchor);
      anchorNode.setParent(getScene());

      Vector3 lineCenter = Vector3.add(previousPosition, currentPosition).scaled(.5f);
      Node lineNode = new Node();
      lineNode.setParent(anchorNode);
      lineNode.setRenderable(model);
      lineNode.setWorldPosition(lineCenter);
      lineNode.setWorldRotation(rotationFromAToB);


      1. Add a text label


      Quaternion cameraRotation = getCamera().getWorldRotation();

      float distance = Vector3.subtract(cameraPosition, lineCenter).length();

      String result = String.format(Locale.ENGLISH, "%.3f", difference.length()) + ".m";

      ViewRenderable textRenderable = mArModelCreator.getTextView();
      ((TextView)textRenderable.getView()
      .findViewById(R.id.textLabel)).setText(result);

      Node textNode = new Node();
      textNode.setParent(lineNode);
      textNode.setRenderable(textRenderable);
      textNode.setWorldScale(new Vector3(1f, 1f, 1f).scaled(distance));
      textNode.setWorldRotation(Quaternion.multiply(rotationFromAToB, cameraRotation));


      But I do not have correct result.



      My current labels:



      wrong labels



      What I need:



      what i need



      Please help me.










      share|improve this question
















      I develop an android application with ArCore library. I need make two points, draw a line between they and set a text labels near each line.



      The text labels need to be rotated face-to-camera and have positions along the line.



      1) Add a line between 2 points:



      AnchorNode previousPoint = /* point 0 */
      AnchorNode currentPoint = /* point 1 */

      Vector3 previousPosition = previousPoint.getWorldPosition();
      Vector3 currentPosition = currentPoint.getWorldPosition();

      Quaternion rotation = currentPoint.getWorldRotation();

      float f1 = new floatcurrentPosition.x, currentPosition.y, currentPosition.z;
      float f2 = new floatrotation.x, rotation.y, rotation.z, rotation.w;

      Vector3 difference = Vector3.subtract(previousPosition, currentPosition);
      Vector3 directionFromTopToBottom = difference.normalized();
      Quaternion rotationFromAToB = Quaternion.lookRotation(directionFromTopToBottom, Vector3.up());

      ModelRenderable model = ShapeFactory.makeCube(new Vector3(.0025f, .0025f, difference.length()), Vector3.zero(), /* material */ );

      Anchor anchor = getSession().createAnchor(new Pose(f1, f2));

      AnchorNode anchorNode = new AnchorNode(anchor);
      anchorNode.setParent(getScene());

      Vector3 lineCenter = Vector3.add(previousPosition, currentPosition).scaled(.5f);
      Node lineNode = new Node();
      lineNode.setParent(anchorNode);
      lineNode.setRenderable(model);
      lineNode.setWorldPosition(lineCenter);
      lineNode.setWorldRotation(rotationFromAToB);


      1. Add a text label


      Quaternion cameraRotation = getCamera().getWorldRotation();

      float distance = Vector3.subtract(cameraPosition, lineCenter).length();

      String result = String.format(Locale.ENGLISH, "%.3f", difference.length()) + ".m";

      ViewRenderable textRenderable = mArModelCreator.getTextView();
      ((TextView)textRenderable.getView()
      .findViewById(R.id.textLabel)).setText(result);

      Node textNode = new Node();
      textNode.setParent(lineNode);
      textNode.setRenderable(textRenderable);
      textNode.setWorldScale(new Vector3(1f, 1f, 1f).scaled(distance));
      textNode.setWorldRotation(Quaternion.multiply(rotationFromAToB, cameraRotation));


      But I do not have correct result.



      My current labels:



      wrong labels



      What I need:



      what i need



      Please help me.







      android rotation quaternions arcore






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 '18 at 20:18







      Andrew Grow

















      asked Nov 12 '18 at 20:10









      Andrew GrowAndrew Grow

      20638




      20638






















          1 Answer
          1






          active

          oldest

          votes


















          0














          For resolving the issue I have make a line between vectors by cylinder.



          private void addLineBetweenPoints(Scene scene, Vector3 from, Vector3 to) 
          // prepare an anchor position
          Quaternion camQ = scene.getCamera().getWorldRotation();
          float f1 = new floatto.x, to.y, to.z;
          float f2 = new floatcamQ.x, camQ.y, camQ.z, camQ.w;
          Pose anchorPose = new Pose(f1, f2);

          // make an ARCore Anchor
          Anchor anchor = mCallback.getSession().createAnchor(anchorPose);
          // Node that is automatically positioned in world space based on the ARCore Anchor.
          AnchorNode anchorNode = new AnchorNode(anchor);
          anchorNode.setParent(scene);

          // Compute a line's length
          float lineLength = Vector3.subtract(from, to).length();

          // Prepare a color
          Color colorOrange = new Color(android.graphics.Color.parseColor("#ffa71c"));

          // 1. make a material by the color
          MaterialFactory.makeOpaqueWithColor(getContext(), colorOrange)
          .thenAccept(material ->
          // 2. make a model by the material
          ModelRenderable model = ShapeFactory.makeCylinder(0.0025f, lineLength,
          new Vector3(0f, lineLength / 2, 0f), material);
          model.setShadowReceiver(false);
          model.setShadowCaster(false);

          // 3. make node
          Node node = new Node();
          node.setRenderable(model);
          node.setParent(anchorNode);

          // 4. set rotation
          final Vector3 difference = Vector3.subtract(to, from);
          final Vector3 directionFromTopToBottom = difference.normalized();
          final Quaternion rotationFromAToB =
          Quaternion.lookRotation(directionFromTopToBottom, Vector3.up());
          node.setWorldRotation(Quaternion.multiply(rotationFromAToB,
          Quaternion.axisAngle(new Vector3(1.0f, 0.0f, 0.0f), 90)));
          );



          and add a TextNode:



          public ViewRenderable getTextView() 
          // return current and make new;
          ViewRenderable renderable = mTextView.makeCopy();
          makeTextModel();
          return renderable;


          private void makeTextModel()
          ViewRenderable.builder()
          .setView(LvgApplication.getContext(), R.layout.view_ar_text)
          .build()
          .thenAccept(renderable ->
          renderable.setShadowCaster(false);
          renderable.setShadowReceiver(false);
          DpToMetersViewSizer viewSizer = new DpToMetersViewSizer(500);
          renderable.setSizer(viewSizer);
          renderable.setHorizontalAlignment(ViewRenderable.HorizontalAlignment.CENTER);
          renderable.setVerticalAlignment(ViewRenderable.VerticalAlignment.CENTER);
          mTextView = renderable;
          );


          private void addTextNodeToLine(Node node, float length)
          // make model
          String result = String.format(Locale.ENGLISH, "%.3f", length) + ".m";
          ViewRenderable textRenderable = mArModelCreator.getTextView();
          ((TextView) textRenderable.getView().findViewById(R.id.textLabel)).setText(result);

          Node textNode = new Node();
          textNode.setParent(node);
          textNode.setRenderable(textRenderable);
          textNode.setWorldScale(new Vector3(1f, 1f, 1f).scaled(0));

          textNode.setLocalPosition(new Vector3(
          /* x - width from parent (left/right) */ -0.025f,
          /* y - depth from parent (forward/back) */ length / 2,
          /* z - height from parent (top/down) */ -0.002f));

          Quaternion alongLine = Quaternion.axisAngle(new Vector3(0.0f, 0.0f, 1.0f), -90);
          textNode.setLocalRotation(alongLine);






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53269393%2fandroid-arcore-how-i-can-make-a-rotation-for-some-object-along-a-line%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            For resolving the issue I have make a line between vectors by cylinder.



            private void addLineBetweenPoints(Scene scene, Vector3 from, Vector3 to) 
            // prepare an anchor position
            Quaternion camQ = scene.getCamera().getWorldRotation();
            float f1 = new floatto.x, to.y, to.z;
            float f2 = new floatcamQ.x, camQ.y, camQ.z, camQ.w;
            Pose anchorPose = new Pose(f1, f2);

            // make an ARCore Anchor
            Anchor anchor = mCallback.getSession().createAnchor(anchorPose);
            // Node that is automatically positioned in world space based on the ARCore Anchor.
            AnchorNode anchorNode = new AnchorNode(anchor);
            anchorNode.setParent(scene);

            // Compute a line's length
            float lineLength = Vector3.subtract(from, to).length();

            // Prepare a color
            Color colorOrange = new Color(android.graphics.Color.parseColor("#ffa71c"));

            // 1. make a material by the color
            MaterialFactory.makeOpaqueWithColor(getContext(), colorOrange)
            .thenAccept(material ->
            // 2. make a model by the material
            ModelRenderable model = ShapeFactory.makeCylinder(0.0025f, lineLength,
            new Vector3(0f, lineLength / 2, 0f), material);
            model.setShadowReceiver(false);
            model.setShadowCaster(false);

            // 3. make node
            Node node = new Node();
            node.setRenderable(model);
            node.setParent(anchorNode);

            // 4. set rotation
            final Vector3 difference = Vector3.subtract(to, from);
            final Vector3 directionFromTopToBottom = difference.normalized();
            final Quaternion rotationFromAToB =
            Quaternion.lookRotation(directionFromTopToBottom, Vector3.up());
            node.setWorldRotation(Quaternion.multiply(rotationFromAToB,
            Quaternion.axisAngle(new Vector3(1.0f, 0.0f, 0.0f), 90)));
            );



            and add a TextNode:



            public ViewRenderable getTextView() 
            // return current and make new;
            ViewRenderable renderable = mTextView.makeCopy();
            makeTextModel();
            return renderable;


            private void makeTextModel()
            ViewRenderable.builder()
            .setView(LvgApplication.getContext(), R.layout.view_ar_text)
            .build()
            .thenAccept(renderable ->
            renderable.setShadowCaster(false);
            renderable.setShadowReceiver(false);
            DpToMetersViewSizer viewSizer = new DpToMetersViewSizer(500);
            renderable.setSizer(viewSizer);
            renderable.setHorizontalAlignment(ViewRenderable.HorizontalAlignment.CENTER);
            renderable.setVerticalAlignment(ViewRenderable.VerticalAlignment.CENTER);
            mTextView = renderable;
            );


            private void addTextNodeToLine(Node node, float length)
            // make model
            String result = String.format(Locale.ENGLISH, "%.3f", length) + ".m";
            ViewRenderable textRenderable = mArModelCreator.getTextView();
            ((TextView) textRenderable.getView().findViewById(R.id.textLabel)).setText(result);

            Node textNode = new Node();
            textNode.setParent(node);
            textNode.setRenderable(textRenderable);
            textNode.setWorldScale(new Vector3(1f, 1f, 1f).scaled(0));

            textNode.setLocalPosition(new Vector3(
            /* x - width from parent (left/right) */ -0.025f,
            /* y - depth from parent (forward/back) */ length / 2,
            /* z - height from parent (top/down) */ -0.002f));

            Quaternion alongLine = Quaternion.axisAngle(new Vector3(0.0f, 0.0f, 1.0f), -90);
            textNode.setLocalRotation(alongLine);






            share|improve this answer



























              0














              For resolving the issue I have make a line between vectors by cylinder.



              private void addLineBetweenPoints(Scene scene, Vector3 from, Vector3 to) 
              // prepare an anchor position
              Quaternion camQ = scene.getCamera().getWorldRotation();
              float f1 = new floatto.x, to.y, to.z;
              float f2 = new floatcamQ.x, camQ.y, camQ.z, camQ.w;
              Pose anchorPose = new Pose(f1, f2);

              // make an ARCore Anchor
              Anchor anchor = mCallback.getSession().createAnchor(anchorPose);
              // Node that is automatically positioned in world space based on the ARCore Anchor.
              AnchorNode anchorNode = new AnchorNode(anchor);
              anchorNode.setParent(scene);

              // Compute a line's length
              float lineLength = Vector3.subtract(from, to).length();

              // Prepare a color
              Color colorOrange = new Color(android.graphics.Color.parseColor("#ffa71c"));

              // 1. make a material by the color
              MaterialFactory.makeOpaqueWithColor(getContext(), colorOrange)
              .thenAccept(material ->
              // 2. make a model by the material
              ModelRenderable model = ShapeFactory.makeCylinder(0.0025f, lineLength,
              new Vector3(0f, lineLength / 2, 0f), material);
              model.setShadowReceiver(false);
              model.setShadowCaster(false);

              // 3. make node
              Node node = new Node();
              node.setRenderable(model);
              node.setParent(anchorNode);

              // 4. set rotation
              final Vector3 difference = Vector3.subtract(to, from);
              final Vector3 directionFromTopToBottom = difference.normalized();
              final Quaternion rotationFromAToB =
              Quaternion.lookRotation(directionFromTopToBottom, Vector3.up());
              node.setWorldRotation(Quaternion.multiply(rotationFromAToB,
              Quaternion.axisAngle(new Vector3(1.0f, 0.0f, 0.0f), 90)));
              );



              and add a TextNode:



              public ViewRenderable getTextView() 
              // return current and make new;
              ViewRenderable renderable = mTextView.makeCopy();
              makeTextModel();
              return renderable;


              private void makeTextModel()
              ViewRenderable.builder()
              .setView(LvgApplication.getContext(), R.layout.view_ar_text)
              .build()
              .thenAccept(renderable ->
              renderable.setShadowCaster(false);
              renderable.setShadowReceiver(false);
              DpToMetersViewSizer viewSizer = new DpToMetersViewSizer(500);
              renderable.setSizer(viewSizer);
              renderable.setHorizontalAlignment(ViewRenderable.HorizontalAlignment.CENTER);
              renderable.setVerticalAlignment(ViewRenderable.VerticalAlignment.CENTER);
              mTextView = renderable;
              );


              private void addTextNodeToLine(Node node, float length)
              // make model
              String result = String.format(Locale.ENGLISH, "%.3f", length) + ".m";
              ViewRenderable textRenderable = mArModelCreator.getTextView();
              ((TextView) textRenderable.getView().findViewById(R.id.textLabel)).setText(result);

              Node textNode = new Node();
              textNode.setParent(node);
              textNode.setRenderable(textRenderable);
              textNode.setWorldScale(new Vector3(1f, 1f, 1f).scaled(0));

              textNode.setLocalPosition(new Vector3(
              /* x - width from parent (left/right) */ -0.025f,
              /* y - depth from parent (forward/back) */ length / 2,
              /* z - height from parent (top/down) */ -0.002f));

              Quaternion alongLine = Quaternion.axisAngle(new Vector3(0.0f, 0.0f, 1.0f), -90);
              textNode.setLocalRotation(alongLine);






              share|improve this answer

























                0












                0








                0







                For resolving the issue I have make a line between vectors by cylinder.



                private void addLineBetweenPoints(Scene scene, Vector3 from, Vector3 to) 
                // prepare an anchor position
                Quaternion camQ = scene.getCamera().getWorldRotation();
                float f1 = new floatto.x, to.y, to.z;
                float f2 = new floatcamQ.x, camQ.y, camQ.z, camQ.w;
                Pose anchorPose = new Pose(f1, f2);

                // make an ARCore Anchor
                Anchor anchor = mCallback.getSession().createAnchor(anchorPose);
                // Node that is automatically positioned in world space based on the ARCore Anchor.
                AnchorNode anchorNode = new AnchorNode(anchor);
                anchorNode.setParent(scene);

                // Compute a line's length
                float lineLength = Vector3.subtract(from, to).length();

                // Prepare a color
                Color colorOrange = new Color(android.graphics.Color.parseColor("#ffa71c"));

                // 1. make a material by the color
                MaterialFactory.makeOpaqueWithColor(getContext(), colorOrange)
                .thenAccept(material ->
                // 2. make a model by the material
                ModelRenderable model = ShapeFactory.makeCylinder(0.0025f, lineLength,
                new Vector3(0f, lineLength / 2, 0f), material);
                model.setShadowReceiver(false);
                model.setShadowCaster(false);

                // 3. make node
                Node node = new Node();
                node.setRenderable(model);
                node.setParent(anchorNode);

                // 4. set rotation
                final Vector3 difference = Vector3.subtract(to, from);
                final Vector3 directionFromTopToBottom = difference.normalized();
                final Quaternion rotationFromAToB =
                Quaternion.lookRotation(directionFromTopToBottom, Vector3.up());
                node.setWorldRotation(Quaternion.multiply(rotationFromAToB,
                Quaternion.axisAngle(new Vector3(1.0f, 0.0f, 0.0f), 90)));
                );



                and add a TextNode:



                public ViewRenderable getTextView() 
                // return current and make new;
                ViewRenderable renderable = mTextView.makeCopy();
                makeTextModel();
                return renderable;


                private void makeTextModel()
                ViewRenderable.builder()
                .setView(LvgApplication.getContext(), R.layout.view_ar_text)
                .build()
                .thenAccept(renderable ->
                renderable.setShadowCaster(false);
                renderable.setShadowReceiver(false);
                DpToMetersViewSizer viewSizer = new DpToMetersViewSizer(500);
                renderable.setSizer(viewSizer);
                renderable.setHorizontalAlignment(ViewRenderable.HorizontalAlignment.CENTER);
                renderable.setVerticalAlignment(ViewRenderable.VerticalAlignment.CENTER);
                mTextView = renderable;
                );


                private void addTextNodeToLine(Node node, float length)
                // make model
                String result = String.format(Locale.ENGLISH, "%.3f", length) + ".m";
                ViewRenderable textRenderable = mArModelCreator.getTextView();
                ((TextView) textRenderable.getView().findViewById(R.id.textLabel)).setText(result);

                Node textNode = new Node();
                textNode.setParent(node);
                textNode.setRenderable(textRenderable);
                textNode.setWorldScale(new Vector3(1f, 1f, 1f).scaled(0));

                textNode.setLocalPosition(new Vector3(
                /* x - width from parent (left/right) */ -0.025f,
                /* y - depth from parent (forward/back) */ length / 2,
                /* z - height from parent (top/down) */ -0.002f));

                Quaternion alongLine = Quaternion.axisAngle(new Vector3(0.0f, 0.0f, 1.0f), -90);
                textNode.setLocalRotation(alongLine);






                share|improve this answer













                For resolving the issue I have make a line between vectors by cylinder.



                private void addLineBetweenPoints(Scene scene, Vector3 from, Vector3 to) 
                // prepare an anchor position
                Quaternion camQ = scene.getCamera().getWorldRotation();
                float f1 = new floatto.x, to.y, to.z;
                float f2 = new floatcamQ.x, camQ.y, camQ.z, camQ.w;
                Pose anchorPose = new Pose(f1, f2);

                // make an ARCore Anchor
                Anchor anchor = mCallback.getSession().createAnchor(anchorPose);
                // Node that is automatically positioned in world space based on the ARCore Anchor.
                AnchorNode anchorNode = new AnchorNode(anchor);
                anchorNode.setParent(scene);

                // Compute a line's length
                float lineLength = Vector3.subtract(from, to).length();

                // Prepare a color
                Color colorOrange = new Color(android.graphics.Color.parseColor("#ffa71c"));

                // 1. make a material by the color
                MaterialFactory.makeOpaqueWithColor(getContext(), colorOrange)
                .thenAccept(material ->
                // 2. make a model by the material
                ModelRenderable model = ShapeFactory.makeCylinder(0.0025f, lineLength,
                new Vector3(0f, lineLength / 2, 0f), material);
                model.setShadowReceiver(false);
                model.setShadowCaster(false);

                // 3. make node
                Node node = new Node();
                node.setRenderable(model);
                node.setParent(anchorNode);

                // 4. set rotation
                final Vector3 difference = Vector3.subtract(to, from);
                final Vector3 directionFromTopToBottom = difference.normalized();
                final Quaternion rotationFromAToB =
                Quaternion.lookRotation(directionFromTopToBottom, Vector3.up());
                node.setWorldRotation(Quaternion.multiply(rotationFromAToB,
                Quaternion.axisAngle(new Vector3(1.0f, 0.0f, 0.0f), 90)));
                );



                and add a TextNode:



                public ViewRenderable getTextView() 
                // return current and make new;
                ViewRenderable renderable = mTextView.makeCopy();
                makeTextModel();
                return renderable;


                private void makeTextModel()
                ViewRenderable.builder()
                .setView(LvgApplication.getContext(), R.layout.view_ar_text)
                .build()
                .thenAccept(renderable ->
                renderable.setShadowCaster(false);
                renderable.setShadowReceiver(false);
                DpToMetersViewSizer viewSizer = new DpToMetersViewSizer(500);
                renderable.setSizer(viewSizer);
                renderable.setHorizontalAlignment(ViewRenderable.HorizontalAlignment.CENTER);
                renderable.setVerticalAlignment(ViewRenderable.VerticalAlignment.CENTER);
                mTextView = renderable;
                );


                private void addTextNodeToLine(Node node, float length)
                // make model
                String result = String.format(Locale.ENGLISH, "%.3f", length) + ".m";
                ViewRenderable textRenderable = mArModelCreator.getTextView();
                ((TextView) textRenderable.getView().findViewById(R.id.textLabel)).setText(result);

                Node textNode = new Node();
                textNode.setParent(node);
                textNode.setRenderable(textRenderable);
                textNode.setWorldScale(new Vector3(1f, 1f, 1f).scaled(0));

                textNode.setLocalPosition(new Vector3(
                /* x - width from parent (left/right) */ -0.025f,
                /* y - depth from parent (forward/back) */ length / 2,
                /* z - height from parent (top/down) */ -0.002f));

                Quaternion alongLine = Quaternion.axisAngle(new Vector3(0.0f, 0.0f, 1.0f), -90);
                textNode.setLocalRotation(alongLine);







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 '18 at 20:46









                Andrew GrowAndrew Grow

                20638




                20638



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53269393%2fandroid-arcore-how-i-can-make-a-rotation-for-some-object-along-a-line%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Use pre created SQLite database for Android project in kotlin

                    Darth Vader #20

                    Ondo