Log in or register to post comments

I change the model, and then have problems holding the camera.

March 31, 2013 - 12:09am #1

 

I try to change the model from the teapot is my how to make a banana.
There are steps, as follows:
1. I put the file banana.h into  jni
2. put the file banana.jpg into assets
3. Change the code in imageTarget.java:
 private void loadTextures()
    {
    	mTextures.add(Texture.loadTextureFromApk("banana.jpg",
                getAssets()));
        /*mTextures.add(Texture.loadTextureFromApk("TextureTeapotBrass.png",
                                                 getAssets()));
        mTextures.add(Texture.loadTextureFromApk("TextureTeapotBlue.png",
                                                 getAssets()));
        mTextures.add(Texture.loadTextureFromApk("TextureTeapotRed.png",
                getAssets()));*/
    }

4. Change the code in imageTarget.cpp:

#ifdef USE_OPENGL_ES_1_1
        // Load projection matrix:
        glMatrixMode(GL_PROJECTION);
        glLoadMatrixf(projectionMatrix.data);

        // Load model view matrix:
        glMatrixMode(GL_MODELVIEW);
        glLoadMatrixf(modelViewMatrix.data);
        glTranslatef(0.f, 0.f, kObjectScale);
        glScalef(kObjectScale, kObjectScale, kObjectScale);

        // Draw object:
        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
        glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*) &teapotTexCoords[0]);
        glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &teapotVertices[0]);
        glNormalPointer(GL_FLOAT, 0,  (const GLvoid*) &teapotNormals[0]);
        glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
                       (const GLvoid*) &teapotIndices[0]);
#else

        QCAR::Matrix44F modelViewProjection;

        SampleUtils::translatePoseMatrix(5.0f, 5.0f, kObjectScale,
                                         &modelViewMatrix.data[0]);
        SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,
                                     &modelViewMatrix.data[0]);
        SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                    &modelViewMatrix.data[0] ,
                                    &modelViewProjection.data[0]);

        glUseProgram(shaderProgramID);
         
        glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &bananaVerts[0]);
        glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &bananaNormals[0]);
        glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &bananaTexCoords[0]);
        
        glEnableVertexAttribArray(vertexHandle);
        glEnableVertexAttribArray(normalHandle);
        glEnableVertexAttribArray(textureCoordHandle);
        
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
        glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/);
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                           (GLfloat*)&modelViewProjection.data[0] );
        glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);

        SampleUtils::checkGlError("ImageTargets renderFrame");
#endif

5. I compile with the new ndk.

I follow the steps. Just turn on the camera and took a shine to the marker and hold camera and there is no model.

What is Hey who needs an excuse.
 

I change the model, and then have problems holding the camera.

August 4, 2013 - 5:09am #7

Hi DavidBeard

thank you for your reply

I just tried to use the array to the position of the X axis, I just use the transform to the same object at different positions this is my code.. i work with virtual button sample :

