Guest User

Projection Matrix

a guest
Nov 24th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  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. }
Add Comment
Please, Sign In to add comment