Log in or register to post comments

Context Android options

September 16, 2011 - 9:24am #1

Hello,

I'm having a problem that I have no idea how to solve.

When a trackable is detected it is suppose o open a android list view with some option on top of it. I've been able to send to android the name of the trackable and it's coordinates. The problem is that the coordinates don't match the screen coordinates.

Here is the code I have so far on the ImageTargets.cpp:

JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv * env, jobject obj)
{
    //LOG("Java_com_qualcomm_QCARSamples_ImageTargets_GLRenderer_renderFrame");

    // Clear color and depth buffer 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Render video background:
    QCAR::State state = QCAR::Renderer::getInstance().begin();

    const QCAR::Tracker& tracker = QCAR::Tracker::getInstance();
    const QCAR::CameraCalibration& cameraCalibration = tracker.getCameraCalibration();
     
    for(int tIdx = 0; tIdx < state.getNumActiveTrackables(); tIdx++)
    {


        // Get the trackable:
        const QCAR::Trackable* trackable = state.getActiveTrackable(tIdx);
	
	

        
        // Compare this trackable's id to a globally stored id
        // If this is a new trackable, find the displayMessage java method and
        // call it with the trackable's name
  
	    
	    QCAR::Vec2F cameraPoint = QCAR::Tool::projectPoint(cameraCalibration, trackable->getPose(), QCAR::Vec3F(0, 0, 0));

	    QCAR::VideoMode videoMode = QCAR::CameraDevice::getInstance().getVideoMode(QCAR::CameraDevice::MODE_DEFAULT);
    	    QCAR::VideoBackgroundConfig config = QCAR::Renderer::getInstance().getVideoBackgroundConfig();
    
            int xOffset = ((int) screenWidth - config.mSize.data[0]) / 2.0f + config.mPosition.data[0];
            int yOffset = ((int) screenHeight - config.mSize.data[1]) / 2.0f - config.mPosition.data[1];
    
            QCAR::Vec2F screenPoint = QCAR::Vec2F(cameraPoint.data[0] * config.mSize.data[0] / (float) videoMode.mWidth + xOffset,
                       cameraPoint.data[1] * config.mSize.data[1] / (float) videoMode.mHeight + yOffset);


	    char mystring[128];
	    sprintf(mystring, "track: %s x: %f y: %f", trackable->getName(), screenPoint.data[0], screenPoint.data[1]);
	    jstring js = env->NewStringUTF(mystring);

            jclass javaClass = env->GetObjectClass(obj);
            jmethodID method = env->GetMethodID(javaClass, "displayMessage", "(Ljava/lang/String;)V");
            env->CallVoidMethod(obj, method, js);
    }
    QCAR::Renderer::getInstance().end();
}

I got the coordinates code from another post.

Could someone help me please? I'm really in a jam.

Thanks

Re: Context Android options

September 20, 2011 - 10:20am #3

Thanks Kim,

That has it. It works perfectly.

Re: Context Android options

September 16, 2011 - 11:57am #2

Are you trying to display that message in a Toast? If so it won't keep up, you can't refresh a Toast each frame. Try printing your string from native first: LOG("%s", &mystring[0]);

Are you running your application in Portrait mode? The transforms given there are calculated for Landscape.

Finally, note that these coordinates represent the center of the target.

- Kim

Log in or register to post comments