Frustum.cpp 772 B

1234567891011121314151617181920212223242526272829
  1. #include <cmath>
  2. #include "client/math/Frustum.h"
  3. Frustum::Frustum(float fovY, float nearClip, float farClip) : fovY(fovY), nearClip(nearClip), farClip(farClip) {
  4. }
  5. void Frustum::setProjection(Matrix& m, int width, int height) {
  6. float tan = tanf((0.5f * fovY) * M_PI / 180.0f);
  7. float q = 1.0f / tan;
  8. float aspect = (float) width / height;
  9. m.set(0, q / aspect);
  10. m.set(1, 0.0f);
  11. m.set(2, 0.0f);
  12. m.set(3, 0.0f);
  13. m.set(4, 0.0f);
  14. m.set(5, q);
  15. m.set(6, 0.0f);
  16. m.set(7, 0.0f);
  17. m.set(8, 0.0f);
  18. m.set(9, 0.0f);
  19. m.set(10, (nearClip + farClip) / (nearClip - farClip));
  20. m.set(11, -1.0f);
  21. m.set(12, 0.0f);
  22. m.set(13, 0.0f);
  23. m.set(14, (2.0f * nearClip * farClip) / (nearClip - farClip));
  24. m.set(15, 0.0f);
  25. }