Search code examples
androidopengl-esartoolkit

2D Position of marker


Hi there I'm using ARToolKit v6 to render marker based on nft jpg image it works very well but.. I need to get position of marker in screen(view) and then add a custom textView there is that possible ? how to get 2d position of marker based on projectionMatrix and modelViewMatrix ?

Or can I draw a text or image instead of Cube ?

code

 @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;
        }
    }
}

Solution

  • @sturner thanks so much , I found a solution below is the code if someone is looking for solution

                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
                }