2

i know what i am going to ask is already discussed sometimes but after going through all of them i can't found my complete answer so i am asking a new question

when i tried integrating JPCT-ae with QCAR all goes well as expected, i got my modelview matrix from renderframe from jni and successfully transferred that in java to jpct model is shown perfectly as expected. but when i tried to pass this matrix to JPCT world camera my model disappear.

my code:in onsurfacechanged:

world = new World();
            world.setAmbientLight(20, 20, 20);
            sun = new Light(world);
            sun.setIntensity(250, 250, 250);
            cube = Primitives.getCube(1);
            cube.calcTextureWrapSpherical();
            cube.strip();
            cube.build();
            world.addObject(cube);
            cam = world.getCamera();
            cam.moveCamera(Camera.CAMERA_MOVEOUT, 10);
            cam.lookAt(cube.getTransformedCenter());
            SimpleVector sv = new SimpleVector();
            sv.set(cube.getTransformedCenter());
            sv.y -= 100;
            sv.z -= 100;
            sun.setPosition(sv);
            MemoryHelper.compact();

and in ondraw:

com.threed.jpct.Matrix mResult = new com.threed.jpct.Matrix();
            mResult.setDump(modelviewMatrix );  //modelviewMatrix i get from Qcar
            cube.setRotationMatrix(mResult);
            cam.setBack(mResult);
                     fb.clear(back);
        world.renderScene(fb);
        world.draw(fb);
        fb.display();

after some research i found that QCAR uses a right-handed coordinate system meaning that the X positive goes right, the Y positive goes up and the Z positive comes out of screen but in JPCT coordinate system the X positive goes right, the Y positive goes down and the Z positive goes into the screen.

Qcar coordinate system:

QCAR coordinate system

i know that matrix QCar is giving is a 4*4 matrix having 3*3 rotational values and translation vector .

i am posting matrices to be more clear:

modelviewmatrix:

1.512537      -159.66255   -10.275316   0.0
-89.86529      -1.1592013   4.7839375            0.0
-8.619186     10.179538     -159.44305   0.0
59.182976        93.205956     437.2832            1.0

modelviewmatrix after reverse using cam.setBack(modelviewmatrix.invert(modelviewmatrix)) :

5.9083453E-5   -0.01109448   -3.3668696E-4   0.0
0.0040540528   -3.8752193E-4   0.0047518034   0.0
-0.004756433   -4.6811014E-4   0.0040459237   0.0
0.7533285     0.4116795            2.7063704   0.9999999

if i remove 13,14 and 15 matrix element assuming 3*3 rotation matrix...model is rotated properly but translation(in and out movement of image) is not there finally i dont know what changes translation vector is needed. so please suggest me what i am missing here?

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
mrYogi
  • 992
  • 2
  • 9
  • 29
  • hi , could you tell me how to get the modelview matrix from renderframe via jni? – Fugogugo Nov 03 '12 at 10:20
  • from jni in renderframe get modelview matrix and pass it to java like this:// Passing the Modelview matrix up to Java jclass javaClass = env->GetObjectClass(obj); jfloatArray modelviewArray = env->NewFloatArray(16); jmethodID method = env->GetMethodID(javaClass, "updateModelviewMatrix", "([F)V"); ... // Passing the ModelView matrix up to Java (cont.) env->SetFloatArrayRegion(modelviewArray, 0, 16, modelViewMatrix.data); env->CallObjectMethod(obj, method, modelviewArray); env->DeleteLocalRef(modelviewArray);in java you will get value in updateModelviewMatrix method,sorry for code formetting – mrYogi Nov 03 '12 at 10:47
  • hey, how about set the camera position using 13, 14, 15 element you just removed? – jaredzhang Nov 06 '12 at 05:25
  • how can i set cam position with these values? – mrYogi Nov 06 '12 at 05:55
  • I know this was a while ago, but were you able to use JPCT? I tried originally and couldn't figure it out, so I'm using gamekit now. The tracking seems to be working correctly at least. If I remember correctly, one of the mods was saying JPCT didn't support direct matrix usage. Oh, I found this article though. Maybe it helps? http://www.jpct.net/wiki/index.php/Integrating_JPCT-AE_with_Vuforia – mpellegr Aug 23 '13 at 14:24
  • yes u r late in the party, jpct takes vuforia matrix with changes in coordinate axis. the link you provided work nearly fine for me.but my current prblm is that this works good only when app is in landscape, but in potrait its become very unstable(shaky).. – mrYogi Aug 26 '13 at 04:12

1 Answers1

0

QCAR::Matrix44F inverseMatrix = SampleMath::Matrix44FInverse(modelViewMatrix); QCAR::Matrix44F invTransposeMatrix = SampleMath::Matrix44FTranspose(inverseMatrix);

then pass the invTransposeMatrix value to java

env->SetFloatArrayRegion(modelviewArray, 0, 16, invTransposeMatrix.data); env->CallVoidMethod(obj, method, modelviewArray);

hari
  • 69
  • 4