Troubles with rotation matrix

Started by rtSJ, May 16, 2014, 02:06:32 PM

Previous topic - Next topic

rtSJ

Hello everyone !

I write it today because I have a problem with the orientation of a jPCT camera. I use the sensor of the device to do augmented reality. I use this tutorial to get the differents values [http://www.thousand-thoughts.com/2012/03/android-sensor-fusion-tutorial/] (Because the easy way is too noisy). I get a rotation matrix and 3 angles (Pitch, roll and Azimuth).

So I want to use the 3 angles with a simple rotateCameraAxis. But I can't because the 3 values ar not independant and when I rotate on 1 axis, others moves and I can't rotate for the 2 others. (I you have a solution, say it, I'm happy to read it !)

The second way to rotate the camera is to use the rotation matrix. I convert it to a 4x4 matrix and fill with 0 and one 1, I base it on cols. But it don't work. And more, my view is totally deformed. My modles are very stranges... Anyone have a solution about it ?

How can I use the 3 angles or the matrix to rotate my camera ?

Thanks ! :)

Aksiom

Hi if I get it right you may want t oread my question on StackOverflow.

http://stackoverflow.com/questions/23683150/rotation-vector-sensor-reverse-the-horizontal-rotation

I have found a solution to my question but I couldnt answer it yet because StackOverflow is in read only mode today. So if this is what you are looking for then let me know I will write the solution here.

Hope it helps.

rtSJ

Thanks for your answer, but it's not what I look for... Sorry ^^'

EgonOlsen

#3
The best approach is to use the rotation matrix. Keep jPCT's coordinate system in mind: http://www.jpct.net/wiki/index.php/Coordinate_system as well as the fact that jPCT's matrices are row major.


rtSJ

Okay, I understand but what is weird is when I apply ma matrix on my camera, the view is deformed. And the camera is not oriented correctly, I'm sur.

When I get the matrix data, I transform it to a 4x4 matrix and I dump to the matrix of the camera :


gyroMatrix = getRotationMatrixFromOrientation(fusedOrientation);
                       
float[] arr4x4 = new float[16];
           
for(int i = 0; i < 9; i++){
    arr4x4[i] = gyroMatrix[i];
}
arr4x4[3] = 0;
arr4x4[7] = 0;
arr4x4[11] = 0;
arr4x4[12] = 0;
arr4x4[13] = 0;
arr4x4[14] = 0;
arr4x4[15] = 1;
           
scene.xyzMatrix.setDump(arr4x4);


And in my cycle of rendering I update the camera with :


Camera worldcam = world.getCamera();

worldcam.setBack(xyzMatrix);


I don't understand what I doing wrong because I think I do everything good...

EgonOlsen

Quote from: rtSJ on May 19, 2014, 01:52:07 PM
... I think I do everything good...
No, you don't...apart from different coordinate systems and the missing conversion between them, your matrix filling is wrong. You copy the 9 elements of the source matrix into the first 9 elements of the target matrix, but it should actually be
  • =[0], [1]=[1], [2]=[2], [4]=[3]...your code ignores the fact that the last row and column in the target matrix are not present in the source matrix.

rtSJ

Okay, okay It's my fault, I'm sorry. It's work quite well. Thank you ! I'm not very familiar with the 3D mathematics.

Concerning the different coordinate systems and the conversion between them, I make a rotation of the matrix with this line of code :

rotationMatrix = matrixMultiplication(rotationMatrix, myXDegRotationMatrix);

But I'm not sur of what matrix I'm suppose to use. I try to do a rotation of 180 degree with :


my180DegRotationMatrix[0] = 1.0f; my180DegRotationMatrix[1] = 0.0f; my180DegRotationMatrix[2] = 0.0f;
my180DegRotationMatrix[3] = 0.0f; my180DegRotationMatrix[4] = -1.0f; my180DegRotationMatrix[5] = 0.0f;
my180DegRotationMatrix[6] = 0.0f; my180DegRotationMatrix[7] = 0.0f; my180DegRotationMatrix[8] = -1.0f;


And a rotation of 90 degree anti-clockwise :


my90DegRotationMatrix[0] = 1.0f; my90DegRotationMatrix[1] = 0.0f; my90DegRotationMatrix[2] = 0.0f;
my90DegRotationMatrix[3] = 0.0f; my90DegRotationMatrix[4] = 0.0f; my90DegRotationMatrix[5] = 1.0f;
my90DegRotationMatrix[6] = 0.0f; my90DegRotationMatrix[7] = -1.0f; my90DegRotationMatrix[8] = 0.0f;


But that didn't works

EgonOlsen

Don't create your own matrices to do a rotation. Just rotate around X (for example) with PI, PI/2...whatever you need...