for (int j = 0; j < NUM_BUTTONS; ++j)
                {
                    if (strcmp(button.getName(), virtualButtonColors[j]) == 0)
                    {
                       // textureIndex = j+1;
                        QCAR::Matrix44F modelViewProjection1;

                        assert(textureIndex < textureCount);
                                const Texture* const thisTexture = textures[textureIndex];
                                const Texture* const texHammer = textures[1];

                    float posisiX [] ={0.0f,-55.0f,-35.0f,-7.0f,18.0f,40.0f,65.0f};

                       for (int  m= 0; m<NUM_BUTTONS;m++){
                        SampleUtils::translatePoseMatrix(posisiX[m],0.0f, kHammer_5Scale, &modelViewMatrix1.data[0]);
                        float angle = 90.0f; // YOUR ROTATION ANGLE HERE (in degrees)
                        SampleUtils::rotatePoseMatrix(angle, -20.0f, -25.0f, 0.0f,&modelViewMatrix1.data[0]);
                        SampleUtils::scalePoseMatrix(kHammer_5Scale, kHammer_5Scale, kHammer_5Scale,&modelViewMatrix1.data[0]);
                        SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewMatrix1.data[0] , &modelViewProjection1.data[0]);

                      // Render 3D model
                       .. some code

                        break;

when I compile NDK-build no error happened, but when I run my application object's position is not working properly,
position of the object is always in the same place for every virtual button, which is the position for my array posisiX[0], if an error in the my code? what should i do for? sorry for my ignorance

 

thanks and regard

mysiamay

 

I change the model, and then have problems holding the camera.

August 3, 2013 - 1:06pm #6

Ale is on vacation, but perhaps I can help.

The translatePoseMatrix function can only receive the transform elements as such..

    /// Set the translation components of this 4x4 matrix.
    static void translatePoseMatrix(float x, float y, float z,
        float* nMatrix = NULL);

But you could write a wrapper functions that accepts an array and them maps the indices to the x,y,z arguments.

Also see: https://developer.vuforia.com/resources/dev-guide/positioning-3d-content

I change the model, and then have problems holding the camera.

August 3, 2013 - 8:03am #5

hi AlessandroB

if i want to display the objects banana with three different positions in the same image target, Should I use a different transforms to position for each models?

like this:

 QCAR::Matrix44F modelViewProjection;
                        SampleUtils::translatePoseMatrix(100.0f, 0.0f, kBananaScale, &modelViewMatrix.data[0]);
                        float angle = 90.0f; // YOUR ROTATION ANGLE HERE (in degrees)
                        SampleUtils::rotatePoseMatrix(angle, -20.0f, -25.0f, 0.0f,&modelViewMatrix.data[0]);
                        SampleUtils::scalePoseMatrix(kBananaScale, kBananaScale, kBananaScale,&modelViewMatrix.data[0]);
                        SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewMatrix.data[0] , &modelViewProjection.data[0]);

 QCAR::Matrix44F modelViewProjection1;
                        SampleUtils::translatePoseMatrix(50.0f, 0.0f, kBananaScale, &modelViewMatrix1.data[0]);
                        float angle = 90.0f; // YOUR ROTATION ANGLE HERE (in degrees)
                        SampleUtils::rotatePoseMatrix(angle, -20.0f, -25.0f, 0.0f,&modelViewMatrix1.data[0]);
                        SampleUtils::scalePoseMatrix(kBananaScale, kBananaScale, kBananaScale,&modelViewMatrix1.data[0]);
                        SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewMatrix1.data[0] , &modelViewProjection1.data[0]);

QCAR::Matrix44F modelViewProjection2;
                        SampleUtils::translatePoseMatrix(0.0f, 0.0f, kBananaScale, &modelViewMatrix2.data[0]);
                        float angle = 90.0f; // YOUR ROTATION ANGLE HERE (in degrees)
                        SampleUtils::rotatePoseMatrix(angle, -20.0f, -25.0f, 0.0f,&modelViewMatrix2.data[0]);
                        SampleUtils::scalePoseMatrix(kBananaScale, kBananaScale, kBananaScale,&modelViewMatrix2.data[0]);
                        SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewMatrix2.data[0] , &modelViewProjection2.data[0]);

 or I could use the transform and use an array for position translatePoseMatrix?

can you give me some suggestion,, for make it simple?

thank you

mysiamay

 

 

I change the model, and then have problems holding the camera.

April 2, 2013 - 4:46am #4

Not sure I understand your last question...

have you changed the kObjectScale ? did it work ?

 

I change the model, and then have problems holding the camera.

April 1, 2013 - 7:59am #3

AlessandroB wrote:

Hi,

this is a common issue, chances are that the banana is simply too small to be visible;

have you tried increasing kObjectScale variable in ImageTargets.cpp to 100.0f (current value is 3.0f)

?

 

 

Now, how do I change the model, then?
But now there is a problem, I will show how the model 2 was a banana with the Teapot shows simultaneously and in different positions.

 

I change the model, and then have problems holding the camera.

March 31, 2013 - 2:38am #2

Hi,

this is a common issue, chances are that the banana is simply too small to be visible;

have you tried increasing kObjectScale variable in ImageTargets.cpp to 100.0f (current value is 3.0f)

?

Log in or register to post comments