Search in sources :

Example 1 with SphereEmitter

use of org.cesiumjs.cs.scene.emitters.SphereEmitter 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)

Example 2 with SphereEmitter

use of org.cesiumjs.cs.scene.emitters.SphereEmitter in project gwt-cs by iSergio.

the class ParticleSystem method createWidget.

public FlexTable createWidget() {
    MSliderListener sliderListener = new MSliderListener();
    MChangeHandler tboxListener = new MChangeHandler();
    rateSlider = new Slider("rate", 0, 100, (int) viewModel.rate);
    rateSlider.setStep(1);
    rateSlider.setWidth("150px");
    rateSlider.addListener(sliderListener);
    rateTBox = new TextBox();
    rateTBox.setValue("" + (int) viewModel.rate);
    rateTBox.setSize("30px", "12px");
    rateTBox.addChangeHandler(tboxListener);
    sizeSlider = new Slider("size", 2, 60, (int) viewModel.particleSize);
    sizeSlider.setStep(1);
    sizeSlider.setWidth("150px");
    sizeSlider.addListener(sliderListener);
    sizeTBox = new TextBox();
    sizeTBox.setValue("" + (int) viewModel.particleSize);
    sizeTBox.setSize("30px", "12px");
    sizeTBox.addChangeHandler(tboxListener);
    minLifeSlider = new Slider("minLife", 1, 30, (int) viewModel.minimumLife);
    minLifeSlider.setStep(1);
    minLifeSlider.setWidth("150px");
    minLifeSlider.addListener(sliderListener);
    minLifeTBox = new TextBox();
    minLifeTBox.setValue("" + (int) viewModel.minimumLife);
    minLifeTBox.setSize("30px", "12px");
    minLifeTBox.addChangeHandler(tboxListener);
    maxLifeSlider = new Slider("maxLife", 1, 30, (int) viewModel.maximumLife);
    maxLifeSlider.setStep(1);
    maxLifeSlider.setWidth("150px");
    maxLifeSlider.addListener(sliderListener);
    maxLifeTBox = new TextBox();
    maxLifeTBox.setValue("" + (int) viewModel.maximumLife);
    maxLifeTBox.setSize("30px", "12px");
    maxLifeTBox.addChangeHandler(tboxListener);
    minSpeedSlider = new Slider("minSpeed", 0, 30, (int) viewModel.minimumSpeed);
    minSpeedSlider.setStep(1);
    minSpeedSlider.setWidth("150px");
    minSpeedSlider.addListener(sliderListener);
    minSpeedTBox = new TextBox();
    minSpeedTBox.setValue("" + (int) viewModel.minimumSpeed);
    minSpeedTBox.setSize("30px", "12px");
    minSpeedTBox.addChangeHandler(tboxListener);
    maxSpeedSlider = new Slider("maxSpeed", 0, 30, (int) viewModel.maximumSpeed);
    maxSpeedSlider.setStep(1);
    maxSpeedSlider.setWidth("150px");
    maxSpeedSlider.addListener(sliderListener);
    maxSpeedTBox = new TextBox();
    maxSpeedTBox.setValue("" + (int) viewModel.maximumSpeed);
    maxSpeedTBox.setSize("30px", "12px");
    maxSpeedTBox.addChangeHandler(tboxListener);
    startScaleSlider = new Slider("startScale", 0, 10, (int) viewModel.startScale);
    startScaleSlider.setStep(1);
    startScaleSlider.setWidth("150px");
    startScaleSlider.addListener(sliderListener);
    startScaleTBox = new TextBox();
    startScaleTBox.setValue("" + (int) viewModel.startScale);
    startScaleTBox.setSize("30px", "12px");
    startScaleTBox.addChangeHandler(tboxListener);
    endScaleSlider = new Slider("endScale", 0, 10, (int) viewModel.endScale);
    endScaleSlider.setStep(1);
    endScaleSlider.setWidth("150px");
    endScaleSlider.addListener(sliderListener);
    endScaleTBox = new TextBox();
    endScaleTBox.setValue("" + (int) viewModel.endScale);
    endScaleTBox.setSize("30px", "12px");
    endScaleTBox.addChangeHandler(tboxListener);
    gravitySlider = new Slider("gravity", -20, 20, (int) viewModel.gravity);
    gravitySlider.setStep(1);
    gravitySlider.setWidth("150px");
    gravitySlider.addListener(sliderListener);
    gravityTBox = new TextBox();
    gravityTBox.setValue("" + (int) viewModel.gravity);
    gravityTBox.setSize("30px", "12px");
    gravityTBox.addChangeHandler(tboxListener);
    translationXTBox = new TextBox();
    translationXTBox.setSize("30px", "12px");
    translationXTBox.setValue(viewModel.transX + "");
    translationXTBox.addChangeHandler(tboxListener);
    translationYTBox = new TextBox();
    translationYTBox.setSize("30px", "12px");
    translationYTBox.setValue(viewModel.transY + "");
    translationYTBox.addChangeHandler(tboxListener);
    translationZTBox = new TextBox();
    translationZTBox.setSize("30px", "12px");
    translationZTBox.setValue(viewModel.transZ + "");
    translationZTBox.addChangeHandler(tboxListener);
    rotationHTBox = new TextBox();
    rotationHTBox.setSize("30px", "12px");
    rotationHTBox.setValue(viewModel.heading + "");
    rotationHTBox.addChangeHandler(tboxListener);
    rotationPTBox = new TextBox();
    rotationPTBox.setSize("30px", "12px");
    rotationPTBox.setValue(viewModel.pitch + "");
    rotationPTBox.addChangeHandler(tboxListener);
    rotationRTBox = new TextBox();
    rotationRTBox.setSize("30px", "12px");
    rotationRTBox.setValue(viewModel.roll + "");
    rotationRTBox.addChangeHandler(tboxListener);
    spinCBox = new CheckBox();
    spinCBox.setHTML("<font color=\"white\">Spin</font>");
    spinCBox.addValueChangeHandler(new MValueChangeHandler());
    flyCBox = new CheckBox();
    flyCBox.setHTML("<font color=\"white\">Fly</font>");
    flyCBox.addValueChangeHandler(new MValueChangeHandler());
    showCBox = new CheckBox();
    showCBox.setHTML("<font color=\"white\">Show</font>");
    showCBox.setValue(true);
    showCBox.addValueChangeHandler(new MValueChangeHandler());
    ListBox emitterLBox = new ListBox();
    emitterLBox.addItem("Circle", "Circle");
    emitterLBox.addItem("Cone", "Cone");
    emitterLBox.addItem("Box", "Box");
    emitterLBox.addItem("Sphere", "Sphere");
    emitterLBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            ListBox source = (ListBox) changeEvent.getSource();
            switch(source.getSelectedValue()) {
                case "Circle":
                    particleSystem.emitter = new CircleEmitter(0.5);
                    break;
                case "Cone":
                    particleSystem.emitter = new ConeEmitter(Math.toRadians(45.0));
                    break;
                case "Box":
                    particleSystem.emitter = new BoxEmitter(new Cartesian3(10.0, 10.0, 10.0));
                    break;
                case "Sphere":
                    particleSystem.emitter = new SphereEmitter(5.0);
                    break;
                default:
                    break;
            }
        }
    });
    FlexTable flexTable = new FlexTable();
    flexTable.getElement().getStyle().setBackgroundColor("rgba(0, 0, 0, 0.5)");
    flexTable.setCellSpacing(2);
    flexTable.setCellPadding(2);
    flexTable.setHTML(0, 0, "<font color=\"white\">Rate</font>");
    flexTable.setWidget(0, 1, rateSlider);
    flexTable.setWidget(0, 2, rateTBox);
    flexTable.setHTML(1, 0, "<font color=\"white\">Size</font>");
    flexTable.setWidget(1, 1, sizeSlider);
    flexTable.setWidget(1, 2, sizeTBox);
    flexTable.setHTML(2, 0, "<font color=\"white\">Min Life</font>");
    flexTable.setWidget(2, 1, minLifeSlider);
    flexTable.setWidget(2, 2, minLifeTBox);
    flexTable.setHTML(3, 0, "<font color=\"white\">Max Life</font>");
    flexTable.setWidget(3, 1, maxLifeSlider);
    flexTable.setWidget(3, 2, maxLifeTBox);
    flexTable.setHTML(4, 0, "<font color=\"white\">Min Speed</font>");
    flexTable.setWidget(4, 1, minSpeedSlider);
    flexTable.setWidget(4, 2, minSpeedTBox);
    flexTable.setHTML(5, 0, "<font color=\"white\">Max Speed</font>");
    flexTable.setWidget(5, 1, maxSpeedSlider);
    flexTable.setWidget(5, 2, maxSpeedTBox);
    flexTable.setHTML(6, 0, "<font color=\"white\">Start Scale</font>");
    flexTable.setWidget(6, 1, startScaleSlider);
    flexTable.setWidget(6, 2, startScaleTBox);
    flexTable.setHTML(7, 0, "<font color=\"white\">End Scale</font>");
    flexTable.setWidget(7, 1, endScaleSlider);
    flexTable.setWidget(7, 2, endScaleTBox);
    flexTable.setHTML(8, 0, "<font color=\"white\">Gravity</font>");
    flexTable.setWidget(8, 1, gravitySlider);
    flexTable.setWidget(8, 2, gravityTBox);
    FlexTable transactionFTable = new FlexTable();
    transactionFTable.setHTML(0, 0, "<font color=\"white\">X</font>");
    transactionFTable.setWidget(0, 1, translationXTBox);
    transactionFTable.setHTML(0, 2, "<font color=\"white\">Y</font>");
    transactionFTable.setWidget(0, 3, translationYTBox);
    transactionFTable.setHTML(0, 4, "<font color=\"white\">Z</font>");
    transactionFTable.setWidget(0, 5, translationZTBox);
    flexTable.setHTML(9, 0, "<font color=\"white\">Translation</font>");
    flexTable.setWidget(9, 1, transactionFTable);
    FlexTable rotationFTable = new FlexTable();
    rotationFTable.setHTML(0, 0, "<font color=\"white\">H</font>");
    rotationFTable.setWidget(0, 1, rotationHTBox);
    rotationFTable.setHTML(0, 2, "<font color=\"white\">P</font>");
    rotationFTable.setWidget(0, 3, rotationPTBox);
    rotationFTable.setHTML(0, 4, "<font color=\"white\">R</font>");
    rotationFTable.setWidget(0, 5, rotationRTBox);
    flexTable.setHTML(10, 0, "<font color=\"white\">Rotation</font>");
    flexTable.setWidget(10, 1, rotationFTable);
    FlexTable btnFTable = new FlexTable();
    btnFTable.setWidget(0, 0, spinCBox);
    btnFTable.setWidget(0, 1, flyCBox);
    btnFTable.setWidget(0, 2, showCBox);
    btnFTable.setWidget(0, 3, emitterLBox);
    flexTable.setWidget(11, 1, btnFTable);
    return flexTable;
}
Also used : Slider(org.cleanlogic.showcase.client.examples.slider.Slider) SphereEmitter(org.cesiumjs.cs.scene.emitters.SphereEmitter) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) ConeEmitter(org.cesiumjs.cs.scene.emitters.ConeEmitter) BoxEmitter(org.cesiumjs.cs.scene.emitters.BoxEmitter) CircleEmitter(org.cesiumjs.cs.scene.emitters.CircleEmitter)

Aggregations

SphereEmitter (org.cesiumjs.cs.scene.emitters.SphereEmitter)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 BoxEmitter (org.cesiumjs.cs.scene.emitters.BoxEmitter)1 CircleEmitter (org.cesiumjs.cs.scene.emitters.CircleEmitter)1 ConeEmitter (org.cesiumjs.cs.scene.emitters.ConeEmitter)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 Slider (org.cleanlogic.showcase.client.examples.slider.Slider)1