I have the following C++ matrix class:
I am using this coupled with a renderer, for which there is an opengl and a directx implementation.
I have a test example where the coordinates of the mouse within the window are used to position a graphic under the cursor. This works as expected under OpenGL.
Because directx is row major and opengl is column major, I reverse the matrix as follows and pass it to directx before rendering:
if(o->tree){
CObjectTransform* t = o->tree->GetTransform(o->transformID);
D3DMATRIX d;
float* m = (float*)&d;
for (int u=0; u<4; u++){
for (int v=0; v<4; v++){
m[u +v*4] = t->worldtransform.matrix[v+u*4];
}
}
pd3dDevice->SetTransform(D3DTS_WORLD, &d);
}
The result of this is nothing is shown in the visible area from the graphics, regardless of here I put my cursor.
So:
- Is my transform class correctly implemented?
- How do I get it working with directx?
edit:
the following code was setup:
float* m = (float*)&d;
for (int u=0; u<4; u++){
for (int v=0; v<4; v++){
m[u +v*4] = t->worldtransform.matrix[v+u*4];
}
}
float test[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
memcpy(test,&d,sizeof(d));
The values of the matrix class:
1,0,0,0
0,1,0,0
0,0,1,0
47,-30,0,1
The values of the swapped matrix:
1,0,0,47
0,1,0,-30
0,0,1,0
0,0,0,1
So the matrix is being swapped around. This rules out the swapping round code as the cause of the problem.