Results 1 to 6 of 6

Thread: LookAt different in DX and OGL, why??

  1. #1

    LookAt different in DX and OGL, why??

    I found this information about how gluLookAt() makes the view transform matrix:

    http://pyopengl.sourceforge.net/docu...uLookAt.3G.xml

    I was trying to replace D3DXMatrixLookAtLH() with a common function for both graphic subsystems (OpenGL and DirectX 9), but it seems DX doesn't work the same way. I thought I would just have to transpose matrices, but the difference is huge. These are the matrices I get:

    Code:
    ODS:   -0.9999999           0           0           0
    ODS:            0   0.7071066  -0.7071067           0
    ODS:            0  -0.7071066  -0.7071067           0
    ODS:    0.9999999           0   1.4142134           1
    ODS: 
    ODS:   -0.7071067           0           0   0.7071067
    ODS:            0   0.4999999  -0.4999999           0
    ODS:            0  -0.7071067  -0.7071067           0
    ODS:            0           0           0           1
    The first 4x4 matrix was made by D3DXMatrixLookAtLH(), and the second one is what I get with the matrix constructed as the document says. The main difference I see, is that D3DXMatrixLookAtLH uses the bottom row... that one is always (0, 0, 0, 1) with the method described. So how do they build their matrix? Looks odd :?

  2. #2

    LookAt different in DX and OGL, why??

    The difference is that OpenGL uses right-handed coordinate system while DirectX uses left-handed one.

  3. #3

    LookAt different in DX and OGL, why??

    Quote Originally Posted by Lifepower
    The difference is that OpenGL uses right-handed coordinate system while DirectX uses left-handed one.
    But, with the function for right handed system, D3DXMatrixLookAtRH(), I still get non-zero values in the bottom row, why?

    EDIT: Ok, maybe it should also by transposed. Now, why are the values different. Am I missing something else?

  4. #4

    LookAt different in DX and OGL, why??

    Weeeeeeeeeeeeeeee!! I almost got the same values! After checking this post:

    http://www.gamedev.net/community/for...opic_id=399115

    I fixed my function, and now I get the same values as D3DXMatrixLookAtRH(). Thanks for your help.

    But now, how do I transform the matrix from right-handed (OGL) to left-handed (DX) ? I'll google for that, ofcourse, but any tip will be greatly appreciated.

    EDIT: Hmm, after some experiments, it seems I just have to negate every even column... is that right?

  5. #5

    LookAt different in DX and OGL, why??

    Quote Originally Posted by cronodragon
    EDIT: Hmm, after some experiments, it seems I just have to negate every even column... is that right?
    you mean transposing matrix?
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  6. #6

    LookAt different in DX and OGL, why??

    The difference between the left-handed and right-handed coordinate systems is in orientation of one axis. so in order to transform a matrix from one system to another just multiply it by one of the following matrices, whichever suits you better.
    Code:
    [-1  0  0  0 ]
    [ 0  1  0  0 ]
    [ 0  0  1  0 ]
    [ 0  0  0  1 ]
    
    [ 1  0  0  0 ]
    [ 0 -1  0  0 ]
    [ 0  0  1  0 ]
    [ 0  0  0  1 ]
    
    [ 1  0  0  0 ]
    [ 0  1  0  0 ]
    [ 0  0 -1  0 ]
    [ 0  0  0  1 ]
    It's basically swaping the direction of one axis.
    The last one is probably the most common.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •