Rotation matrix between two spaces

260 views Asked by At

I am working to integrate the Razer Hydra into my project. The integration is not difficult and the basic functions are working well already. Nevertheless, I have a problem and I can't solve it myself. It's about rotation. The problem is that the Sixense SDK space and my space are not the same. But the only difference is the sign of the Z-Axis. Here you can see it on a picture for better understanding:

http://imgur.com/UShwRIA

Now I get a 3x3 rotation matrix from each hydra controller. But to use it I have to convert the rotation matrix into a rotation matrix for my space. I'm doing it like this:

  float (*mat)[3];
  mat = hydra.controllerRight.rot_mat;

  float x1 = mat[0][0];
  float x2 = mat[0][1];
  float x3 = mat[0][2];
  float x4 = 0;

  float y1 = mat[1][0];
  float y2 = mat[1][1];
  float y3 = mat[1][2];
  float y4 = 0;

  float z1 = mat[2][0];
  float z2 = mat[2][1];
  float z3 = mat[2][2];
  float z4 = 0;

  float w1 = 0;
  float w2 = 0;
  float w3 = 0;
  float w4 = 1;

  // my 4x4 rotation matrix
  MatrixF rotMat( x1, x2, x3, x4,
                  y1, y2, y3, y4,
                  z1, z2, z3, z4,
                  w1, w2, w3, w4 );

Now of course the results using this rotation matrix are wrong. But I can't find out what to do to fix it. I tried out a tons of configurations, starting by inverting the z-values over transposing the matrix, because I am not sure about the structure of the sixense matrix.

Can somebody help me out here?

1

There are 1 answers

0
Nico Schertler On BEST ANSWER

I assume, the sixense matrix is some kind of model transform. You are given this transform in space A (the sixense space) and you want to represent the transform in space B (your space).

You know that the system transform between the two spaces is a simple reflection matrix:

          / 1  0  0  0 \
T(B<-A) = | 0  1  0  0 |
          | 0  0 -1  0 |
          \ 0  0  0  1 /

To convert your model transform in space A M_A to a model transform in space B M_B, you have to multiply:

M_B = T(B<-A) * M_A

This equals negating the third row of the matrix M_A (assuming a column-major matrix). It looks like this could be all zs in your code. But it could as well be all ..3s.