Log in or register to post comments

Virtual button on ImageTarget

February 24, 2012 - 9:10am #1

Hi everyone,

first of all, many compliments for the SDK, very very helpful. I'm planning to use it in future projects.

I created a project from ImageTarget project and I added three ImageTarget inside a dataset. I added the management of tapevent as described by ksiva in https://ar.qualcomm.at/arforums/showpost.php?p=70&postcount=2. Everythink work great.
Now I want to manage the same event of "tap" on screen but on tapping the 3d object on the scene.
To reach this goal I want to add a virtual button on an ImageTarget. I edited the config file adding the tag inside the tag and adding in the "renderFrame" method somethinj like

// Did we find any trackables this frame?
for(int tIdx = 0; tIdx {
// Get the trackable:
const QCAR::Trackable* trackable = state.getActiveTrackable(tIdx);
modelViewMatrix =
QCAR::Tool::convertPose2GLMatrix(trackable->getPose());

/** start virtual button code **/

const QCAR::ImageTarget* target = static_cast(trackable);

const QCAR::VirtualButton* button = target->getVirtualButton(0);

if (button->isPressed())
{
LOG("-------- virtual button pressed -----------");
// here handle tap management
}
else
{
// here render objects
.....
}

I can't understand the behaviour of my code: I touch the object in the scene but nothing appens, in a second moment starts an infinite loop "------virtual button pressed-------".

I'm using
- the vuforia sdk 1.5.9.
- the teapot target image

Thanks a lot in advance.
Saverio

Re: Virtual button on ImageTarget

February 26, 2012 - 2:21pm #2

button->isPressed() will return true for every frame that the button is occluded. That means you need to do a little more work to detect the moment the button is first pressed. Try using a global variable to keep track of the current state of the button, something like this:

// global var
bool buttonIsPressed = false;

JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv* env, jobject obj)
{
    ...

        if (button->isPressed())
        {
            if (!buttonIsPressed)
            {
                LOG("-------- virtual button pressed -----------");
                // here handle tap management
                buttonIsPressed = true;
            }
        }
        else
        {
            buttonIsPressed = false;
        }
    ...
}

- Kim

Log in or register to post comments