Jump to content
  • Advertisement
Sign in to follow this  
SteveDeFacto

OpenGL Code behind D3DXMatrixPerspectiveFovLH?

This topic is 2678 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

I am converting my graphics over to OpenGL and already rebuilt all major matrix functions except D3DXMatrixPerspectiveFovLH. I was able to find this and tried to convert it to work with my matrices but I don't think I did it right:



Ovgl::Matrix44 Ovgl::MatrixPerspectiveLH( float ViewWidth, float ViewHeight, float NearZ, float FarZ)
{
Ovgl::Matrix44 out = {0};

float depth = FarZ - NearZ;
float q = -(FarZ + NearZ) / depth;
float qn = -2 * (FarZ * NearZ) / depth;
float w = 2 * NearZ / ViewWidth;
float h = 2 * NearZ / ViewHeight;

out._11 = w;
out._12 = 0;
out._13 = 0;
out._14 = 0;

out._21 = 0;
out._22 = h;
out._23 = 0;
out._24 = 0;

out._31 = 0;
out._32 = 0;
out._33 = q;
out._34 = -1;

out._41 = 0;
out._42 = 0;
out._43 = qn;
out._44 = 0;

return out;
}



Does anyone know how D3DXMatrixPerspectiveFovLH works?

Share this post


Link to post
Share on other sites
Advertisement

Yes, MSDN. You'll find that all D3DX matrix methods are explained in how they calculate the matrix fields.


One thing to look out for is the difference between right and left handed coords, which affect your view and projection matrices. If you are working with a right handed coordinate system, you would want to use D3DXLookAtRH.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

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!