Author Topic: jPCT + vuforia => multi targets with multi objects  (Read 2636 times)

Offline rafael_afn

  • byte
  • *
  • Posts: 10
    • View Profile
jPCT + vuforia => multi targets with multi objects
« on: September 11, 2015, 12:35:25 am »
Hi

I did Vuforia integration with jpct using native java \ o /

I would like to be able to print two objects on the screen in different targets.

In onDrawFrame method I have those calls:
Code: [Select]
@Override
    public void onDrawFrame(GL10 gl){
        if (!mIsActive)
            return;
       
        // Call our function to render content
        renderFrame();

        updateCamera();

        if(isMarker){
            world.renderScene(fb);
            world.draw(fb);

            GLES20.glDisable(GLES20.GL_DEPTH_TEST);
        }else{
            fb.flush();
        }

        fb.display();
    }

In renderFrame, the targets are recognized in this code snippet:
Code: [Select]
for (int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++) {
            TrackableResult result = state.getTrackableResult(tIdx);
            Trackable trackable = result.getTrackable();
            printUserData(trackable);
            modelViewMatrix_Vuforia = Tool.convertPose2GLMatrix(result.getPose());

            Matrix44F inverseMV = SampleMath.Matrix44FInverse(modelViewMatrix_Vuforia);
            Matrix44F invTranspMV = SampleMath.Matrix44FTranspose(inverseMV);

            modelViewMatrix = invTranspMV.getData();

            //LANDSCAPE: 0, 180.0f, 0, 0, 1.0f
            //PORTRAIT: 0, -90.0f, 0, 0, 1.0f
            Matrix.rotateM(modelViewMatrix, 0, 90.0f, 0, 0, 1.0f);

            mCameraPosition = new SimpleVector(modelViewMatrix[12], modelViewMatrix[13], modelViewMatrix[14]);
            mCameraDirection = new SimpleVector(modelViewMatrix[8], modelViewMatrix[9], modelViewMatrix[10]);
            //LANDSCAPE: 0, 1, 2
            //PORTRAIT: 4, 5, 6
            mCameraUp = new SimpleVector(-modelViewMatrix[0], -modelViewMatrix[1], -modelViewMatrix[2]);

            SampleUtils.checkGLError("Render Frame");
        }

Note that the camera coordinates are defined for each detected target.
But the camera is only updated the loop end, then it only receives the coordinate of the last target. (See the order of calls onDrawFrame)

I need to draw an object in the target 1 and B 2 on the target object.

Can anyone help me, I can not imagine how to upgrade the camera coordinates to display the object and then upgrade to display object B.

updateCamera method:
Code: [Select]
public void updateCamera() {
        if (modelViewMatrix != null) {
            com.threed.jpct.Matrix m = new com.threed.jpct.Matrix();
            m.setDump(modelViewMatrix);
            cam.setBack(m);

            cam.setOrientation(mCameraDirection, mCameraUp);
            cam.setPosition(mCameraPosition);
        }
    }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: jPCT + vuforia => multi targets with multi objects
« Reply #1 on: September 11, 2015, 08:18:43 am »
Are you sure that you actually want to update the camera and not the object's transformation instead? Anyway, you can't do this with one world instance. What you could do is to create 2 worlds, add each object to it's own and render them both with different cameras.

Offline rafael_afn

  • byte
  • *
  • Posts: 10
    • View Profile
Re: jPCT + vuforia => multi targets with multi objects
« Reply #2 on: September 11, 2015, 03:32:19 pm »
Ok, I'll try your approach.

I implemented this solution:
When I recognize the target 1, remove all objects of my world, I add the object to be printed on this target.
When I recognize the target 2, remove all objects of my world, I add the object to be printed on this target.
(Solution tested and working for two objects. I do not know the behavior for various objects or complex objects)

Now I will try what you said, create an object and a camera for each world. See which has the best performance.

Post the result here so that others can use the same solution.

Thank you

Offline rafael_afn

  • byte
  • *
  • Posts: 10
    • View Profile
Re: jPCT + vuforia => multi targets with multi objects
« Reply #3 on: September 11, 2015, 04:17:04 pm »
Hi EgonOlsen

Both ways worked, great.

Apparently had the same performance. Analyzed by the CPU and memory tools on Android Studio.

Create different worlds, cameras and lights have more work to me, than removing all objects and add what I need on moment.

Which of the two approaches do you recommend I use? Because I do not know what the complexity of jPCT for each approach. What it should work better?

Thanks again.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: jPCT + vuforia => multi targets with multi objects
« Reply #4 on: September 11, 2015, 04:40:57 pm »
Whatever suits you better. A world instance itself doesn't cause much overhead, if any at all. The drawback is that lights and settings are doubled. To me, it's still the cleaner way of doing it, but it all depends on your needs.

Offline rafael_afn

  • byte
  • *
  • Posts: 10
    • View Profile
Re: jPCT + vuforia => multi targets with multi objects
« Reply #5 on: September 11, 2015, 04:48:39 pm »
Ok, I will evaluate what is best for my code.

If I start having performance problems, try another approach.

Thank EgonOlsen for responding so quickly.