• Advertisement
Sign in to follow this  

Different Projection Calculation

This topic is 4367 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Why does D3DX and GLU calculates the projection matrix differently? D3DXMatrixPerspectiveFovRH (converted to column major): xScale 0 0 0 0 yScale 0 0 0 0 zf/(zn-zf) zn*zf/(zn-zf) 0 0 -1 0 where: yScale = cot(fovY/2) xScale = yScale / aspect ratio gluPerspective: xScale 0 0 0 0 yScale 0 0 0 0 zf+zn/(zn-zf) 2*zf*zn/(zn-zf) 0 0 -1 0 where: yScale = cot(fovY/2) xScale = yScale / aspect ratio D3DXMatrixOrthoRH (converted to column major ): 2/w 0 0 0 0 2/h 0 0 0 0 1/(zn-zf) zn/(zn-zf) 0 0 0 l glOrtho: 2/w 0 0 tx 0 2/h 0 ty 0 0 -2/(zf-zn) tz 0 0 0 l where: w = right - left; h = top - bottom tx = -( right + left ) / w ty = -( top + bottom ) / h tz = -( zf + zn ) / ( zf - zn ) So if I want to make an engine that can switch back and forth between D3D and OpenGL, projection matrix generation has to be API specific? What about for view matrix?

Share this post


Link to post
Share on other sites
Advertisement
Quick answer:

1. The projection matrices differ in the handedness, and in the z-clipping range
2. The view matrix constructed by the 'look at' functions differ in the handedness
3. The DX library includes functions for both left- and right-handed versions of both, I believe

Share this post


Link to post
Share on other sites
OpenGL is always right handed so I did choose the right handed version of the D3D function.

Share this post


Link to post
Share on other sites
If you've already accounted for handedness and vector orientation, the remaining differences in the projection matrices are due to z-clipping range ([0, 1] in D3D, [-1, 1] in OpenGL).

Also, earlier you mentioned converting the matrices to 'column major', but the correct term is 'column vectors' (a common mistake).

Share this post


Link to post
Share on other sites
If you've already accounted for handedness and vector orientation, the remaining differences in the projection matrices are due to z-clipping range ([0, 1] in D3D, [-1, 1] in OpenGL).

Also, earlier you mentioned converting the matrices to 'column major', but the correct term is 'column vectors' (a common mistake).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement