D3D and OpenGL projection matrices

Started by
1 comment, last by V-man 16 years, 11 months ago
Hi! Why D3D and OpenGL have different projection matrices ? Basically, functions that create this projection matrices has same IN parameters: (fov, aspect, z_near, z_far) but math behind creating this matrix is little bit different. Thx for answers.
Advertisement
They don't have different projection matrices. What you are talking about is handedness (right and left) of matrices and coordinate systems. The right and left handedness are mere conventions. To say that one is different from the other is wrong. It is up to you to decide which one (handedness) you want to use. Direct3D offers APIs to create both types.

D3DXMatrixPerspectiveFovLH - Left handed.
D3DXMatrixPerspectiveFovRH - Right handed.

True, OpenGL doesn't offer an API for left-handed system out of the box, or rather GLU doesn't, but you can write your own function to create a left-handed matrix for OpenGL.

If you set left-handed matrices, you can make OpenGL behave exactly like Direct3D or vice-versa.
++ My::Game ++
D3D maps the depth 0.0 to 1.0 while GL maps to -1.0 to 1.0 and then remaps to 0.0 to 1.0 using another functionality (glDepthRange)
Don't worry, you don't lose performance.

D3DX also has 2 functions. One for right handed and another for left.

I think that element [3][3] of the D3DX projection matrix version is incorrect.

It is zf/(zn-zf) instead of (zf+zn)/(zn-zf)
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement