Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Anuxander

Pages: [1]
1
Hi guys, thanks in advance for reading my topic. This is quite a complicated question I guess.

It sounds weird to draw things from 2 places, why wont I draw all models with JPCT? The reason is that QCAR has provided useful codes to draw a "transparent" cylinder/squareBox to act as the TARGET itself. Its transparent texture can show the camera preview screen while blocking any drawn models which lie behind it. I tried to draw the cylinder in JPCT also but I couldn't make such a texture. Even after blending I got it transparent but it fails to block any 3D models lying behind it. So I decided to leave the cylinder drawing to QCAR.

Here is my code in QCAR:
Code: [Select]
                glEnable (GL_DEPTH_TEST);
glEnable (GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// prepare the cylinder

SampleUtils::scalePoseMatrix(kCylinderScaleX, kCylinderScaleY,
kCylinderScaleZ, &modelViewMatrix.data[0]);
SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
&modelViewMatrix.data[0], &modelViewProjection.data[0]);
SampleUtils::checkGlError("CylinderTargets prepareCylinder");

glUseProgram(shaderProgramID);
glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) mCylinderModel.ptrVertices());
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) mCylinderModel.ptrNormals());
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) mCylinderModel.ptrTexCoords());

glEnableVertexAttribArray(vertexHandle);
glEnableVertexAttribArray(normalHandle);
glEnableVertexAttribArray(textureCoordHandle);

glActiveTexture (GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textures[0]->mTextureID);
glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
(GLfloat*) &modelViewProjection.data[0]);
glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/);
glDrawElements(GL_TRIANGLES, mCylinderModel.nbIndices(),
GL_UNSIGNED_SHORT, (const GLvoid*) mCylinderModel.ptrIndices());
So my cylinder is drawn now.

The following passes the matrix of the TARGET to JPCT:
Quote
      modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose());
      SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
            &modelViewMatrix.data[0], &modelViewProjection.data[0]);
      jfloatArray modelviewArray = env->NewFloatArray(16);
      env->SetFloatArrayRegion(modelviewArray, 0, 16, modelViewMatrix.data);
      env->CallVoidMethod(obj, updateMatrixMethod, modelviewArray);
      env->DeleteLocalRef(modelviewArray);
      env->CallVoidMethod(obj, fovMethod, fovRadians);
      env->CallVoidMethod(obj, fovyMethod, fovyRadians);

This is where to receive the matrix in JPCT:
Code: [Select]
public void updateModelviewMatrix(float mat[]) {

modelViewMat = mat;
}

and onDraw:
Code: [Select]
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
modelViewMat = null;
cylinderModelViewMat = null;
renderFrame();    //here call the QCAR native code so that JPCT receives the new matrix
updateCamera();
world.renderScene(fb);
world.draw(fb);
fb.display();


}

The updateCamera method:
Code: [Select]
public void updateCamera() {
Matrix m = new Matrix();
if (modelViewMat != null) {
firstObj.setVisibility(true);
m.setDump(modelViewMat);
cam.setBack(m);
return;
}
firstObj.setVisibility(false);
cam.setBack(originalMatrix);

}

While tracking 3D TARGETS, depth test is very important as animated models may go behind or in front of the targets. So they should be hindered or shown in case. In the above example, there is simply a cylinder drawn in QCAR and a firstObj(a Object3D type md2) drawn in JPCT.

Now the problem Im facing is that when I put my camera close to the target, things go perfect - depth test gives a correct order - e.g firstObj on top of the cylinder, in case that it is closer to the camera. But when I slowly move my camera further from the TARGET, the firstObj "dives" into the cylinder slowly as well ( cylinder gradually rises to top and firstObj gets covered by it), which is not correct accroding to the translation I set.

The firstObj is not supposed to be covered by the cylinder. This just happens when 2 of them overlaps while the camera is pulled away for a certain extent. Other testing like translating and rotating gives no error.

After reading plenty of posts in forums, I suspect this is caused by different coordinates systems from QCAR & JPCT, but I have tried various suggested solutions which do not even output a drawing. Some say that QCAR matrix is column major and JPCT is row major. But why do all other parts of it work perfectly well if the matrix major does matter? I didnt even invert it.

**Note that if I draw the cylinder also in JPCT : Primitives.getCylinder........, then translate it to stick to the virtual target from QCAR, error doesnt happen! No matter how I pull and move my camera, the firstObj and cylinder keep in correct drawing order. The only shame is that I could not give the cylinder a correct "transparent" texture by this. But this case, has proven that the way passing the matrix from QCAR to JPCT is exactly right.

It has been very confusing and I have been struggling to this for several days. If you have any questions or suggestions, please give me a reply. Thank you for reading such a long question!!


2
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!

Pages: [1]