CullingVolume.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*global define*/
  2. define([
  3. '../Core/defaultValue',
  4. '../Core/defined',
  5. '../Core/DeveloperError',
  6. '../Core/Intersect'
  7. ], function(
  8. defaultValue,
  9. defined,
  10. DeveloperError,
  11. Intersect) {
  12. "use strict";
  13. /**
  14. * The culling volume defined by planes.
  15. *
  16. * @alias CullingVolume
  17. * @constructor
  18. *
  19. * @param {Cartesian4[]} planes An array of clipping planes.
  20. */
  21. var CullingVolume = function(planes) {
  22. /**
  23. * Each plane is represented by a Cartesian4 object, where the x, y, and z components
  24. * define the unit vector normal to the plane, and the w component is the distance of the
  25. * plane from the origin.
  26. * @type {Cartesian4[]}
  27. * @default []
  28. */
  29. this.planes = defaultValue(planes, []);
  30. };
  31. /**
  32. * Determines whether a bounding volume intersects the culling volume.
  33. *
  34. * @param {Object} boundingVolume The bounding volume whose intersection with the culling volume is to be tested.
  35. * @returns {Intersect} Intersect.OUTSIDE, Intersect.INTERSECTING, or Intersect.INSIDE.
  36. */
  37. CullingVolume.prototype.computeVisibility = function(boundingVolume) {
  38. //>>includeStart('debug', pragmas.debug);
  39. if (!defined(boundingVolume)) {
  40. throw new DeveloperError('boundingVolume is required.');
  41. }
  42. //>>includeEnd('debug');
  43. var planes = this.planes;
  44. var intersecting = false;
  45. for (var k = 0, len = planes.length; k < len; ++k) {
  46. var result = boundingVolume.intersect(planes[k]);
  47. if (result === Intersect.OUTSIDE) {
  48. return Intersect.OUTSIDE;
  49. } else if (result === Intersect.INTERSECTING) {
  50. intersecting = true;
  51. }
  52. }
  53. return intersecting ? Intersect.INTERSECTING : Intersect.INSIDE;
  54. };
  55. return CullingVolume;
  56. });