Skip to content

Commit

Permalink
updates based on ggetz comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbollar committed Apr 24, 2018
2 parents 6de6bb3 + 35c6f8e commit e9e1248
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 41 deletions.
25 changes: 11 additions & 14 deletions Apps/Sandcastle/gallery/Particle System Tails.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
var planePosition = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883, 800.0);
var particlesOffset = new Cesium.Cartesian3(-8.950115473940969, 34.852766731753945, -30.235411095432937);
var cameraLocation = Cesium.Cartesian3.add(planePosition, particlesOffset, new Cesium.Cartesian3());
var recenterCamera = function() {
viewer.camera.lookAt(cameraLocation, new Cesium.Cartesian3(170, -170, 170));
var resetCamera = function() {
viewer.camera.lookAt(cameraLocation, new Cesium.Cartesian3(-450, -300, 200));
};
recenterCamera();
resetCamera();

// Draw particle image to a canvas
var particleCanvas;
Expand Down Expand Up @@ -69,9 +69,9 @@
});

// creating particles model matrix
var transl = Cesium.Matrix4.fromTranslation(particlesOffset, new Cesium.Matrix4());
var translPosition = Cesium.Matrix4.fromTranslation(planePosition, new Cesium.Matrix4());
var particlesModelMatrix = Cesium.Matrix4.multiplyTransformation(translPosition, transl, new Cesium.Matrix4());
var translationOffset = Cesium.Matrix4.fromTranslation(particlesOffset, new Cesium.Matrix4());
var translationOfPlane = Cesium.Matrix4.fromTranslation(planePosition, new Cesium.Matrix4());
var particlesModelMatrix = Cesium.Matrix4.multiplyTransformation(translationOfPlane, translationOffset, new Cesium.Matrix4());

