Direct3D View Matrix: porting problem from OpenGL


  • Hi,

    I am porting an application from OpenGL to Direct3D. OpenGL does not have a View Matrix and a World Matrix as Direct3D, but just what is called the ModelView matrix.

    I have the following lines of code in OpenGL:


    glMatrixMode(GL_MODELVIEW); //Work on the ModelView matrix
    glLoadIdentity(); //Clear everything
    glLoadMatrixd(myModelViewMatrix); //Load my ModelView matrix

    Now I would like to port this to Direct3D, and this is my suggestion on how to do it:
    1. Convert from OpenGL right hand coord sys to Direct3D left hand by scaling myModelViewMatrix with (1, 1, -1). (should I to newMat= myModelViewMat * scaleMat, or newMat = scaleMat * myModelViewMat?)
    2. Set myModelViewMatrix as the View Matrix

    This does not seem to work.

    Am I missing something? Or am I attacking this the wrong way? Should I set myModelViewMatrix as the world matrix for all my objects instead, or something?

    Wednesday, February 22, 2006 11:16 AM


All replies

  • You will find some information’s about how to porting from right hand to left hand in the SDK documentation.




    If you don’t need the world transformation simply don’t change it.



    Wednesday, February 22, 2006 12:05 PM
  • Thanks!

    So, the SDK says to flip the sign of the view matrix elements 31, 32, 33 and 34. But isn't 34 always 0?

    And in OpenGL, isn't the ModelView matrix kind of a combination of Direct3D's View Matrix and World Matrix? Do I need to split the OpenGL ModelView matrix somehow?

    Wednesday, February 22, 2006 12:11 PM
  • Yes normally it is zero but “better save than sorry”.


    Yes it is a combination. But you can set it to the View matrix and let the World matrix at identity.


    Wednesday, February 22, 2006 12:22 PM
  • Thanks again for your help!

    My transformation matrix is of this form:

    r11 r12 r13 tx
    r21 r22 r23 ty
    r31 r32 r33 tz
    0      0      0  1

    while Direct3D assumes:

    r11 r12 r13 0
    r21 r22 r23 0
    r31 r32 r33 0
    tx     ty    tz    1

    So I need to move the translation vector from column 4 to row 4. Do I need to do something with the rotation matrix as well, since the original rotation matrix is defined in a right-hand coordinate system, or is that taken care of by switching the sign or the third row of the matrix?


    Wednesday, February 22, 2006 1:47 PM
  • Good Question. Normally it should be enough to convert the final matrix from right to left hand before you set it as transformation. But I must confess that the last time I have done this is too long ago.

    Wednesday, February 22, 2006 2:08 PM