Log in or register to post comments

Frame Index

June 18, 2011 - 4:25am #1

I want to play a sound for a marker when it is detected. I thought i can check the frameIndex for this case, but the Index is always -0. Anybody know why the FrameIndex never change?

Stephan

Re: Frame Index

June 19, 2011 - 9:42pm #3

More to the point though, if you want to do something (e.g. play a sound) when a marker is detected you should just look for the change in status. Here's a code snippet:

int markerStatus[5]; // make this big enough to hold all your markers

JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_FrameMarkers_FrameMarkersRenderer_renderFrame(JNIEnv *env, jobject obj)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    QCAR::State state = QCAR::Renderer::getInstance().begin();
    
    for(int tIdx = 0; tIdx < state.getNumTrackables(); tIdx++)
    {
        const QCAR::Trackable* trackable = state.getTrackable(tIdx);
        assert(trackable->getType() == QCAR::Trackable::MARKER);
        const QCAR::Marker* marker = static_cast<const QCAR::Marker*>(trackable);
        
        int currentStatus = trackable->getStatus();
        int previousStatus = markerStatus[marker->getMarkerId()];
        
        if (previousStatus != currentStatus)
        {
            const char *statusStrings[] = { "UNKNOWN", "UNDEFINED", "NOT_FOUND", "DETECTED", "TRACKED" };
            LOG("marker %d changed status from %s to %s", marker->getMarkerId(), statusStrings[previousStatus], statusStrings[currentStatus]);
            
            if (currentStatus == QCAR::Trackable::DETECTED)
            {
                // this marker was just detected, do something!
            }
            
            markerStatus[marker->getMarkerId()] = currentStatus;
        }
    }
    
    QCAR::Renderer::getInstance().end();
}

- Kim

Re: Frame Index

June 19, 2011 - 8:23pm #2

It should work, here's the way to use it:

QCAR::State state = QCAR::Renderer::getInstance().begin();
QCAR::Frame frame = state.getFrame();
int index = frame.getIndex();
LOG("frame index: %d", index);

- Kim

Log in or register to post comments