cameraLight.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import MathLight from './MathLight'
  2. var cameraLight = {
  3. clampVFOV: function (currentFov, maxHFov, width, height) {
  4. //限制currentFov, 使之造成的横向fov不大于指定值maxHFov
  5. var r = cameraLight.getHFOVFromVFOV(currentFov, width, height)
  6. return r > maxHFov ? cameraLight.getVFOVFromHFOV(maxHFov, width, height) : currentFov
  7. },
  8. getHFOVForCamera: function (camera, width, height) {
  9. return cameraLight.getHFOVFromVFOV(camera.fov, width, height)
  10. },
  11. getHFOVFromVFOV: function (fov, width, height) {
  12. return 2 * Math.atan(Math.tan((fov * MathLight.RADIANS_PER_DEGREE) / 2) * (width / height)) * MathLight.DEGREES_PER_RADIAN
  13. },
  14. getVFOVFromHFOV: function (fov, width, height) {
  15. return 2 * Math.atan(Math.tan((fov * MathLight.RADIANS_PER_DEGREE) / 2) * (height / width)) * MathLight.DEGREES_PER_RADIAN
  16. },
  17. /* clampVFOV: function(fov, t, i, n) {
  18. var r = cameraLight.getHFOVFromVFOV(fov, i, n);
  19. return r > t ? cameraLight.getVFOVFromHFOV(t, i, n) : fov
  20. },
  21. getHFOVForCamera: function(e, t, i) {
  22. return cameraLight.getHFOVFromVFOV(e.fov, t, i)
  23. },
  24. getHFOVFromVFOV: function(fov, t, i) {
  25. var n = t
  26. , o = i
  27. , a = 2 * Math.atan(Math.tan(fov * MathLight.RADIANS_PER_DEGREE / 2) * (n / o)) * MathLight.DEGREES_PER_RADIAN;
  28. return a
  29. },
  30. getVFOVFromHFOV: function(e, t, i) {
  31. var n = t
  32. , o = i
  33. , a = 2 * Math.atan(Math.tan(e * MathLight.RADIANS_PER_DEGREE / 2) * (o / n)) * MathLight.DEGREES_PER_RADIAN;
  34. return a
  35. } */
  36. }
  37. export default cameraLight