Log in or register to post comments

integrating JPCT-ae with QCAR(vuforia)

October 22, 2012 - 12:02am #1

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?

integrating JPCT-ae with QCAR(vuforia)

October 15, 2014 - 7:23am #15

hi, 

i have question on this project. How to change image target(stone and chips or tarmac) in this project. I can't change the stonesAndChips whatever i do. May you help me ?

integrating JPCT-AE with Vuforia

November 12, 2013 - 3:34pm #14

Hi,

I have integrated Vuforia and JPCT-AE following the tutorial (http://www.jpct.net/wiki/index.php/Integrating_JPCT-AE_with_Vuforia) and pushed the project on Github.

You can find the project here: https://github.com/sidneibjunior/vuforia-jpct

Glad that I was helpful. Just

January 6, 2013 - 12:30am #13

Glad that I was helpful.

Just in case you want to get some more info about the relation between camera FOV and projection matrix,

you may find this Post useful (this is in the FAQ section of our Forum):

https://developer.vuforia.com/forum/faq/technical-how-do-i-build-my-own-camera-projection-matrix

If you have other questions, don't hesitate to post them here.

 

Hi AlessandroB Thanks for

January 4, 2013 - 12:39pm #12

Hi AlessandroB

Thanks for your replies. I followed your instructions and the results get better. But it seems something is still missing (I think it is related to Fov). 

I am switching to other opensource 3D framework so that I can intercept the code and directly use projection matrix passed from Vuforia.

Thanks anyway. You've been helpful and Vuforia is really great.

 

 

Hi again marsmedia, just an

January 3, 2013 - 3:46am #11

Hi again marsmedia,

just an additional note, if it can be of additional help:

the modelviewMatrix from QCAR represents the position/orientation of the target (world reference) with respect to the camera reference;

if in JPCT you want to set the position and orientation of the Camera with respect to the world reference system (i.e. the opposite of what QCAR does), you could do the following:

- invert the modelviewMatrix from QCAR, using the function  static QCAR::Matrix44F Matrix44FInverse(QCAR::Matrix44F& m) which is defined in SampleMath.h in the Dominoes sample

- extract the components mat[12], mat[13] and mat[14] of such inverted matrix; those components will represent the position X,Y,Z of the camera with respect to the target (world) reference frame; 

- set the JPCT camera position: camera.setposition( X, Y, Z ); using the components computed at previous point;

- set the JPCT camera to "lookAt" some world location (e.g. lookAT( 0, 0, 0 ) to look toward the center of the image target, i.e. the center of the world)

I hope this helps.

 

Hi marsmedia, I don't know

January 2, 2013 - 2:30am #10

Hi marsmedia,

I don't know exactly how the JPCT handles matrices internally and which functions (setDump / setBack) are the correct ones to use in JPCT, however I can explain here how the OpenGL modelview matrix (from QCAR) is organized internally:

- the elements modelviewMat [0], modelviewMat [1] amd modelviewMat [2] represent the 3 components of the local X-axis of the image target (i.e. the "world") represented in the camera reference frame

- the elements modelviewMat [4], modelviewMat [5] amd modelviewMat [6] represent the 3 components of the local Y-axis of the image target (i.e. the "world") represented in the camera reference frame

- the elements modelviewMat [8], modelviewMat [9] amd modelviewMat [10] represent the 3 components of the local Z-axis of the image target (i.e. the "world") represented in the camera reference frame

- the elements modelviewMat [12], modelviewMat [13] and modelviewMat [14] represent the translation (x,y,z) of the image target (i.e. the "world") with respect to the camera reference frame

 

Also, the camera reference frame in QCAR is such that the positive Z-axis is entering the screen and the positive Y-axis is screen-aligned but pointing downward (so you usually need a 180 deg rotation around X to have Y pointing up and Z exiting the screen, as I also mentioned in a previous post)

 

Hi I am facing the same

January 1, 2013 - 1:36am #9

Hi

I am facing the same problem. After passing the matrix from the native code to Java, I don't know how to convert the Vuforia modelViewMatrix to jpct matrix.

The closest answer I can find is at: http://www.jpct.net/forum2/index.php/topic,2461.msg18413.html#msg18413

 

I came up with the following. But the 3D Object is not showing. What am I missing?
 
public void setCameraMatrix(float[] modelViewMatrixFromVuforia) {
 
float x = modelViewMatrixFromVuforia[12];
float y = modelViewMatrixFromVuforia[13];
float z = modelViewMatrixFromVuforia[14];
 
modelViewMatrixFromVuforia[12] = 0;
modelViewMatrixFromVuforia[13] = 0;
modelViewMatrixFromVuforia[14] = 0;
 
Matrix cameraMatrix = new Matrix();
cameraMatrix.setDump(modelViewMatrixFromVuforia);
 
cameraMatrix = cameraMatrix.invert();
cameraMatrix.rotateX((float)Math.PI); // Folowing the instructions of AlessandroB
camera.setBack(cameraMatrix);
camera.setPosition(x, y, z);
 
}
 

 

integrating JPCT-ae with QCAR(vuforia)

October 22, 2012 - 1:11pm #8

Hi, I think I'm not fully understanding what you are trying to do; I see in your original code that you set the mResult matrix both in the Cube object and in the camera; normally it should be sufficient to do either one transformation or the other (i.e. either the camera or the object);

maybe it would help if you could provide all the logic, or copy paste here the relevant part of your code with some comments explaining what you do with your JPCT objects and matrices; 

then maybe we can try to sort it out ...

 

integrating JPCT-ae with QCAR(vuforia)

October 22, 2012 - 4:38am #7

hi AlessandroB,

thanks for your reply..but multiplying after inverting model disappeared , i got modelviewmatrix from

QCAR::Matrix44F modelViewMatrixKeyframe = QCAR::Tool::convertPose2GLMatrix(trackable->getPose());

matrix i posted earlier ,could you please inspect matrix and tell me if it is of correct formation? after passing this matrix to java i am doing two steps: 1.converting by multiplying as you suggested. 2.inverting the matrix. then i set the resulted matrix to renderer camera . after following these steps model is not appearing but if i do invert after multiply it appear but translation and rotation are not completely correct as it should be...

integrating JPCT-ae with QCAR(vuforia)

October 22, 2012 - 4:38am #6

hi AlessandroB,

thanks for your reply..but multiplying after inverting model disappeared , i got modelviewmatrix from

QCAR::Matrix44F modelViewMatrixKeyframe = QCAR::Tool::convertPose2GLMatrix(trackable->getPose());

matrix i posted earlier ,could you please inspect matrix and tell me if it is of correct formation? after passing this matrix to java i am doing two steps: 1.converting by multiplying as you suggested. 2.inverting the matrix. then i set the resulted matrix to renderer camera . after following these steps model is not appearing but if i do invert after multiply it appear but translation and rotation are not completely correct as it should be...

integrating JPCT-ae with QCAR(vuforia)

October 22, 2012 - 4:38am #5

hi AlessandroB,

thanks for your reply..but multiplying after inverting model disappeared , i got modelviewmatrix from

QCAR::Matrix44F modelViewMatrixKeyframe = QCAR::Tool::convertPose2GLMatrix(trackable->getPose());

matrix i posted earlier ,could you please inspect matrix and tell me if it is of correct formation? after passing this matrix to java i am doing two steps: 1.converting by multiplying as you suggested. 2.inverting the matrix. then i set the resulted matrix to renderer camera . after following these steps model is not appearing but if i do invert after multiply it appear but translation and rotation are not completely correct as it should be...

integrating JPCT-ae with QCAR(vuforia)

October 22, 2012 - 3:52am #4

Hi, this could be due to some wrong order of multiplication of the matrices; the "conversion matrix" (rotation of 180 deg around X); try multiply the converison matrix after doing the matrix inversion, and not before.....the thing is, the matrix conversion should represent really the last step in your matrix chain (i.e. the step closest to the camera reference and not closest to the object reference frame), because it just represents a different camera frame.

 

integrating JPCT-ae with QCAR(vuforia)

October 22, 2012 - 3:47am #3

Hi,

i did the conversion as you said and then done the invert of matrix and set on camera..results are better than before but there are two problems still persist:

1.translation in left to right is incorrect(however other two axis have correct translation).

2.rotaion is correct but if one complete rotation of camera  is done model is misplaced little from it's origin.

plz help me outFrown.

integrating JPCT-ae with QCAR(vuforia)

October 22, 2012 - 1:43am #2

Hi, both QCAR and JPCT use a right-handed reference frame, however the JPCT camera reference frame is just rotated by 180 degrees around the X axis (so y points downward and Z points into the screen as you correctly explained);

so, in practice if you want to pass from one system to the other you have to multiply the QCAR modelview matrix by a "conversion matrix" which represents just a 180-deg rotation around X; in practice this is just an axis direction inversion of Y and Z, so this "conversion matrix" is nothing more than the following:

1   0    0    0

0  -1    0    0

0   0    -1    0

0    0    0    1

I hope this helps.

 

Log in or register to post comments