Log in or register to post comments

How can i make opengl coordinates system have the same size as t

January 15, 2016 - 12:12am #1

Hello everyone. First of all I'd like to say that I'm totally a newbie in OpenGL & Vuforia APIs development. Said that, what I'm trying to build is an Android Application where the user can scan a picture of a model via Vuforia Cloud Recognition and show on top of that image some OpenGL Texture corresponding to the cloths shown on that image. For example, if the user scans a picture of a model with jeans and a sweater, the app should show two buttons (OpenGL Texutres) on top of each one so when the user taps on one of them, he gets redirected to another screen to buy the selected cloth.

The problem here is, that I receive the coordinates of those "buttons" (textures) relative to the size of the image. E.g: if the image is 1400x2000, a texture in the middle would have coordinates (700, 1000). And I don't know how to translate those coordinates to the OpenGL System. The problem isn't that OpenGL coordinates start on the center of the image and the ones I have start on the top left, I know how to deal with this.

Any help would be appreciated.

This is my renderAugmentation method:

 
//Arrays with positions just for testing purposes
//private float [] mPositionsX = {0.0f, 1.0f, 2.0f, 3.0f};
//private float [] mPositionsY = {0.0f, 1.0f, 2.0f, 3.0f};
private void renderAugmentation(TrackableResult trackableResult){
 
    float targetWidth = ((ImageTarget)trackableResult.getTrackable()).getSize().getData()[0];
    float targetHeight = ((ImageTarget)trackableResult.getTrackable()).getSize().getData()[1];
    float[] modelViewProjection = new float[16];
 
    float zInc = 0.0f;
 
    Matrix.scaleM(modelViewMatrix, 0, 430.f * mScaleFactor, 430.f * mScaleFactor, 1.0f);
    // Applies 3d Transformations to the plane
    Matrix.multiplyMM(modelViewProjection, 0, vuforiaAppSession.getProjectionMatrix().getData(), 0, modelViewMatrix, 0);
 
    pose = trackableResult.getPose();
 
    // Shader Program for drawing
    GLES20.glUseProgram(shaderProgramID);
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
 
        for (int i = 0; i < mProductTexture.size(); i++) {
 
            float[] modelViewMatrixTemp = modelViewMatrix.clone();
            float[] modelViewProjectionTemp = modelViewProjection.clone();
            Texture t = mProductTexture.get(i);
            ModelARClothing cloth = mClothingARArray.get(i);
 
            GLES20.glVertexAttribPointer(vertexHandle, 3, GLES20.GL_FLOAT,
                    true, 0, mPlane.getVertices());
            GLES20.glVertexAttribPointer(normalHandle, 3, GLES20.GL_FLOAT,
                    true, 0, mPlane.getNormals());
            GLES20.glVertexAttribPointer(textureCoordHandle, 2,
                    GLES20.GL_FLOAT, true, 0, mPlane.getTexCoords());
 
            GLES20.glEnableVertexAttribArray(vertexHandle);
            GLES20.glEnableVertexAttribArray(normalHandle);
            GLES20.glEnableVertexAttribArray(textureCoordHandle);
 
            // Enables Blending State
            GLES20.glEnable(GLES20.GL_BLEND);
 
            // Drawing Textured Plane
            GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, t.mTextureID[0]);
 
            VuforiaUtils.translatePoseMatrix(mPositionsX[i], mPositionsY[i],0.0f, modelViewMatrixTemp);
            VuforiaUtils.multiplyMatrix(vuforiaAppSession.getProjectionMatrix().getData(), modelViewMatrixTemp, modelViewProjectionTemp);
 
            GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, FloatBuffer.wrap(modelViewProjectionTemp));
            GLES20.glUniform1i(texSample2dHandle, 0);
 
            GLES20.glDrawElements(GLES20.GL_TRIANGLES, 6, GLES20.GL_UNSIGNED_SHORT, mPlane.getIndices());
        }
        GLES20.glDisableVertexAttribArray(vertexHandle);
        GLES20.glDisableVertexAttribArray(normalHandle);
        GLES20.glDisableVertexAttribArray(textureCoordHandle);
 
        // Disables Blending State - Its important to disable the blending
        // state after using it for preventing bugs with the Camera Video
        // Background
        GLES20.glDisable(GLES20.GL_BLEND);
    }
 
    VuforiaUtils.checkGLError("Books renderFrame");
}
 
Log in or register to post comments