Guest User

Untitled

a guest
Jan 19th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. // viewportSize is SCREEN_WIDTH and SCREEN_HEIGHT
  2. // viewportLowerLeft is 0.0 and 0.0
  3. ivec2 size = this->viewportSize;
  4. ivec2 lowerLeft = this->viewportLowerLeft;
  5. glViewport(lowerLeft.x, lowerLeft.y, size.x, size.y); // if I put size.x, size.x it draws well
  6.  
  7.  
  8. mat4 projectionMatrix = mat4::FOVFrustum(45.0, 0.1, 100.0, size.x / size.y);
  9.  
  10. glUniformMatrix4fv(uniforms.Projection, 1, 0, projectionMatrix.Pointer());
  11.  
  12. static Matrix4<T> Frustum(T left, T right, T bottom, T top, T near, T far)
  13. {
  14. T a = 2 * near / (right - left);
  15. T b = 2 * near / (top - bottom);
  16. T c = (right + left) / (right - left);
  17. T d = (top + bottom) / (top - bottom);
  18. T e = - (far + near) / (far - near);
  19. T f = -2 * far * near / (far - near);
  20. Matrix4 m;
  21. m.x.x = a; m.x.y = 0; m.x.z = 0; m.x.w = 0;
  22. m.y.x = 0; m.y.y = b; m.y.z = 0; m.y.w = 0;
  23. m.z.x = c; m.z.y = d; m.z.z = e; m.z.w = -1;
  24. m.w.x = 0; m.w.y = 0; m.w.z = f; m.w.w = 1;
  25. return m;
  26. }
  27. static Matrix4<T> FOVFrustum(T fieldOfView, T near, T far, T aspectRatio)
  28. {
  29. T size = near * tanf(DEGREES_TO_RADIANS(fieldOfView) / 2.0);
  30. return Frustum(-size, size, -size / aspectRatio, size / aspectRatio, near, far);
  31. }
  32.  
  33. return Frustum(-size, size, -size / aspectRatio, size / aspectRatio, near, far);
  34.  
  35. return Frustum(-size / aspectRatio, size / aspectRatio, -size, size,, near, far);
Add Comment
Please, Sign In to add comment