Log in or register to post comments

How to replace teapot to banana in virtualbutons?

March 29, 2013 - 11:32pm #1

Hi to All,

I have to change teapot object to banana object .

i do some changes in virtualbuttons app .

i have banana.h file i put that in jni folder and bananayellow.png, bananawhite.png files in assets folder.

and i change somecode in VirtualButtons.cpp file like below as per some posts

// Render 3D model
        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);

        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                              (GLfloat*)&modelViewProjection.data[0] );
        glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);

and also i replaced in src/VirtualButtons.java file like below

 private void loadTextures()
    {
        mTextures.add(Texture.loadTextureFromApk("TextureBananaYellow.png",
                getAssets()));
        mTextures.add(Texture.loadTextureFromApk("TextureBananaRed.png",
                getAssets()));
        
        /*mTextures.add(Texture.loadTextureFromApk("TextureTeapotBrass.png",
                getAssets()));
        mTextures.add(Texture.loadTextureFromApk("TextureTeapotRed.png",
                getAssets()));
        mTextures.add(Texture.loadTextureFromApk("TextureTeapotBlue.png",
                getAssets()));
        mTextures.add(Texture.loadTextureFromApk("TextureTeapotYellow.png",
                getAssets()));        
        mTextures.add(Texture.loadTextureFromApk("TextureTeapotGreen.png",
                getAssets()));*/
    }

i rebuild it and run it but there was no errors but that banana image was not displaying when showing the wood image through camera.

Was I done anything wrong. Can Anyone please help me.

Thanks in Advance.

How to replace teapot to banana in virtualbutons?

October 22, 2013 - 11:12pm #11

hi AlessandroB

i follow your suggestion to take a look for videoplayback.cpp

i paste the isTapOnScreenTarget for my code

 

in imageTarget.cpp

#include <SampleMath.h>

JNIEXPORT bool JNICALL
Java_com_qualcomm_QCARSamples_VideoPlayback_VideoPlayback_isTapOnScreenInsideTarget(JNIEnv *env, jobject, jint target, jfloat x, jfloat y)
{
    //LOG("Java_com_qualcomm_QCARSamples_VideoPlayback_VideoPlayback_isTapOnScreenInsideTarget");
    // Here we calculate that the touch event is inside the target
    QCAR::Vec3F intersection, lineStart, lineEnd;

    SampleMath::projectScreenPointToPlane(inverseProjMatrix, modelViewMatrix[target], screenWidth, screenHeight,
                              QCAR::Vec2F(x, y), QCAR::Vec3F(0, 0, 0), QCAR::Vec3F(0, 0, 1), intersection, lineStart, lineEnd);

    // The target returns as pose the center of the trackable. The following if-statement simply checks that the tap is within this range
    if ( (intersection.data[0] >= -(targetPositiveDimensions[target].data[0])) && (intersection.data[0] <= (targetPositiveDimensions[target].data[0])) &&
         (intersection.data[1] >= -(targetPositiveDimensions[target].data[1])) && (intersection.data[1] <= (targetPositiveDimensions[target].data[1])))
        return true;
    else
        return false;
}

in imagetarget.java

private native boolean isTapOnScreenInsideTarget(int target,float x, float y);

    protected void onCreate(Bundle savedInstanceState)
    {
        DebugLog.LOGD("ImageTargets::onCreate");
        super.onCreate(savedInstanceState);

        // Load any sample specific textures:
        mTextures = new Vector<Texture>();
        loadTextures();

        // Query the QCAR initialization flags:
        mQCARFlags = getInitializationFlags();

        // Creates the GestureDetector listener for processing double tap
        //mSimpleListener = new SimpleOnGestureListener();
        mSimpleListener = new SimpleOnGestureListener();
        mGestureDetector = new GestureDetector(getApplicationContext(), mSimpleListener);
//        mGestureDetector.setOnDoubleTapListener(new OnDoubleTapListener()
        mGestureDetector = new GestureDetector(this, new GestureListener());
        
        mGestureDetector.setOnDoubleTapListener(new OnDoubleTapListener() {
            
            @Override
            public boolean onSingleTapConfirmed(MotionEvent e)
            {    
   
                 System.out.println("X Coordinate: "+e.getX());
                    System.out.println("Y Coordinate: "+e.getY());
                   
                    if (isTapOnScreenInsideTarget(0,e.getX(), e.getY()))
                    {
                    System.out.println("Touched for new screen");

                    PlaySound(1);
                    }
                    return true;
            //return false;    
            }
            
            @Override
            public boolean onDoubleTapEvent(MotionEvent e)
            {
                
                return false;    
            }
            
            @Override
            public boolean onDoubleTap(MotionEvent e)
            {
                System.out.println("Hello double tap");
                if (isTapOnScreenInsideTarget(0,e.getX(), e.getY()))
                {
                System.out.println("Touched for new screen");
              
                }
               else
                {
                    System.out.println("Else touched");
                }
                return true;
                
            }
        });

 

but my application can tap everywhere even it's not tracker the target.and my application just get the coordinate x and y fortap,  like my isTapOnTheScreen function does not work,,
could you help me ?

How to replace teapot to banana in virtualbutons?

April 3, 2013 - 12:18am #10

Hi, yes, 

you can also change the color (or do any other action you like) when touching the button via the screen;

this is however not supported out-of-the-box by Vuforia; you will need to put some code together to achieev that;

in particular, you will need to determine whether your finger touch is actually tapping on the rectangle of a virtual button;

something very similar is implemented in our VideoPlayback sample, which I encourage to read, as you will find the necessary code to support your use case;

in particular you can find this function defined in VideoPlayback.cpp:

isTapOnScreenInsideTarget

that function is defined in C++, but  it is called from the Java code in VideoPlayback.java (see onSingleTapConfirmed).

 

How to replace teapot to banana in virtualbutons?

April 2, 2013 - 11:09pm #9

Hi AlessandroB,

Is there no way to change colors touching on screen.

Thanks in Advance.

How to replace teapot to banana in virtualbutons?

April 2, 2013 - 5:37am #8

Ok, I see; you're trying to change button color via touch of the screen;

that's not how Virtual Buttons work, you need to really touch the buttons on the real printed target (on paper)...

 

How to replace teapot to banana in virtualbutons?

April 2, 2013 - 5:18am #7

Hi AlessandroB,

Without any changes also the toggle buttons are not working.

When we clicking on toggle buttons on mobile screen it doesn't changing the color.

how can we change colors by clicking the toggle buttons on mobile screen.

Thanks in advance.

How to replace teapot to banana in virtualbutons?

April 2, 2013 - 5:10am #6

Hi, can you calrify a bit?

have you tried the original VirtualButtons sample (without any changes) ?

does it work?

what are the specific things that you want to change and which do not seem to work ?

 

How to replace teapot to banana in virtualbutons?

April 1, 2013 - 5:07am #5

Hi AlessandroB,

can we change the colors when we clicking on the mobile toogle buttons.

when i clicking toogle buttons in mobile, the colors are not changing. How can we change colors with clicking toogle buttons also.

Thanks in advance.

How to replace teapot to banana in virtualbutons?

March 30, 2013 - 3:21am #4

Great, You're welcome.

How to replace teapot to banana in virtualbutons?

March 30, 2013 - 3:12am #3

Hi AlessandroB,

Thanks a lot its working now.

 

How to replace teapot to banana in virtualbutons?

March 30, 2013 - 2:28am #2

Hi, the code looks fine,

you might simply need to adjust the kObjectScale (increase it to e.g. 100.0f, current value is 3.0f)

This may solve your issue.

 

Log in or register to post comments