daily pastebin goal
66%
SHARE
TWEET

Projection Matrix

a guest Nov 24th, 2016 20 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mat4 Projection(float fov, float aspect, float zNear, float zFar) {
  2.     // https://msdn.microsoft.com/en-us/library/windows/desktop/bb205350(v=vs.85).aspx
  3.    
  4.     float tanHalfFov = tanf(DEG2RAD((fov * 0.5f)));
  5.     float fovY = 1.0f / tanHalfFov; // cot(fov/2)
  6.     float fovX = fovY / aspect; // cot(fov/2) / aspect
  7.  
  8.     mat4 result; // Creates identity matrix
  9.  
  10.     result._11 = fovX;
  11.     result._22 = fovY;
  12.     result._33 = zFar / (zFar - zNear); // far / range
  13.     result._34 = 1.0f;
  14.     result._43 = -zNear * result._33; // - near * (far / range)
  15.     result._44 = 0.0f;
  16.  
  17.     return result;
  18. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top