rayEllipsoidIntersectionInterval.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "czm_raySegment czm_rayEllipsoidIntersectionInterval(czm_ray ray, vec3 ellipsoid_center, vec3 ellipsoid_inverseRadii)\n\
  3. {\n\
  4. vec3 q = ellipsoid_inverseRadii * (czm_inverseModelView * vec4(ray.origin, 1.0)).xyz;\n\
  5. vec3 w = ellipsoid_inverseRadii * (czm_inverseModelView * vec4(ray.direction, 0.0)).xyz;\n\
  6. q = q - ellipsoid_inverseRadii * (czm_inverseModelView * vec4(ellipsoid_center, 1.0)).xyz;\n\
  7. float q2 = dot(q, q);\n\
  8. float qw = dot(q, w);\n\
  9. if (q2 > 1.0)\n\
  10. {\n\
  11. if (qw >= 0.0)\n\
  12. {\n\
  13. return czm_emptyRaySegment;\n\
  14. }\n\
  15. else\n\
  16. {\n\
  17. float qw2 = qw * qw;\n\
  18. float difference = q2 - 1.0;\n\
  19. float w2 = dot(w, w);\n\
  20. float product = w2 * difference;\n\
  21. if (qw2 < product)\n\
  22. {\n\
  23. return czm_emptyRaySegment;\n\
  24. }\n\
  25. else if (qw2 > product)\n\
  26. {\n\
  27. float discriminant = qw * qw - product;\n\
  28. float temp = -qw + sqrt(discriminant);\n\
  29. float root0 = temp / w2;\n\
  30. float root1 = difference / temp;\n\
  31. if (root0 < root1)\n\
  32. {\n\
  33. czm_raySegment i = czm_raySegment(root0, root1);\n\
  34. return i;\n\
  35. }\n\
  36. else\n\
  37. {\n\
  38. czm_raySegment i = czm_raySegment(root1, root0);\n\
  39. return i;\n\
  40. }\n\
  41. }\n\
  42. else\n\
  43. {\n\
  44. float root = sqrt(difference / w2);\n\
  45. czm_raySegment i = czm_raySegment(root, root);\n\
  46. return i;\n\
  47. }\n\
  48. }\n\
  49. }\n\
  50. else if (q2 < 1.0)\n\
  51. {\n\
  52. float difference = q2 - 1.0;\n\
  53. float w2 = dot(w, w);\n\
  54. float product = w2 * difference;\n\
  55. float discriminant = qw * qw - product;\n\
  56. float temp = -qw + sqrt(discriminant);\n\
  57. czm_raySegment i = czm_raySegment(0.0, temp / w2);\n\
  58. return i;\n\
  59. }\n\
  60. else\n\
  61. {\n\
  62. if (qw < 0.0)\n\
  63. {\n\
  64. float w2 = dot(w, w);\n\
  65. czm_raySegment i = czm_raySegment(0.0, -qw / w2);\n\
  66. return i;\n\
  67. }\n\
  68. else\n\
  69. {\n\
  70. return czm_emptyRaySegment;\n\
  71. }\n\
  72. }\n\
  73. }\n\
  74. ";