// creating the particle systems
var rocketOptions = {
Expand Down Expand Up @@ -130,23 +130,21 @@
var scratchCartesian3 = new Cesium.Cartesian3();
var scratchCartographic = new Cesium.Cartographic();
var forceFunction = function(options, iteration) {
var iterationOffset = iteration;
var func = function(particle) {
return function(particle) {
scratchCartesian3 = Cesium.Cartesian3.normalize(particle.position, new Cesium.Cartesian3());
scratchCartesian3 = Cesium.Cartesian3.multiplyByScalar(scratchCartesian3, -1.0, scratchCartesian3);

particle.position = Cesium.Cartesian3.add(particle.position, scratchCartesian3, particle.position);

scratchCartographic = Cesium.Cartographic.fromCartesian(particle.position, Cesium.Ellipsoid.WGS84, scratchCartographic);

var angle = Cesium.Math.PI * 2.0 * iterationOffset / options.numberOfSystems;
iterationOffset += options.iterationOffset;
var angle = Cesium.Math.PI * 2.0 * iteration / options.numberOfSystems;
iteration += options.iterationOffset;
scratchCartographic.longitude += Math.cos(angle) * options.cartographicStep;
scratchCartographic.latitude += Math.sin(angle) * options.cartographicStep;

particle.position = Cesium.Cartographic.toCartesian(scratchCartographic);
};
return func;
};

var matrix4Scratch = new Cesium.Matrix4();
Expand All @@ -173,7 +171,6 @@
imageSize : imageSize,
emissionRate : 30.0,
emitter : new Cesium.CircleEmitter(0.1),
bursts : [ ],
lifetime : 0.1,
updateCallback : force,
modelMatrix : particlesModelMatrix,
Expand Down Expand Up @@ -201,15 +198,15 @@
onselect : function() {
showAll(rocketSystems, false);
showAll(cometSystems, true);
recenterCamera();
resetCamera();

}
}, {
text : 'Rocket Thruster',
onselect : function() {
showAll(cometSystems, false);
showAll(rocketSystems, true);
recenterCamera();
resetCamera();
}
}];
Sandcastle.addToolbarMenu(options);
Expand Down
10 changes: 5 additions & 5 deletions Apps/Sandcastle/gallery/Particle System Weather.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
});
var scene = viewer.scene;
scene.globe.depthTestAgainstTerrain = true;
var recenterFunction = function() {
var resetCameraFunction = function() {
scene.camera.setView({
destination : new Cesium.Cartesian3(277096.634865404, 5647834.481964232, 2985563.7039122293),
orientation : {
Expand All @@ -44,7 +44,7 @@
}
});
};
recenterFunction();
resetCameraFunction();

// snow
var snowParticleSize = scene.drawingBufferWidth / 100.0;
Expand All @@ -60,7 +60,7 @@
particle.velocity = Cesium.Cartesian3.add(particle.velocity, snowGravityScratch, particle.velocity);

var distance = Cesium.Cartesian3.distance(scene.camera.position, particle.position);
if (distance > (snowRadius)) {
if (distance > snowRadius) {
particle.endColor.alpha = 0.0;
} else {
particle.endColor.alpha = snowSystem.endColor.alpha / (distance / snowRadius + 0.1);
Expand Down Expand Up @@ -100,7 +100,7 @@
particle.position = Cesium.Cartesian3.add(particle.position, rainGravityScratch, particle.position);

var distance = Cesium.Cartesian3.distance(scene.camera.position, particle.position);
if (distance > (rainRadius)) {
if (distance > rainRadius) {
particle.endColor.alpha = 0.0;
} else {
particle.endColor.alpha = rainSystem.endColor.alpha / (distance / rainRadius + 0.1);
Expand All @@ -124,7 +124,7 @@
scene.primitives.add(rainSystem);

// button
Sandcastle.addToolbarButton("Recenter", recenterFunction);
Sandcastle.addToolbarButton("Reset Camera", resetCameraFunction);

// drop down
var options = [{
Expand Down
42 changes: 20 additions & 22 deletions Apps/Sandcastle/gallery/Particle System.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
<tr>
<td>Rate</td>
<td>
<input type="range" min="0.0" max="100.0" step="1" data-bind="value: rate, valueUpdate: 'input'">
<input type="text" size="5" data-bind="value: rate">
<input type="range" min="0.0" max="100.0" step="1" data-bind="value: emissionRate, valueUpdate: 'input'">
<input type="text" size="5" data-bind="value: emissionRate">
</td>
</tr>

Expand All @@ -61,16 +61,16 @@
<tr>
<td>Min Life</td>
<td>
<input type="range" min="0.1" max="30.0" step="1" data-bind="value: minimumLife, valueUpdate: 'input'">
<input type="text" size="5" data-bind="value: minimumLife">
<input type="range" min="0.1" max="30.0" step="1" data-bind="value: minimumParticleLife, valueUpdate: 'input'">
<input type="text" size="5" data-bind="value: minimumParticleLife">
</td>
</tr>

<tr>
<td>Max Life</td>
<td>
<input type="range" min="0.1" max="30.0" step="1" data-bind="value: maximumLife, valueUpdate: 'input'">
<input type="text" size="5" data-bind="value: maximumLife">
<input type="range" min="0.1" max="30.0" step="1" data-bind="value: maximumParticleLife, valueUpdate: 'input'">
<input type="text" size="5" data-bind="value: maximumParticleLife">
</td>
</tr>

Expand Down Expand Up @@ -161,10 +161,10 @@
viewer.timeline.zoomTo(start, stop);

var viewModel = {
rate : 5.0,
emissionRate : 5.0,
gravity : 0.0,
minimumLife : 1.0,
maximumLife : 1.0,
minimumParticleLife : 1.0,
maximumParticleLife : 1.0,
minimumSpeed : 1.0,
maximumSpeed : 4.0,
startScale : 1.0,
Expand Down Expand Up @@ -263,16 +263,16 @@
startScale : viewModel.startScale,
endScale : viewModel.endScale,

minimumParticleLife : viewModel.minimumLife,
maximumParticleLife : viewModel.maximumLife,
minimumParticleLife : viewModel.minimumParticleLife,
maximumParticleLife : viewModel.maximumParticleLife,

minimumSpeed : viewModel.minimumSpeed,
maximumSpeed : viewModel.maximumSpeed,

imageSize : new Cesium.Cartesian2(viewModel.particleSize, viewModel.particleSize),

// Particles per second.
emissionRate : viewModel.rate,
emissionRate : viewModel.emissionRate,

bursts : [
// these burst will occasionally sync to create a multicolored effect
Expand Down Expand Up @@ -316,31 +316,29 @@
}
});

Cesium.knockout.getObservable(viewModel, 'rate').subscribe(
Cesium.knockout.getObservable(viewModel, 'emissionRate').subscribe(
function(newValue) {
particleSystem.rate = parseFloat(newValue);
particleSystem.emissionRate = parseFloat(newValue);
}
);

Cesium.knockout.getObservable(viewModel, 'particleSize').subscribe(
function(newValue) {
var particleSize = parseFloat(newValue);
particleSystem.minimumWidth = particleSize;
particleSystem.maximumWidth = particleSize;
particleSystem.minimumHeight = particleSize;
particleSystem.maximumHeight = particleSize;
particleSystem.imageSize.x = particleSize;
particleSystem.imageSize.y = particleSize;
}
);

Cesium.knockout.getObservable(viewModel, 'minimumLife').subscribe(
Cesium.knockout.getObservable(viewModel, 'minimumParticleLife').subscribe(
function(newValue) {
particleSystem.minimumLife = parseFloat(newValue);
particleSystem.minimumParticleLife = parseFloat(newValue);
}
);

Cesium.knockout.getObservable(viewModel, 'maximumLife').subscribe(
Cesium.knockout.getObservable(viewModel, 'maximumParticleLife').subscribe(
function(newValue) {
particleSystem.maximumLife = parseFloat(newValue);
particleSystem.maximumParticleLife = parseFloat(newValue);
}
);

Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Change Log
* Improved `MapboxImageryProvider` performance by 300% via `tiles.mapbox.com` subdomain switching. [#6426](https://github.com/AnalyticalGraphicsInc/cesium/issues/6426)
* Added ability to invoke `sampleTerrain` from node.js to enable offline terrain sampling
* Added more ParticleSystem Sandcastle examples for rocket and comet tails and weather. [#6375](https://github.com/AnalyticalGraphicsInc/cesium/pull/6375)
* Added ability to invoke `sampleTerrain` from node.js to enable offline terrain sampling
* Added color and scale attributes to the `ParticleSystem` class constructor. When defined the variables override startColor and endColor and startScale and endScale. [#6429](https://github.com/AnalyticalGraphicsInc/cesium/pull/6429)

##### Fixes :wrench:
Expand Down

0 comments on commit e9e1248

Please sign in to comment.