title: OpenGL projection matrix for perspective with fovy and aspect
body: <p>I'm making my custom <code>frustum</code> and <code>perspective</code> implementations, part of the reasons are that I might need to do it myself, without library, in the future, and I want to polish up computer graphics skills before the exam.</p>
  
  <p>I'm following a book and I am converting their examples in C++ to my ones in Java/LWJGL, however one example strikes me, it is the projection of a cube.<br>
  My cube is projected much further away (about double?) as theirs, which is odd.</p>
  
  <p>This are my implemenations in column-major order:</p>
  
  <pre><code>public static Matrix4f frustum(final float left, final float right, final float bottom, final float top, final float near, final float far) {
      return new Matrix4f(new float[] {
          2 * near / (right - left),          0.0f,                               0.0f,                           0.0f,   //X column
          0.0f,                               2 * near / (top - bottom),          0.0f,                           0.0f,   //Y column
          (right + left) / (right - left),    (top + bottom) / (top - bottom),    (near + far) / (near - far),    -1.0f,  //Z column
          0.0f,                               0.0f,                               2 * near * far / (near - far),  0.0f    //Z column
      });
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public static Matrix4f perspective(final float fovy, final float aspect, final float near, final float far) {
      float y2 = near * (float)Math.tan(Math.toRadians(fovy));
      float y1 = -y2;
      float x1 = y1 * aspect;
      float x2 = y2 * aspect;
      return frustum(x1, x2, y1, y2, near, far);
  }
  </code></pre>
  
  <p>I've seen somewhere where they use a similar <code>y2</code> as I have but divide it by 2, however I do not want to make a dirty fix without exactly understanding why it is going wrong.</p>
  
  <p>Could someone verify whether the <code>perspective</code> matrix I am using, and point me out what the other reasons could be that my object looks to be further away?</p>
  
  <p>I have got my other matrix math right and I am only translating the cube by <code>(0f, 0f, -4f)</code> and verified that that was also correct.</p>
  
  <p>Would a wrongly implemented <code>perspective</code> matrix cause my object to be further away?</p>