Search in sources :

Example 1 with ParticleSystem

use of org.cesiumjs.cs.scene.particle.ParticleSystem in project gwt-cs by iSergio.

the class ParticleSystemFireworks method createFirework.

private void createFirework(Scene scene, Cartesian3 offset, Color color, ParticleBurst[] bursts) {
    Cartesian3 position = Cartesian3.add(emitterInitialLocation, offset, new Cartesian3());
    Matrix4 emitterModelMatrix = Matrix4.fromTranslation(position, emitterModelMatrixScratch);
    Matrix4 particleToWorld = Matrix4.multiply(modelMatrix, emitterModelMatrix, new Matrix4());
    final Matrix4 worldToParticle = Matrix4.inverseTransformation(particleToWorld, particleToWorld);
    final double size = Math.randomBetween(minimumExplosionSize, maximumExplosionSize);
    final Cartesian3 particlePositionScratch = new Cartesian3();
    ParticleSystem.ApplyForce force = new ParticleSystem.ApplyForce() {

        @Override
        public void function(Particle particle, double dt) {
            Cartesian3 position = Matrix4.multiplyByPoint(worldToParticle, particle.position, particlePositionScratch);
            if (Cartesian3.magnitudeSquared(position) >= size * size) {
                Cartesian3.clone(Cartesian3.ZERO(), particle.velocity);
            }
        }
    };
    double normalSize = (size - minimumExplosionSize) / (maximumExplosionSize - minimumExplosionSize);
    double minLife = 0.3;
    double maxLife = 1.0;
    double life = normalSize * (maxLife - minLife) + minLife;
    ParticleSystemOptions particleSystemOptions = new ParticleSystemOptions();
    particleSystemOptions.image = getImage();
    particleSystemOptions.startColor = color;
    particleSystemOptions.endColor = color.withAlpha(0.0f);
    particleSystemOptions.life = life;
    particleSystemOptions.speed = 100.0;
    particleSystemOptions.width = particlePixelSize;
    particleSystemOptions.height = particlePixelSize;
    particleSystemOptions.rate = 0;
    particleSystemOptions.emitter = new SphereEmitter(0.1);
    particleSystemOptions.bursts = bursts;
    particleSystemOptions.lifeTime = lifetime;
    particleSystemOptions.forces = new ParticleSystem.ApplyForce[] { force };
    particleSystemOptions.modelMatrix = modelMatrix;
    particleSystemOptions.emitterModelMatrix = emitterModelMatrix;
    scene.primitives().add(new ParticleSystem(particleSystemOptions));
}
Also used : Particle(org.cesiumjs.cs.scene.particle.Particle) SphereEmitter(org.cesiumjs.cs.scene.emitters.SphereEmitter) ParticleSystem(org.cesiumjs.cs.scene.particle.ParticleSystem) ParticleSystemOptions(org.cesiumjs.cs.scene.particle.options.ParticleSystemOptions)

Aggregations

SphereEmitter (org.cesiumjs.cs.scene.emitters.SphereEmitter)1 Particle (org.cesiumjs.cs.scene.particle.Particle)1 ParticleSystem (org.cesiumjs.cs.scene.particle.ParticleSystem)1 ParticleSystemOptions (org.cesiumjs.cs.scene.particle.options.ParticleSystemOptions)1