Tuesday 15 July 2014

c++ - Matrix classes Directx & OpenGL -


I have the following C ++ matrix class:

I I am using coupled with a renderer, for which there is an OpenLog and DirectX implementation.

I have a test example where within the window the coordinates of the mouse are used in the graphic position under the cursor. This works as expected under OpenGL.

Because the DirectX line head and OpenGell columns are the main, I reverse the matrix in the following way and pass it to the DirectX before rendering:

  if ( O-> Tree) {CObjectTransform * t = o- & gt; Tree-> gatetransform (O-> transgenied); D3d Matrix D; Float * M = (Float *) & amp; D; For (int u = 0; u & lt; 4; u ++) {for (int v = 0; v <4; v ++) {m [u + v * 4] = t-> ; Worldtransform.matrix [v + u * 4]; }} Pd3dDevice-> SetTransform (D3DTS_WORLD, & amp; d); }  

The result of this is nothing shown in the area visible from the graphics, here I have placed my cursor.

Like this:

  1. Is my change class correctly implemented?
  2. How do I work with DirectX? Edit:

    The following code setup was:

      float * m = (float *) & amp; D; For (int u = 0; u & lt; 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,0,0,0,0,0,0,0,0,0,0,0 , 0,0}}; Memcpy (test, & amp; d, sizeof (d));  

    Matrix class values:

    1,0,0,0 - 0,1,0,0 - 0,0,1, 0
    47 , -30,0,1

    Values ​​of Swap Matrix:

    1,0,0,47 = 0,1,0, -30
    0,1,1 0,0,0,1

    Then the matrix is ​​being swaped around. Owing to the problem, swapping out the round code.

OpenGL and DirectX matrix represent against representation, but they have the opposite vector * matrix < / Code> is the command:

  • OpenGL: M * v . The main column in the M memory is
  • DirectX: v * m . M is the key in memory

Because the multiplication is reversed, you have to move your OpenGL matrix to pass the DX. But since DX uses the key of the line, you have to move again. Twice infected is actually the identity.

Why do not you try to make any changes about everyone?


No comments:

Post a Comment