PDA

View Full Version : LookAt different in DX and OGL, why??



cronodragon
05-11-2007, 04:13 PM
I found this information about how gluLookAt() makes the view transform matrix:

http://pyopengl.sourceforge.net/documentation/manual/gluLookAt.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:


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 :?

LP
05-11-2007, 04:15 PM
The difference is that OpenGL uses right-handed coordinate system while DirectX uses left-handed one.

cronodragon
05-11-2007, 04:21 PM
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?

cronodragon
05-11-2007, 04:44 PM
Weeeeeeeeeeeeeeee!! I almost got the same values! After checking this post:

http://www.gamedev.net/community/forums/topic.asp?topic_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) ? :S 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?

JernejL
06-11-2007, 12:47 AM
EDIT: Hmm, after some experiments, it seems I just have to negate every even column... is that right?

you mean transposing matrix?

Dan
06-11-2007, 01:19 AM
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.


[-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.