如何借助ARcore相对于一个锚定位锚/节点/锚节点?

时间:2019-02-14 15:02:30

标签: java android arcore

我正在android studio中创建AR导航。 我正在寻找一种将锚与其他锚“或”锚节点/节点“连接”的方法。我不确定要使用哪个。基于我将迫使用户创建的第一个锚点,我想绘制相对于第一个锚点位置的其余节点。我尝试了下面显示的方法,但没有成功。有什么想法吗?

private void getAnchors(DataSnapshot dataSnapshot){
    double temp_x=0.0;
    double temp_y=0.0;
    double temp_z=0.0;
    Vector3 wektor3;

    for(DataSnapshot ds : dataSnapshot.getChildren())
    {
          ObjectConversion vars = ds.getValue(ObjectConversion.class);
          temp_x = vars.getX();
          temp_y = vars.getY();
          temp_z = vars.getZ();

          wektor3 = new Vector3((float)temp_x,(float)temp_y,(float)temp_z);

          //Pose pose = new Pose(translation,rotation);
          Anchor anchor = download_hit_result.createAnchor();
          AnchorNode anchorNode = new AnchorNode(anchor);
          Node node = new Node();

          node.setParent(anchorNode);
          node.setWorldPosition(wektor3);
          node.setRenderable(andyRenderable);

          //anchorNode.setParent(arFragment.getArSceneView().getScene());
          //anchorNode.setRenderable(andyRenderable);
          //anchorNode.setParent(arFragment.getArSceneView().getScene());
    }
}

1 个答案:

答案 0 :(得分:0)

我已经发现一个错误。对于需要基于不同对象定位对象的其他任何人。只需将锚节点的parent设置为arFragment。我希望这对以后的所有人有帮助:

private void getAnchors(DataSnapshot dataSnapshot){
    double temp_x=0.0;
    double temp_y=0.0;
    double temp_z=0.0;
    long   temp_val=0;
    String temp_room="";
    float[] translation= new float[3];
    float[] rotation = {0.0f,0.0f,0.0f,0.0f};
    Vector3 wektor3;
    for(DataSnapshot ds : dataSnapshot.getChildren())
    {
        //TODO: create anchors with downloaded values when in the same position use hitpose.creatanchor with pose.

          ObjectConversion vars = ds.getValue(ObjectConversion.class);
          temp_x = vars.getX();
          temp_y = vars.getY();
          temp_z = vars.getZ();
          temp_room = vars.getRoom();
          temp_val=vars.getType();

          translation[0]=(float) temp_x;
          translation[1]=(float) temp_y;
          translation[2]=(float) temp_z;
          wektor3 = new Vector3((float)temp_x,(float)temp_y,(float)temp_z);
          Pose pose = new Pose(translation,rotation);

          Anchor anchorx = download_hit_result.getTrackable().createAnchor(pose);
          AnchorNode anchorNodex = new AnchorNode(anchorx);
          anchorNodex.setParent(arFragment.getArSceneView().getScene());
          anchorNodex.setRenderable(andyRenderable);
    }
}