Overlaying of multiple objects according to relative position to camera

Started by Anuxander, August 14, 2013, 09:06:19 AM

Previous topic - Next topic

Anuxander

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 :

                //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 :

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!

EgonOlsen

Sounds like as if your gl config has no depth buffer set. How are creating the gl context? Does Vuforia do this for you?

Anuxander

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?

EgonOlsen

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.

Anuxander

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:

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:)