Render a 3D Object off the Center of the screen: ARTOOLKIT ANDROID

时间:2017-11-13 06:28:02

标签: android opengl-es augmented-reality artoolkit

Hi I am working on a AR android app. I am using ARToolkit6. In this app I want to view my 3D object( A Cube) on left half of the screen. With this eventually I want to display 3 cubes on the screen each on 1/3 of the screen area.

I was able to scale the 3D object by tweaking ModelView Matrix. What I read so far, I think I need to tweak projection matrix to achieve my goal. I tried looking solutions online. But Couldn't get it to work. Can anyone direct me to right path?

for (int trackableUID : trackableUIDs) {
        // If the marker is visible, apply its transformation, and render a cube
        if (ARToolKit.getInstance().queryMarkerVisible(trackableUID)) {
            float[] projectionMatrix = ARToolKit.getInstance().getProjectionMatrix();
            float[] modelViewMatrix = ARToolKit.getInstance().queryMarkerTransformation(trackableUID);

            float[] scalingMat = {1, 0, 0, 0, 0, 3.0f, 0, 0, 0, 0, 1.0f, 0, 0.0f, 0, 0, 1};
            float[] newModelView = modelViewMatrix;
            multiplyMM(newModelView, 0, modelViewMatrix, 0, scalingMat, 0);

            cube.draw(projectionMatrix, newModelView);
}

I followed the this link Set origin to top-left corner of screen in OpenGL ES 2 and (OpenGL ES) Objects away from view centre are stretched. So I translated the modelView Matrix but it doesn't solve the problem, the 3D object appears at the center of the screen. Can you explain how should I approach this problem? Thanks

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

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

// Look for trackables, and draw on each found one.
for (int trackableUID : trackableUIDs) {
    // If the marker is visible, apply its transformation, and render a cube
    if (ARToolKit.getInstance().queryMarkerVisible(trackableUID)) {
        float[] projectionMatrix = ARToolKit.getInstance().getProjectionMatrix();
        float[] modelViewMatrix = ARToolKit.getInstance().queryMarkerTransformation(trackableUID);

        float[] scalingMat = {1, 0, 0, 0, 0, 3.0f, 0, 0, 0, 0, 1.0f, 0, 0.0f, 0, 0, 1};

        multiplyMM(modelViewMatrix, 0, scalingMat, 0, modelViewMatrix, 0);

        float[] rightModelMatrix = new float[16];
        Matrix.setIdentityM(rightModelMatrix, 0);
        // Translate outer sphere by 5 in x.
        Matrix.translateM(rightModelMatrix, 0, 5.0f, 0.0f, 0.0f);

        Matrix.multiplyMM(modelViewMatrix, 0, rightModelMatrix, 0, modelViewMatrix, 0);

        cube.draw(projectionMatrix, modelViewMatrix);



    }
}

Also tried this but the object gets displayed at the center of the screen.

glMatrixMode(GL_PROJECTION);
glTranslatef(5f, 0f, 0f);

0 个答案:

没有答案