代码之家  ›  专栏  ›  技术社区  ›  G.L

标记的2D位置

  •  0
  • G.L  · 技术社区  · 7 年前

    我需要获得屏幕(视图)中标记的位置,然后添加一个自定义文本视图,有可能吗?如何基于projectionMatrix和modelViewMatrix获得标记的二维位置?

     @Override
    public void draw() {
        super.draw();
    
        GLES20.glEnable(GLES20.GL_CULL_FACE);
        GLES20.glEnable(GLES20.GL_DEPTH_TEST);
        GLES20.glFrontFace(GLES20.GL_CCW);
    
    
        boolean show = false;
        for (int trackableUID : trackableUIDs) {
            if (ARToolKit.getInstance().queryMarkerVisible(trackableUIDs.get(trackableUID))) {
                float[] projectionMatrix = ARToolKit.getInstance().getProjectionMatrix();
                float[] modelViewMatrix = ARToolKit.getInstance().queryMarkerTransformation(trackableUIDs.get(trackableUID));
                Log.i("INFOOOOO", projectionMatrix.toString());
                Log.i("INFOOOOO", modelViewMatrix.toString());
                cube.draw(projectionMatrix, modelViewMatrix);
                show = true;
            }
        }
    }
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   G.L    7 年前

    @斯特纳非常感谢,我发现下面的解决方案是代码,如果有人正在寻找解决方案

                final float[] projectionMatrix = ARToolKit.getInstance().getProjectionMatrix();
                final float[] modelViewMatrix = ARToolKit.getInstance().queryMarkerTransformation(trackableUIDs.get(trackableUID));
    
                if (view == null) {
                    view = new int[4];
                    view[0] = 0;
                    view[1] = 0;
                    view[2] = ARTrackingActivity.width;
                    view[3] = ARTrackingActivity.height;
                }
    
                int i = GLU.gluProject(0, 0, 0, modelViewMatrix, 0, projectionMatrix, 0, view, 0, floats, 0);
                if (i == GLES20.GL_TRUE) {
                   // draw the object in screen
                }
    
    推荐文章