Log in or register to post comments

Multiple textures, how to center objects?

August 28, 2015 - 7:51am #1

Hello.

I posted a question in this post, but there was no answer: https://developer.vuforia.com/forum/rendering-opengl-es/models-multiple-texture-maps
 
I did what was suggested. I divided the object into multiple objects, each party applied different textures.
 
Now I would like some help to display each part in its original coordinate. At the time, using the example ImageTarget all parties are being displayed in the center. An object overlapping each other.
 
The following code snippet.
 
private void renderFrame() {
...

float[] modelViewProjection = new float[16];

            Matrix.translateM(modelViewMatrix, 0, 0.0f, 0.0f, OBJECT_SCALE_FLOAT);
            Matrix.scaleM(modelViewMatrix, 0, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT);
            
            Matrix.multiplyMM(modelViewProjection, 0, vuforiaAppSession.getProjectionMatrix().getData(), 0, modelViewMatrix, 0);
            
            // activate the shader program and bind the vertex/normal/tex coords
            GLES20.glUseProgram(shaderProgramID);

            renderPartObject(1, cadeiraBase.getVertices(), cadeiraBase.getNormals(), cadeiraBase.getTexCoords(), cadeiraBase.getNumObjectVertex(), modelViewProjection);
            renderPartObject(0, cadeiraEncosto.getVertices(), cadeiraEncosto.getNormals(), cadeiraEncosto.getTexCoords(), cadeiraEncosto.getNumObjectVertex(), modelViewProjection);
            renderPartObject(0, cadeiraAssento.getVertices(), cadeiraAssento.getNormals(), cadeiraAssento.getTexCoords(), cadeiraAssento.getNumObjectVertex(), modelViewProjection);

            // disable the enabled arrays
            GLES20.glDisableVertexAttribArray(vertexHandle);
            GLES20.glDisableVertexAttribArray(normalHandle);
            GLES20.glDisableVertexAttribArray(textureCoordHandle);

...

}

 private void renderPartObject(int textureIndex, Buffer vertices, Buffer normals, Buffer coords, int numVerts, float[] modelViewProjection){
        GLES20.glVertexAttribPointer(vertexHandle, 3, GLES20.GL_FLOAT, false, 0, vertices);
        GLES20.glVertexAttribPointer(normalHandle, 3, GLES20.GL_FLOAT, false, 0, normals);
        GLES20.glVertexAttribPointer(textureCoordHandle, 2, GLES20.GL_FLOAT, false, 0, coords);

        GLES20.glEnableVertexAttribArray(vertexHandle);
        GLES20.glEnableVertexAttribArray(normalHandle);
        GLES20.glEnableVertexAttribArray(textureCoordHandle);

        // activate texture 0, bind it, and pass to shader
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures.get(textureIndex).mTextureID[0]);
        GLES20.glUniform1i(texSampler2DHandle, 0);

        GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, modelViewProjection, 0);

        GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, numVerts);
    }

 

 

Log in or register to post comments