title: Calculate a LookAt Matrix
body: <p>I have been trying to write a view matrix/look at matrix but there is an error somewhere in my code and I need help finding it. When I use my function I get a blank screen rather than the test view of my triangle that I should be getting.</p>
  
  <pre><code>public static Mat4 lookAt(
  float eyeX, float eyeY, float eyeZ,     //Where we are looking from
  float centreX, float centreY, float centreZ, //Where we are looking to
  float upX, float upY, float upZ)        //Which way is up
  {
      Vec3 eye    = new Vec3(eyeX, eyeY, eyeZ);
      Vec3 target = new Vec3(centreX, centreY, centreZ);
      Vec3 up     = new Vec3(upX, upY, upZ);
  
      Vec3 zaxis = normal(subtract(target,eye)); // The "forward" vector.
      Vec3 xaxis = normal(cross(up, zaxis));     // The "right" vector.
      Vec3 yaxis = cross(zaxis, xaxis);          // The "up" vector.
  
  
      // [ right.x    right.y     right.z  0]
      // [   up.x       up.y       up.z    0]
      // [-forward.x -forward.y -forward.z 0]
      // [    0         0           0      1]
  
      Mat4 orientation = new Mat4(
         new Vec4( xaxis.get()[0], yaxis.get()[0], -zaxis.get()[0], +0.0f ),  //Column 1 
         new Vec4( xaxis.get()[1], yaxis.get()[1], -zaxis.get()[1], +0.0f ),  //Column 2 
         new Vec4( xaxis.get()[2], yaxis.get()[2], -zaxis.get()[2], +0.0f ),  //Column 3 
         new Vec4( +0.0f, +0.0f,  +0.0f,  +1.0f)                  //Column 4 
         ); 
  
  Mat4 translation = new Mat4 (
          new Vec4( +1.0f, +0.0f, +0.0f, +0.0f ), //Column 1
          new Vec4( +0.0f, +1.0f, +0.0f, +0.0f ), //Column 2
          new Vec4( +0.0f, +0.0f, +1.0f, +0.0f ), //Column 3
          new Vec4( -eye.get()[0], -eye.get()[1], -eye.get()[2], +1.0f)   //Column 4
          );      
  
      return multiply(orientation, translation);
  }
  </code></pre>
  
  <p>This is for a right handed coordinate system. All the matrices are column major; they are constructed starting at a11, moving down the first column to a41, then to a12 and so on to a44.</p>
  
  <p>I have gone over the following functions and I am fairly sure they are correct but I have included them just in case I have overlooked something:</p>
  
  <pre><code>Vec3 normal(Vec3 a)
  {
      Vec3 unit;
  
      float[] v_a = a.get();
      float   v_mag = magnitude(a);
  
      unit = new Vec3(v_a[0]/v_mag, v_a[1]/v_mag, v_a[2]/v_mag);
  
      return unit;
  }
  </code></pre>
  
  <p>--</p>
  
  <pre><code>float magnitude(Vec3 a)
  {
      float[] v_a = a.get();
  
  
      return( (float)Math.sqrt(
      Math.pow( (double)v_a[0], 2) +
      Math.pow( (double)v_a[1], 2) +
      Math.pow( (double)v_a[2], 2)
      )   // -- end sqrt --
  ); // -- return --
  }
  </code></pre>
  
  <p>--</p>
  
  <pre><code>Vec3 cross(Vec3 a, Vec3 b)
  {
      Vec3 crossProduct;
  
      float[] v_a = a.get();
      float[] v_b = b.get();
  
      crossProduct = new Vec3(
         v_a[1]*v_b[2] - v_a[2]*v_b[1],   //cx = ay*bz - az*by
         v_a[2]*v_b[0] - v_a[0]*v_b[2],   //cy = az*bx - ax*bz
         v_a[0]*v_b[1] - v_a[1]*v_b[0]    //cz = ax*by - ay*bz
     ); 
  
  return(crossProduct);
  }
  </code></pre>
  
  <p>All the vector assignments are correct. get() returns a float[].</p>