JPCT + QCAR problem of applying the matrix to the camera

Started by teal03, August 28, 2013, 07:52:14 AM

Previous topic - Next topic

teal03

Hello, I want to see my obj is rendered on Marker in real Camera background. I followed your sample code but it's not working.
Native code is working but in java code not working when i attach updateCamera() in onDrawFrame.
How can i do that??

my ImageTargetsRenderer.java code

private float[] modelViewMat=null;  // create the Value of modelViewMat : is it right?

public ImageTargetsRenderer(ImageTargets activity) {
    this.mActivity = activity;
    world = new World();
    world.setAmbientLight(20, 20, 20);
   
    sun = new Light(world);
    sun.setIntensity(250, 250, 250);
   
    Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(mActivity.getResources().getDrawable(R.drawable.markman)), 64, 64));
TextureManager.getInstance().addTexture("texture", texture);

    obj = Object3D.mergeAll(Loader.loadOBJ(mActivity.getResources().openRawResource(R.raw.mark_obj), mActivity.getResources().openRawResource(R.raw.mark_mtl), 25));

    obj.setTexture("texture");
    obj.strip();
    obj.build();

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

    }
   
    public void updateModelviewMatrix(float mat[]) {
        modelViewMat = mat;
    }


    /** 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");
       
        if (fb != null) {
            fb.dispose();
       }
       fb = new FrameBuffer(width, height);
       
        updateRendering(width, height);
        QCAR.onSurfaceChanged(width, height);
    }

    /** The native render function. */
    public native void renderFrame();
       
    public void updateCamera() {
   
    cam = world.getCamera();
   
    Matrix m = new Matrix();
    m.setDump(modelViewMat);
            cam.setBack(m);
    }
   
     /** Called to draw the current frame. */
    public void onDrawFrame(GL10 gl)
    {
        if (!mIsActive)
            return;     
        mActivity.updateRenderView();
        renderFrame();
        updateCamera();
       
world.renderScene(fb);
world.draw(fb);
fb.display();
    }


this is JNI C++ renderframe code.

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

jclass activityClass = env->GetObjectClass(obj); //We get the class of out activity

    // 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();

    jmethodID updateMatrixMethod = env->GetMethodID(activityClass, "updateModelviewMatrix", "([F)V");

    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]);
        // Passes the model view matrix to java
        env->SetFloatArrayRegion(modelviewArray, 0, 16, modelViewMatrix.data);
        env->CallVoidMethod(obj, updateMatrixMethod , modelviewArray);
    }
    env->DeleteLocalRef(modelviewArray);


    QCAR::Renderer::getInstance().end();
}


error message

08-28 16:00:01.254: W/dalvikvm(4729): threadid=14: thread exiting with uncaught exception (group=0x411852a0)
08-28 16:00:01.254: E/AndroidRuntime(4729): FATAL EXCEPTION: GLThread 11388
08-28 16:00:01.254: E/AndroidRuntime(4729): java.lang.NullPointerException
08-28 16:00:01.254: E/AndroidRuntime(4729): at com.threed.jpct.Matrix.setDump(Matrix.java:954)
08-28 16:00:01.254: E/AndroidRuntime(4729): at com.qualcomm.QCARSamples.ImageTargets.ImageTargetsRenderer.updateCamera(ImageTargetsRenderer.java:127)
08-28 16:00:01.254: E/AndroidRuntime(4729): at com.qualcomm.QCARSamples.ImageTargets.ImageTargetsRenderer.onDrawFrame(ImageTargetsRenderer.java:138)
08-28 16:00:01.254: E/AndroidRuntime(4729): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1516)
08-28 16:00:01.254: E/AndroidRuntime(4729): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
08-28 16:00:01.274: D/QCAR(4729): ImageTargets::onPause
08-28 16:00:01.279: W/SurfaceView(4729): CHECK surface infomation creating=false formatChanged=false sizeChanged=false visible=false visibleChanged=true surfaceChanged=true realSizeChanged=false redrawNeeded=false left=false top=false
08-28 16:00:01.279: I/QCAR(4729): Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_stopCamera
08-28 16:00:01.484: D/gralloc(4729): unmmap  pid(1857), vaddr(0x5614a000)
08-28 16:00:01.484: E/gralloc(4729): [GR_MD] unmapping from 0x54331000, size=33427456
08-28 16:00:01.484: D/gralloc(4729): unmmap  pid(1857), vaddr(0x5a2cd000)
08-28 16:00:01.484: E/gralloc(4729): [GR_MD] unmapping from 0x583ce000, size=33427456
08-28 16:00:01.489: D/gralloc(4729): unmmap  pid(1857), vaddr(0x5a46a000)
08-28 16:00:01.489: E/gralloc(4729): [GR_MD] unmapping from 0x5a46a000, size=33427456
08-28 16:00:01.494: D/gralloc(4729): unmmap  pid(1857), vaddr(0x5c533000)
08-28 16:00:01.494: E/gralloc(4729): [GR_MD] unmapping from 0x5c4c0000, size=33427456
08-28 16:00:01.494: D/gralloc(4729): unmmap  pid(1857), vaddr(0x5e5a3000)
08-28 16:00:01.494: E/gralloc(4729): [GR_MD] unmapping from 0x5e4bd000, size=33427456
08-28 16:00:01.499: D/gralloc(4729): unmmap  pid(1857), vaddr(0x605f7000)
08-28 16:00:01.499: E/gralloc(4729): [GR_MD] unmapping from 0x6049e000, size=33427456
08-28 16:00:01.499: D/gralloc(4729): unmmap  pid(1857), vaddr(0x6264b000)
08-28 16:00:01.499: E/gralloc(4729): [GR_MD] unmapping from 0x6247f000, size=33427456
08-28 16:00:01.504: D/dalvikvm(4729): WAIT_FOR_CONCURRENT_GC blocked 0ms
08-28 16:00:01.544: D/dalvikvm(4729): GC_EXPLICIT freed 505K, 66% free 12405K/35911K, paused 4ms+4ms, total 39ms

EgonOlsen

Your modelViewMat is obviously null...you have to initialize and fill it somewhere.

teal03

Thank you i just initiallize the modelViewMat like this..    

private float[] modelViewMat ={0.0f,0.0f,0.0f,0.0f               
                                            ,0.0f,0.0f,0.0f,0.0f                
                                            ,0.0f,0.0f,0.0f,0.0f                  
                                            ,0.0f,0.0f,0.0f,0.0f};
so it's working!
That's very basic problem. Thanks agian.