Log in or register to post comments

Orthogonal/Perspective Camera View problem

November 16, 2011 - 9:07am #1


we are trying to use QCAR together with jPCT-AE on Android 3.0 on an LG-V900 Optimus Pad device. We want to use both API's in a very unusual way:
- QCAR shall recognize a marker and then the program shall show a 3D model (obj) as an overlay over the (real) camera view.
- That means, the marker only shall activate something like a switch and then the 3D model shall appear.
- The 3D model shall be independent from the marker then.
- If I touch the screen, the 3D model shall disappear again until QCAR recognizes the marker again.

We use this command to tell our 3D model the position where it shall appear (in C++ code):
modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(trackable->getPose());

The code gets transfered from the C++ code to the Java code of Android:

public native float[] getMatrixForJPCT(float[] matrix);

cam = world.getCamera();
float[] matrix = getMatrixForJPCT(new float[16]);
com.threed.jpct.Matrix matrixForJPCT = new Matrix();
for (int i = 0; i < 4; i++) { 
   matrixForJPCT.setRow(i, matrix[i * 4], matrix[i * 4 + 1], 
                        matrix[i * 4 + 2], matrix[i * 4 + 3]); 

In Java (Android) we use this matrix and put the 3D model at that position (only one time). Then we replace the information by the information which we receive from the Android SensorManager via SensorManager.getRotationMatrix(rotationMatrix, null, bufferedAccelGData, bufferedMagnetData); until I touch the screen.

The example code of the SensorManager and jPCT which we used is here:

The matrix for cam.setBack (4x4 matrix) includes a rotation matrix (first 3 rows of the matrix ending with a 0 in the last column = 3x3 matrix) and a translation vector (last row of the matrix ending with a 1 in the last column = 1x3 matrix).

We could already program it so far. And it works good so far. But we have one big problem: The 3D model appears in an orthographic view. But we need it in a perspective view. http://db-in.com/blog/wp-content/uploads/2011/03/projection_example.gif - that means the 3D model gets stretched as soon as the SensorManager gives new data.

I tried already the following examples:
- http://opengles2learning.wordpress.com/tag/gles20/
- http://www.learnopengles.com/android-lesson-one-getting-started/
- http://blog.shayanjaved.com/2011/03/13/shaders-android/
And I tried gl.glMatrixMode().

But I have the feeling that all that code gets ignored as soon as I enter it in the functions onSurfaceCreated, onSurfaceChanged and onDrawFrame in the Android OpenGL ES Renderer class.

Is it possible that there are functions which have a higher priority, e.g. the code of the QCAR C++ code? That the C++ code overrides the Java code here?

Please tell me if you need more detailed information.
As I said, the problem is to get the GL camera from an orthographic view into a perspective view somehow. Maybe someone had already a similar problem.

I'm sorry for possible spelling and grammar mistakes, I'm a German native speaker.

Many thanks for your help in advance.

Re: Orthogonal/Perspective Camera View problem

November 17, 2011 - 3:23am #2

We have solved it in another way now. We know the reason meanwhile, too. But we couldn't solve it. The problem was in the SensorManager somewhere. We didn't get a correct rotation matrix back and the command SensorManager.remapCoordinateSystem() didn't work for us. We only got a zero matrix back although the input matrix had correct data. And after that we had something like a domino effect. That means, the main problem caused other problems then.

Case is closed. Many thanks for your attention! ;)

Log in or register to post comments