title: Projection and View Matrix
body: <h1>Edit</h1>
  <p>I have determined it's not a problem with my matrices, rather <code>glGetUniformLocation</code> not finding the requested variable</p>
  <h1>Edit 2</h1>
  <p>I've fixed the above mistake and unit matrices now work. So the error goes back to my matrices now I think.</p>
  <hr />
  <p>I am having some issues getting my projection and view matrices correct. I have checked them against several examples and don't know where I am going wrong. I see nothing on screen unless I disable the shader.</p>
  <p>I calculate the model matrix like so:</p>
  <pre><code>float aspect = (float)width / std::max(1.0f, (float)height);
  float top = tan(Maths::toRadian(FOV * 0.5f)) * near;
  float bottom = -top;
  float right = top * aspect;
  float left = -right;
  
  projMatrix.reset();
  projMatrix(0, 0) = (2.0f * near) / (right - left);
  projMatrix(1, 1) = (2.0f * near) / (top - bottom);
  projMatrix(2, 2) = -(far + near) / (far - near);
  projMatrix(2, 3) = -1.0f;
  projMatrix(3, 2) = (-2.0f * far * near) / (far - near);
  projMatrix(3, 3) = 0.0f;
  </code></pre>
  <p>I calculate the view matrix like so:</p>
  <pre><code>Camera::Camera(const Maths::Vector3&amp; pos)
      : position(pos), target(0.0f, 0.0f, 0.0f), up(0.0f, 1.0f, 0.0f) {
      target.normalize();
      up.normalize();
  }
  
  Maths::Matrix4 Camera::getMatrix() const {
      Maths::Matrix4 mat;
      Maths::Vector3 z = position - target;
      Maths::Vector3 x = Maths::crossProduct(up, z);
      Maths::Vector3 y = Maths::crossProduct(z, x);
  
      z.normalize();
      x.normalize();
  
      mat(0, 0) = x.x; mat(0, 1) = y.x; mat(0, 2) = y.z;
      mat(1, 0) = x.y; mat(1, 1) = y.y; mat(1, 2) = y.z;
      mat(2, 0) = x.z; mat(1, 2) = y.z; mat(2, 2) = y.z;
  
      mat(3, 0) = -Maths::dotProduct(x, position);
      mat(3, 1) = -Maths::dotProduct(y, position);
      mat(3, 2) = -Maths::dotProduct(z, position);
  
      return mat;
  }
  </code></pre>
  <p>Then I pass them into the shader eventually like so:</p>
  <pre><code>glGetUniformLocation(viewMatrix, &quot;view&quot;);
  glGetUniformLocation(projMatrix, &quot;proj&quot;);
  
  glUniformMatrix4fv(viewMatrix, 1, GL_TRUE, view.asArray());
  glUniformMatrix4fv(projMatrix, 1, GL_TRUE, proj.asArray());
  </code></pre>
  <p>and finally my shader:</p>
  <p>Vertex:</p>
  <pre><code>#version 330
  
  layout (location = 0) in vec3 position;
  
  uniform mat4 view;
  uniform mat4 proj;
  
  void main()
  {
      gl_Position = proj * view * vec4(position, 1.0);
  };
  </code></pre>
  <p>Fragment:</p>
  <pre><code>#version 330
  
  out vec4 gl_FragColor;
  
  void main()
  {
      gl_FragColor = vec4(1.0f, 0.0f, 0.0f, 1.0f);
  } 
  </code></pre>
  <p>And to cover all bases here are my methods for calculating the dot product and the cross product:</p>
  <pre><code>float dotProduct(const Vector3&amp; a, const Vector3&amp; b) {
      return a.x * b.x + a.y * b.y + a.z * b.z;
  }
  
  Vector3 crossProduct(const Vector3&amp; a, const Vector3&amp; b) {
      return Vector3(a.y * b.z - a.z * b.y,
                     a.z * b.x - a.x * b.z,
                     a.x * b.y - a.y * b.z);
  }
  </code></pre>