智慧水务管理系统 - 精河县供水工程综合管理平台

ConeEmitter.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import Cartesian3 from "../Core/Cartesian3.js";
  2. import Check from "../Core/Check.js";
  3. import CesiumMath from "../Core/Math.js";
  4. const defaultAngle = CesiumMath.toRadians(30.0);
  5. /**
  6. * A ParticleEmitter that emits particles within a cone.
  7. * Particles will be positioned at the tip of the cone and have initial velocities going towards the base.
  8. *
  9. * @alias ConeEmitter
  10. * @constructor
  11. *
  12. * @param {number} [angle=Cesium.Math.toRadians(30.0)] The angle of the cone in radians.
  13. */
  14. function ConeEmitter(angle) {
  15. this._angle = angle ?? defaultAngle;
  16. }
  17. Object.defineProperties(ConeEmitter.prototype, {
  18. /**
  19. * The angle of the cone in radians.
  20. * @memberof CircleEmitter.prototype
  21. * @type {number}
  22. * @default Cesium.Math.toRadians(30.0)
  23. */
  24. angle: {
  25. get: function () {
  26. return this._angle;
  27. },
  28. set: function (value) {
  29. //>>includeStart('debug', pragmas.debug);
  30. Check.typeOf.number("value", value);
  31. //>>includeEnd('debug');
  32. this._angle = value;
  33. },
  34. },
  35. });
  36. /**
  37. * Initializes the given {Particle} by setting it's position and velocity.
  38. *
  39. * @private
  40. * @param {Particle} particle The particle to initialize
  41. */
  42. ConeEmitter.prototype.emit = function (particle) {
  43. const radius = Math.tan(this._angle);
  44. // Compute a random point on the cone's base
  45. const theta = CesiumMath.randomBetween(0.0, CesiumMath.TWO_PI);
  46. const rad = CesiumMath.randomBetween(0.0, radius);
  47. const x = rad * Math.cos(theta);
  48. const y = rad * Math.sin(theta);
  49. const z = 1.0;
  50. particle.velocity = Cartesian3.fromElements(x, y, z, particle.velocity);
  51. Cartesian3.normalize(particle.velocity, particle.velocity);
  52. particle.position = Cartesian3.clone(Cartesian3.ZERO, particle.position);
  53. };
  54. export default ConeEmitter;