The Perspective Projection Matrix

This is a simplified version of the perspective projection matrix, where we assume right-left and up-down symmetry in the view frustum.

121                 function generatePerspectivematrix(x_scale, y_scale, z_near, z_far)
122                 {
123                   return new   Float32Array([z_near/x_scale,      0.0,                           0.0,                                       0.0,
124                                                                 0.0,                z_near/y_scale,                  0.0,                                       0.0,
125                                                                 0.0,                        0.0,         -(z_far+z_near)/(z_far-z_near),            -1.0,
126                                                                 0.0,                        0.0,            -2*z_far*z_near/(z_far-z_near),        0.0]);
127                 }

Notes

At first glance, this code might not match the the full projection matrix from the online references.

[ 2 z near right - left 0 right + left right - left 0 0 2 z near top - bottom top + bottom top - bottom 0 0 0 z far + z near z far - z near -2 z far z near z far - z near 0 0 -1 0 ]

Me make significant simplifications using top-bottom and left-right symmetry.


  
   right
  
  
   =
  
  
   -
  
  
   left
  
  
   =
  
  
   xscale
  
 
        

and


  
   top
  
  
   =
  
  
   -
  
  
   bottom
  
  
   =
  
  
   yscale
  
 
        

Substituting these values into the full matrix gives the much simpler version used in the code.

[ z near xscale 0 0 0 0 z near yscale 0 0 0 0 z far + z near z far - z near -2 z far z near z far - z near 0 0 -1 0 ]