Author Topic: Overlaying of multiple objects according to relative position to camera  (Read 2858 times)

Offline Anuxander

  • byte
  • *
  • Posts: 6
    • View Profile
Hi everyone!

I am new to JPCT and this is my very first post. I have been integrating AR (vuforia) with JPCT for a while. And everything works fine except for the part of rendering multiple objects( some md2 ).

I add all objects in the same world :
Code: [Select]
                //translation
firstObj.translate(400.0f, 0.0f, 0.0f);
firstObj.rotateZ(90.0f);
firstObj.rotateY(90.0f);

tester.translate(-400.0f, 0.0f, 0.0f);
tester.rotateZ(90.0f);
tester.rotateY(90.0f);

world.addObject(firstObj);
world.addObject(tester);

cam = world.getCamera();
originalMatrix = cam.getBack();

And whenever I receive a new matrix(modelViewMat) from vuforia I move my camera to that specific location :
Code: [Select]
m.setDump(modelViewMat);
cam.setBack(m);

Here comes my problem, when I move my device camera to a spot where the 2 objects overlap, ideally the one closer to my camera should overlay the further one. But this is not happening to me. Instead, the object which is added later to the world does always appear on top, that is, the tester object in my case.

Is there anything I am missing? What I want is to arrange the order of the objects according to their distance to the camera. Any comments would be very much appreciated, thx!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Overlaying of multiple objects according to relative position to camera
« Reply #1 on: August 14, 2013, 07:53:58 pm »
Sounds like as if your gl config has no depth buffer set. How are creating the gl context? Does Vuforia do this for you?

Offline Anuxander

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Overlaying of multiple objects according to relative position to camera
« Reply #2 on: August 14, 2013, 09:18:57 pm »
Thank for reply :)

Vuforia has its depth test settings while rendering objects with openGL, however, I am not using Vuforia to draw any object. Actually I only obtain a matrix from Vuforia so that I can put my Camera in JPCT to a correct location at run time. Simply saying, anything done in Vuforia only affect the camera location in JPCT. My drawing totally counts on JPCT.

So I am wondering if there is a depth test setting in JPCT?  For instance, with a static camera seeing 2 overlaping objects, the further one should not cover the closer one right?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Overlaying of multiple objects according to relative position to camera
« Reply #3 on: August 14, 2013, 10:09:03 pm »
jPCT uses whatever kind of GL context you provide it. It doesn't care if a depth buffer is present or not and it doesn't create a context on it's own. If the context that Vuforia provides has none, it's an issue with that particular context and not with jPCT. It can't enforce one on a context that has none.

Offline Anuxander

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Overlaying of multiple objects according to relative position to camera
« Reply #4 on: August 15, 2013, 04:42:30 am »
Big thanks to EgonOlsen for the valuable comments which has helped me a lot. I have fixed the problem.

Vuforia has the following depth setting codes working in combination for each rendering:
Code: [Select]
glEable(GL_DEPTH_TEST);
...
...
...
...
glDisable(GL_DEPTH_TEST);

My bug is that Vuforia had run glDisable(GL_DEPTH_TEST) already before JPCT finished its drawing. I guess its the problem...

so I drag away the disable code and things go right now:)