123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- import Cartesian2 from "../Core/Cartesian2.js";
- import Cartesian3 from "../Core/Cartesian3.js";
- import Color from "../Core/Color.js";
- import defaultValue from "../Core/defaultValue.js";
- import defined from "../Core/defined.js";
- var defaultSize = new Cartesian2(1.0, 1.0);
- function Particle(options) {
- options = defaultValue(options, defaultValue.EMPTY_OBJECT);
-
- this.mass = defaultValue(options.mass, 1.0);
-
- this.position = Cartesian3.clone(
- defaultValue(options.position, Cartesian3.ZERO)
- );
-
- this.velocity = Cartesian3.clone(
- defaultValue(options.velocity, Cartesian3.ZERO)
- );
-
- this.life = defaultValue(options.life, Number.MAX_VALUE);
-
- this.image = options.image;
-
- this.startColor = Color.clone(defaultValue(options.startColor, Color.WHITE));
-
- this.endColor = Color.clone(defaultValue(options.endColor, Color.WHITE));
-
- this.startScale = defaultValue(options.startScale, 1.0);
-
- this.endScale = defaultValue(options.endScale, 1.0);
-
- this.imageSize = Cartesian2.clone(
- defaultValue(options.imageSize, defaultSize)
- );
- this._age = 0.0;
- this._normalizedAge = 0.0;
-
- this._billboard = undefined;
- }
- Object.defineProperties(Particle.prototype, {
-
- age: {
- get: function () {
- return this._age;
- },
- },
-
- normalizedAge: {
- get: function () {
- return this._normalizedAge;
- },
- },
- });
- var deltaScratch = new Cartesian3();
- Particle.prototype.update = function (dt, particleUpdateFunction) {
-
- Cartesian3.multiplyByScalar(this.velocity, dt, deltaScratch);
- Cartesian3.add(this.position, deltaScratch, this.position);
-
- if (defined(particleUpdateFunction)) {
- particleUpdateFunction(this, dt);
- }
-
- this._age += dt;
-
- if (this.life === Number.MAX_VALUE) {
- this._normalizedAge = 0.0;
- } else {
- this._normalizedAge = this._age / this.life;
- }
-
- return this._age <= this.life;
- };
- export default Particle;
|