# Different Projection Calculation

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

## 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 on other sites

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 on other sites
OpenGL is always right handed so I did choose the right handed version of the D3D function.

##### 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 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).

1. 1
Rutin
47
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632994
• Total Posts
3009766
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!