Log in or register to post comments

Problem in rendering object

October 28, 2013 - 11:08pm #1

Hi, I am doing the integration of vuforia and jpct-ae library. I follow step by step the tutorial, but there is nothing render when i point the camera on the marker. Can anyone tell me what's wrong with my code.

ImageTargetsRenderer.java
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();
	
		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();

    }

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

        // 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();
        
        world.renderScene(fb);
        world.draw(fb);
        fb.display(); 
    }
    
    public void updateCamera() {
    	Matrix m = new Matrix();
    	m.setDump(modelViewMat);
            cam.setBack(m);
    }
    
    public void updateModelviewMatrix(float mat[]) {
        modelViewMat = mat;
    }

ImageTarget.cpp

JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv *, jobject)
{
	jclass activityClass = javaEnv->GetObjectClass(javaObj); //We get the class of out activity
	//jmethodID updateMatrixMethod = javaEnv->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 = javaEnv->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]);

		if (trackable.getType() == QCAR::Trackable::IMAGE_TARGET) {
			jmethodID updateMatrixMethod = javaEnv->GetMethodID(activityClass, "updateModelviewMatrix", "([F)V");
			javaEnv->SetFloatArrayRegion(modelviewArray, 0, 16, modelViewMatrix.data);
			javaEnv->CallVoidMethod(javaObj, updateMatrixMethod , modelviewArray);
		} 
		// Passes the model view matrix to java
		//javaEnv->SetFloatArrayRegion(modelviewArray, 0, 16, modelViewMatrix.data);
		//javaEnv->CallVoidMethod(javaObj, updateMatrixMethod , modelviewArray);
	}
	javaEnv->DeleteLocalRef(modelviewArray);
    QCAR::Renderer::getInstance().end();
}

 

Log in or register to post comments