Problem with integration of Jpct-ae and Vuforia

Started by Maro, April 23, 2013, 01:40:38 PM

Previous topic - Next topic

Maro

Hi, in these days i started to looking for a good sdk to combine with Vuforia.
I think this one is pretty good so i started to use, but i've encountered some problem.
Can someone help me?

I followed step by step this helpful guide: http://www.jpct.net/wiki/index.php/Integrating_JPCT-AE_with_Vuforia

But when I call the function updateCamera(), i have ever the same error:
This is my code:

  public ImageTargetsRenderer(ImageTargets activity){
    this.mActivity = activity;
    world = new World();
    world.setAmbientLight(20, 20, 20);

    sun = new Light(world);
    sun.setIntensity(250, 250, 250);

    // Create a texture out of the icon...:-)
    Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(mActivity.getResources().getDrawable(R.drawable.ic_launcher)), 64, 64));
    TextureManager.getInstance().addTexture("texture", texture);

    cube = Primitives.getCube(10);
    cube.calcTextureWrapSpherical();
    cube.setTexture("texture");
    cube.strip();
    cube.build();
    cube.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS|Object3D.COLLISION_CHECK_SELF);
cube.setCollisionOptimization(true);

    world.addObject(cube);

    cam = world.getCamera();
    //cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
    //cam.lookAt(cube.getTransformedCenter());

    SimpleVector sv = new SimpleVector();
    sv.set(cube.getTransformedCenter());
    sv.y -= 100;
    sv.z -= 100;
    sun.setPosition(sv);
    MemoryHelper.compact();

    }

    /** Native function for initializing the renderer. */
    public native void initRendering();

    /** Native function to update the renderer. */
    public native void updateRendering(int width, int height);

    /** Called when the surface is created or recreated. */
    public void onSurfaceCreated(GL10 gl, EGLConfig config)
    {
        DebugLog.LOGD("GLRenderer::onSurfaceCreated");

        // Call native function to initialize rendering:
        initRendering();

        // Call QCAR function to (re)initialize rendering after first use
        // or after OpenGL ES context was lost (e.g. after onPause/onResume):
        QCAR.onSurfaceCreated();
    }


    /** Called when the surface changed size. */
    public void onSurfaceChanged(GL10 gl, int width, int height)
    {
    DebugLog.LOGD("GLRenderer::onSurfaceChanged");

    // Call native function to update rendering when render surface
    // parameters have changed:
    updateRendering(width, height);

    // Call QCAR function to handle render surface size changes:
    QCAR.onSurfaceChanged(width, height);

    if (fb != null) {
    fb.dispose();
    }
    fb = new FrameBuffer(width, height);
    }


    /** The native render function. */
    public native void renderFrame();


    /** Called to draw the current frame. */
    public void onDrawFrame(GL10 gl)
    {
        if (!mIsActive)
            return;
       
        // Update render view (projection matrix and viewport) if needed:
        mActivity.updateRenderView();

        // Call our native function to render content
        renderFrame();
       
        updateCamera();
       
        world.renderScene(fb);
        world.draw(fb);
        fb.display();
       
    }
   
    public void updateModelviewMatrix(float mat[]) {
        modelViewMat = mat;
    }
   
    public void updateCamera() {
    Matrix m = new Matrix();
    m.setDump(modelViewMat);
        cam.setBack(m);
    }


and this is my logcat:

04-23 13:24:50.255: E/AndroidRuntime(13001): FATAL EXCEPTION: GLThread 14
04-23 13:24:50.255: E/AndroidRuntime(13001): java.lang.NullPointerException
04-23 13:24:50.255: E/AndroidRuntime(13001): at com.threed.jpct.Matrix.setDump(Matrix.java:955)
04-23 13:24:50.255: E/AndroidRuntime(13001): at com.example.vuforiajpctae.ImageTargetsRenderer.updateCamera(ImageTargetsRenderer.java:160)
04-23 13:24:50.255: E/AndroidRuntime(13001): at com.example.vuforiajpctae.ImageTargetsRenderer.onDrawFrame(ImageTargetsRenderer.java:146)
04-23 13:24:50.255: E/AndroidRuntime(13001): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1388)
04-23 13:24:50.255: E/AndroidRuntime(13001): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1138)


the problem is about the function setDump in updateCamera, but i don't know how to fix, i tryed everything...
Please, healp me!

Maro

After some debug i discovered setDump() error is caused from modelViewMat, because it is null.
Now the new question is, why that array is not filled by the native function?

my code native function:

JNIEXPORT void JNICALL
Java_com_example_vuforiajpctae_ImageTargetsRenderer_renderFrame(JNIEnv *env, jobject obj)
{
jclass activityClass = env->GetObjectClass(obj); //We get the class of out activity
jmethodID updateMatrixMethod = env->GetMethodID(activityClass, "updateModelviewMatrix", "([F)V");
    // Clear color and depth buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    // Get the state from QCAR and mark the beginning of a rendering section
    QCAR::State state = QCAR::Renderer::getInstance().begin();
    // Explicitly render the Video Background
    QCAR::Renderer::getInstance().drawVideoBackground();
    // Did we find any trackables this frame?
    jfloatArray modelviewArray = env->NewFloatArray(16);
    for(int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++)
    {
        // Get the trackable:
        const QCAR::TrackableResult* result = state.getTrackableResult(tIdx);
        const QCAR::Trackable& trackable = result->getTrackable();
        QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose());

        SampleUtils::rotatePoseMatrix(180.0f, 1.0f, 0, 0, &modelViewMatrix.data[0]);
        env->SetFloatArrayRegion(modelviewArray, 0, 16, modelViewMatrix.data);
        env->CallVoidMethod(obj, updateMatrixMethod , modelviewArray);
    }
    env->DeleteLocalRef(modelviewArray);
    //QCAR::Renderer::getInstance().end();

}


THX

EgonOlsen

No idea...maybe kelmer can help. He wrote that tutorial...

Maro

Ok i found the solution, i post it in the case someone will read.

In the native function the array is initialize only if marker is currently track.
So in the java code i use an if to dected when the array is null, in that case i simply do nothing, waiting for another call of that function, when finally is not null i can execute the portion of code who gave me some problem

the code here:

    Matrix m = new Matrix();
    if(modelViewMat!=null)
    {
    m.setDump(modelViewMat);
    cam.setBack(m);
    }

binspaul

Hello All,

I have found an issue in the Vuforia and jPCT-AE integration. I was following the steps mentioned in the url: http://www.jpct.net/wiki/index.php/Integrating_JPCT-AE_with_Vuforia.

You will be able to get the 3D cube when the 'Start' button is pressed. When you press the back button, you will reach the start up screen again. When you press the 'Start' button again, the system will throw an exception telling that 'Texture' already exists. You can fix this by checking if we are having a valid texture in the constructor or you can wrap the code in a try-catch block.

---
try {
         
Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(mActivity.getResources().getDrawable(R.drawable.ic_launcher)), 64, 64));
         TextureManager.getInstance().addTexture("texture", texture);
         
} catch (Exception e) {

}
---

Thanks,
Binu Paul
Thanks & Regards,
Binu Paul