Search in sources :

Example 1 with Particle

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

the class ParticleSystem method buildPanel.

@Override
public void buildPanel() {
    ViewerPanel csVPanel = new ViewerPanel();
    // Set the random number seed for consistent results.
    Math.setRandomNumberSeed(3);
    // Make sure viewer is at the desired time.
    csVPanel.getViewer().clock().startTime = start.clone();
    csVPanel.getViewer().clock().stopTime = stop.clone();
    csVPanel.getViewer().clock().currentTime = start.clone();
    // Loop at the end
    csVPanel.getViewer().clock().clockRange = ClockRange.LOOP_STOP();
    csVPanel.getViewer().clock().multiplier = 1;
    // Set timeline to simulation bounds
    csVPanel.getViewer().timeline().zoomTo(start, stop);
    // Compute the entity position property.
    circularPosition = computeCirclularFlight(-112.110693, 36.0994841, 0.03);
    staticPosition = Cartesian3.fromDegrees(-112.110693, 36.0994841, 1000);
    TimeIntervalOptions timeIntervalOptions = new TimeIntervalOptions();
    timeIntervalOptions.start = start;
    timeIntervalOptions.stop = stop;
    ModelGraphicsOptions modelGraphicsOptions = new ModelGraphicsOptions();
    modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/CesiumAir/Cesium_Air.gltf");
    modelGraphicsOptions.minimumPixelSize = new ConstantProperty<>(64);
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.availability = new TimeIntervalCollection(new TimeInterval[] { new TimeInterval(timeIntervalOptions) });
    entityOptions.model = new ModelGraphics(modelGraphicsOptions);
    entityOptions.position = new ConstantPositionProperty(staticPosition);
    entity = csVPanel.getViewer().entities().add(entityOptions);
    csVPanel.getViewer().trackedEntity = entity;
    ParticleSystemOptions particleSystemOptions = new ParticleSystemOptions();
    particleSystemOptions.image = GWT.getModuleBaseURL() + "SampleData/fire.png";
    particleSystemOptions.startColor = Color.RED().withAlpha(0.7f);
    particleSystemOptions.endColor = Color.YELLOW().withAlpha(0.3f);
    particleSystemOptions.startScale = viewModel.startScale;
    particleSystemOptions.endScale = viewModel.endScale;
    particleSystemOptions.minimumLife = viewModel.minimumLife;
    particleSystemOptions.maximumLife = viewModel.maximumLife;
    particleSystemOptions.minimumSpeed = viewModel.minimumSpeed;
    particleSystemOptions.maximumSpeed = viewModel.maximumSpeed;
    particleSystemOptions.minimumWidth = viewModel.particleSize;
    particleSystemOptions.minimumHeight = viewModel.particleSize;
    particleSystemOptions.maximumWidth = viewModel.particleSize;
    particleSystemOptions.maximumHeight = viewModel.particleSize;
    particleSystemOptions.rate = viewModel.rate;
    particleSystemOptions.bursts = new ParticleBurst[] { ParticleBurst.create(5.0, 300, 500), ParticleBurst.create(10.0, 50, 100), ParticleBurst.create(15.0, 200, 300) };
    particleSystemOptions.lifeTime = 16;
    particleSystemOptions.emitter = new CircleEmitter(0.5);
    particleSystemOptions.emitterModelMatrix = computeEmitterModelMatrix();
    particleSystemOptions.forces = new org.cesiumjs.cs.scene.particle.ParticleSystem.ApplyForce[] { new org.cesiumjs.cs.scene.particle.ParticleSystem.ApplyForce() {

        @Override
        public void function(Particle particle, double dt) {
            Cartesian3 position = particle.position;
            Cartesian3.normalize(position, gravityScratch);
            Cartesian3.multiplyByScalar(gravityScratch, viewModel.gravity * dt, gravityScratch);
            particle.velocity = Cartesian3.add(particle.velocity, gravityScratch, particle.velocity);
        }
    } };
    particleSystem = (org.cesiumjs.cs.scene.particle.ParticleSystem) csVPanel.getViewer().scene().primitives().add(new org.cesiumjs.cs.scene.particle.ParticleSystem(particleSystemOptions));
    csVPanel.getViewer().scene().preRender().addEventListener(new Event.Listener() {

        @Override
        public void function(Object... o) {
            Scene scene = (Scene) o[0];
            JulianDate time = (JulianDate) o[1];
            particleSystem.modelMatrix = computeModelMatrix(entity, time);
            // Account for any changes to the emitter model matrix.
            particleSystem.emitterModelMatrix = computeEmitterModelMatrix();
            // Spin the emitter if enabled.
            if (viewModel.spin) {
                viewModel.heading += 1.0;
                viewModel.pitch += 1.0;
                viewModel.roll += 1.0;
                rotationHTBox.setValue(viewModel.heading + "");
                rotationPTBox.setValue(viewModel.pitch + "");
                rotationRTBox.setValue(viewModel.roll + "");
            }
        }
    });
    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(createWidget(), 20, 20);
    contentPanel.add(new HTML("<p>Particle systems.</p>"));
    contentPanel.add(aPanel);
    initWidget(contentPanel);
}
Also used : ModelGraphics(org.cesiumjs.cs.datasources.graphics.ModelGraphics) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions) Particle(org.cesiumjs.cs.scene.particle.Particle) ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) TimeIntervalOptions(org.cesiumjs.cs.core.options.TimeIntervalOptions) TimeIntervalCollection(org.cesiumjs.cs.collections.TimeIntervalCollection) Scene(org.cesiumjs.cs.scene.Scene) ModelGraphics(org.cesiumjs.cs.datasources.graphics.ModelGraphics) ModelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions) CircleEmitter(org.cesiumjs.cs.scene.emitters.CircleEmitter) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) SliderEvent(org.cleanlogic.showcase.client.examples.slider.SliderEvent) JsObject(org.cesiumjs.cs.js.JsObject) ParticleSystemOptions(org.cesiumjs.cs.scene.particle.options.ParticleSystemOptions)

Example 2 with Particle

use of org.cesiumjs.cs.scene.particle.Particle 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

Particle (org.cesiumjs.cs.scene.particle.Particle)2 ParticleSystemOptions (org.cesiumjs.cs.scene.particle.options.ParticleSystemOptions)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 TimeIntervalCollection (org.cesiumjs.cs.collections.TimeIntervalCollection)1 TimeIntervalOptions (org.cesiumjs.cs.core.options.TimeIntervalOptions)1 ModelGraphics (org.cesiumjs.cs.datasources.graphics.ModelGraphics)1 ModelGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions)1 EntityOptions (org.cesiumjs.cs.datasources.options.EntityOptions)1 JsObject (org.cesiumjs.cs.js.JsObject)1 Scene (org.cesiumjs.cs.scene.Scene)1 CircleEmitter (org.cesiumjs.cs.scene.emitters.CircleEmitter)1 SphereEmitter (org.cesiumjs.cs.scene.emitters.SphereEmitter)1 ParticleSystem (org.cesiumjs.cs.scene.particle.ParticleSystem)1 ViewerPanel (org.cesiumjs.cs.widgets.ViewerPanel)1 SliderEvent (org.cleanlogic.showcase.client.examples.slider.SliderEvent)1