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);
}
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));
}
Aggregations