Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created May 15, 2013 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5583138 to your computer and use it in GitHub Desktop.
Save anonymous/5583138 to your computer and use it in GitHub Desktop.
Compute OpenGL projection matrix from intrinsic parameters
Matrix4d computeOpenGLProjectionMatrix(const Matrix3d &K, double x0,double y0, double width, double height, double znear, double zfar)
{
double depth = zfar - znear;
double q = -(zfar + znear) / depth;
double qn = -2.0 * (zfar * znear) / depth;
Matrix4d OpenGLProjectionMatrix;
OpenGLProjectionMatrix << 2*K(0,0)/width, -2*K(0,1)/width, (-2*K(0,2)+width+2*x0)/width, 0 ,
0, -2*K(1,1)/height,(-2*K(1,2)+height+2*y0)/height, 0,
0,0,q,qn,
0,0,-1,0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment