2D标记的位置

时间:2017-09-24 11:01:40

标签: android opengl-es artoolkit

您好我在使用ARToolKit v6来渲染基于nft jpg图像的标记,它的效果非常好但是...... 我需要在屏幕(视图)中获取标记的位置,然后添加自定义textView有可能吗?如何获得基于projectionMatrix和modelViewMatrix的标记的2d位置?

或者我可以绘制文字或图像而不是立方体吗?

 @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 个答案:

答案 0 :(得分:0)

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

            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
            }