use of org.cesiumjs.cs.scene.emitters.CircleEmitter 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);
}
use of org.cesiumjs.cs.scene.emitters.CircleEmitter 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;
}
Aggregations