Log in or register to post comments

Problem in virtual button coordinate

October 16, 2013 - 12:16am #1

I tried to change coordinate of virtual button (in xml and cpp file). I got 5 virtual buttons:

if (buttonMask & BUTTON_1)
                LOG("Toggle Button 1");

                toggleVirtualButton(imageTarget, virtualButtonColors[0],
                                    -121.03f, 83.04f, -79.04f, 36.33f);

            if (buttonMask & BUTTON_2)
                LOG("Toggle Button 2");

                toggleVirtualButton(imageTarget, virtualButtonColors[1],
                                    -121.03f, -34.6f, -79.04f, -81.31f);
            if (buttonMask & BUTTON_3)
                LOG("Toggle Button 3");

                toggleVirtualButton(imageTarget, virtualButtonColors[2],
                                    79.04f, 83.04f, 119.8f, 36.33f);
            if (buttonMask & BUTTON_4)
                LOG("Toggle Button 4");

                toggleVirtualButton(imageTarget, virtualButtonColors[3],
                                    79.04f, -34.6f, 119.8f, -81.31f);
			if (buttonMask & BUTTON_5)
                LOG("Toggle Button 5");

                toggleVirtualButton(imageTarget, virtualButtonColors[4],
                                    -10, 10, 10, -10);

The problem is that, only the 5th button is pressable. why the other button do not work?


Problem in virtual button coordinate

October 17, 2013 - 8:49pm #7
Hi, where should i put this code?
mSoundManager = new SoundManager(getApplicationContext());
It seem to be wrong to put in anywhere in initApplicationAR.
Below is my code:
private void initApplicationAR()
        mGlView.setOnClickListener(new OnClickListener(){
            public void onClick(View v) {
            mSoundManager = new SoundManager(getApplicationContext());
                // Autofocus action resets focus mode
                mFocusMode = FOCUS_MODE_NORMAL;


Problem in virtual button coordinate

October 17, 2013 - 4:35am #6

Glad to hear that is now works!

Concerning the Sound effect, make sure that the Java method playSound is in the right class and has the right signature (corresponding to the JNI C++ code that you have written to invoke it)... but note that how to play sounds is not Vuforia-related.


Problem in virtual button coordinate

October 17, 2013 - 1:30am #5

Thanks. It works now. I changed the Sensitivity to low, it work better.

Now, I would like to add sound, but when i run the app, it cannot be run, where it show a message said the application is stopped unexpectedly and need to force stop.

This is my code in cpp:

if (strcmp(button.getName(), "worda") == 0)
					// Assumptions:
					textureIndex = 0;
					const Texture* const thisTexture0 = textures[textureIndex];
					// Scale 3D model
					QCAR::Matrix44F modelViewScaled = modelViewMatrix;
					SampleUtils::scalePoseMatrix(kTeapotScale, kTeapotScale, kTeapotScale,

					QCAR::Matrix44F modelViewProjectionScaled;

					// Render 3D model

					glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
										  (const GLvoid*) &teapotVertices[0]);
					glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
										  (const GLvoid*) &teapotNormals[0]);
					glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
										  (const GLvoid*) &teapotTexCoords[0]);


					glBindTexture(GL_TEXTURE_2D, thisTexture0->mTextureID);
					glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
									   (GLfloat*)&modelViewProjectionScaled.data[0] );
					glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/);
								   (const GLvoid*) &teapotIndices[0]);
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_initNativeCallback(JNIEnv* env, jobject obj)
    // Store the java environment for later use
    // Note that this environment is only safe for use in this thread
    javaEnv = env;

    // Store the calling object for later use
    // Make a global reference to keep it valid beyond the scope of this function
    javaObj = env->NewGlobalRef(obj);

    // Store the class of the calling object for later use
    jclass objClass = env->GetObjectClass(obj);
    javaClass = (jclass) env->NewGlobalRef(objClass);

void playSoundEffect(int soundIndex, float volume)
    // Sound playback is always handled by the Android SDK
    // Use the environment and class stored in initNativeCallback
    // to call a Java method that plays a sound
    jmethodID method = javaEnv->GetMethodID(javaClass, "playSound", "(IF)V");
    javaEnv->CallVoidMethod(javaObj, method, soundIndex, volume);

Do I miss out anything?



Problem in virtual button coordinate

October 17, 2013 - 12:13am #4

Ok, this will need to be debugged a bit; for example, one thing you may try is to replace one of the 4 Buttons of the VB sample with another one (e.g. located at a slightly different position) and see what happens. Also, make sure to update the dataset.xml as well, so that the C++ code and the XML include the same set of Virtual buttons.

Problem in virtual button coordinate

October 16, 2013 - 7:25pm #3

I had change several size. But only the middle(5th) button is worked. My button size is 250 x 280 and my image size is 1500 x 1050.

I had read the guide several times.



Problem in virtual button coordinate

October 16, 2013 - 3:57am #2

Make sure that the Virtual Buttons are all defined within the Image targets boundary and have appropriate size;

see also the developer guide - Virtual Buttons section, for more details:



Log in or register to post comments