Using addMarker with ARToolKit

420 views Asked by At

I am currently working on an android app, and I want to include ARToolKit to scan pictures and show 3d models.

So I added the ARToolKit 6 to my Android Studio and I created the program itself fast. Next I wanted to add markers with addMarker, so basically my code was this.

class ARTrackingRenderer extends ARRenderer {

private static final class Trackable{
    String name;
    float height;

    Trackable(String name, float height)
    {
        this.name = name;
        this.height = height;
    }
}

private static final Trackable trackables[] = new Trackable[]{
        new Trackable("Alterra_Ticket_1.jpg", 95.3f),
        new Trackable("Alterra_Postcard_2.jpg", 95.3f),
        new Trackable("Alterra_Postcard_3.jpg", 127.0f),
        new Trackable("Alterra_Postcard_4.jpg", 95.3f)
};

private int trackableUIDs[] = new int[trackables.length];
private Cube cube;
private Cube cube2;

@Override
public boolean configureARScene() {
    int i = 0;
    for (Trackable trackable : trackables){
        trackableUIDs[i] = ARToolKit.getInstance().addMarker("2d;Data/2d/" + trackable.name + ";" + trackable.height);
        if (trackableUIDs[1] < 0) return false;
    }
    NativeInterface.arwSetTrackerOptionInt(NativeInterface.ARW_TRACKER_OPTION_2D_MAX_IMAGES, trackables.length);
    return true;
}

//Shader calls should be within a GL thread. GL threads are onSurfaceChanged(), onSurfaceCreated() or onDravFrame()
//As the cube instantiates the shader during setShaderProgram call  we need to create the cube here.
@Override
public void onSurfaceCreated(GL10 unused, javax.microedition.khronos.egl.EGLConfig config){
    this.shaderProgram = new SimpleShaderProgram(new SimpleVertexShader(), new SimpleFragmentShader());
    cube = new Cube(30.0f, 0.0f, 0.0f, 0.0f); //Das erste ist die Größe, das zweite die horizontale Ausrichtung, das dritte die vertikale und das vierte der Abstand vom boden aus
    cube2 = new Cube(15.0f, 50.0f, 0.0f, 20.0f);
    cube.setShaderProgram(shaderProgram);
    cube2.setShaderProgram(shaderProgram);
    super.onSurfaceCreated(unused, config);
}

@Override
public void draw(){
    super.draw();

    GLES20.glEnable(GLES20.GL_CULL_FACE);
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    GLES20.glFrontFace(GLES20.GL_CCW);

    for (int trackableUID:trackableUIDs){
        if (ARToolKit.getInstance().queryMarkerVisible(trackableUID)){
            float[] projectionMatrix = ARToolKit.getInstance().getProjectionMatrix();
            float[] modelVievMatrix = ARToolKit.getInstance().queryMarkerTransformation(trackableUID);
            cube.draw(projectionMatrix, modelVievMatrix);
            cube2.draw(projectionMatrix, modelVievMatrix);
        }
    }
}

}

I got the code from a Tutorial on YouTube. I want to add new markers. How can I do this? Or basically just how can I add new pictures, so it wont scan everytime the alterra pictures?

Thanks for all help.

1

There are 1 answers

0
Thor_Bux On

This code:

private static final Trackable trackables[] = new Trackable[]{
        new Trackable("Alterra_Ticket_1.jpg", 95.3f),
        new Trackable("Alterra_Postcard_2.jpg", 95.3f),
        new Trackable("Alterra_Postcard_3.jpg", 127.0f),
        new Trackable("Alterra_Postcard_4.jpg", 95.3f)
};

Is responsible for adding the 'markers' called Trackable to ARToolKit. You can add your markers to the trackables array.

The .jpg files need to be available in the assets directory parallel to the Alterra*.jpg files.

Only .jpg files are possible.