title: Eigen perspective projection matrix
body: <p>I'm trying to create a perspective projection matrix for OpenGL. I know how to do it with a <code>float[16]</code> but for consistencies sake I'd like to use an Eigen matrix.</p>
  
  <p>The <a href="http://openglbook.com/the-book/chapter-4-entering-the-third-dimension/" rel="nofollow">formula</a> is:</p>
  
  <pre><code>    [ xScale   0                 0                        0               ]
  P = [   0    yScale              0                        0               ]
      [   0      0    -(zFar+zNear)/(zFar-zNear) -2*zNear*zFar/(zFar-zNear) ]
      [   0      0                -1                        0               ]
  </code></pre>
  
  <p>Where:</p>
  
  <pre><code>yScale = cot(fovY/2)
  xScale = yScale/aspectRatio
  </code></pre>
  
  <p>Since the formula is column-major and c-arrays are defined row-major, you would define a <code>float[16]</code> matrix with:</p>
  
  <pre><code>float P[16] = {
    xScale, 0, 0, 0,
    0, yScale, 0, 0,
    0, 0, -(zFar+zNear)/(zFar-zNear), -1
    0, 0, -2*zNear*zFar/(zFar-zNear), 0
  };
  </code></pre>
  
  <p>So how exactly would I create a matrix like this with Eigen? Would I use an <code>Eigen::Affine3f</code> or a <code>Eigen::Matrix4f</code>? Looking at <a href="http://eigen.tuxfamily.org/dox/TutorialGeometry.html" rel="nofollow">the</a> <a href="http://eigen.tuxfamily.org/dox/TutorialMapClass.html" rel="nofollow">documentation</a>, it's not apparent to me how to set individual cell values.</p>