use of org.cesiumjs.cs.datasources.properties.options.SampledPropertyInterpolationOptions in project gwt-cs by iSergio.
the class Cardboard method buildPanel.
@Override
public void buildPanel() {
ViewerOptions viewerOptions = new ViewerOptions();
viewerOptions.vrButton = true;
ViewerPanel csVPanel = new ViewerPanel(viewerOptions);
csVPanel.getViewer().scene().globe.enableLighting = true;
CesiumTerrainProviderOptions cesiumTerrainProviderOptions = new CesiumTerrainProviderOptions();
cesiumTerrainProviderOptions.url = "https://assets.agi.com/stk-terrain/world";
cesiumTerrainProviderOptions.requestVertexNormals = true;
csVPanel.getViewer().terrainProvider = new CesiumTerrainProvider(cesiumTerrainProviderOptions);
csVPanel.getViewer().scene().globe.depthTestAgainstTerrain = true;
// Follow the path of a plane. See the interpolation Sandcastle example.
Math.setRandomNumberSeed(3);
start = JulianDate.fromDate(new JsDate(2015, 2, 25, 16));
stop = JulianDate.addSeconds(start, 360, new JulianDate());
csVPanel.getViewer().clock().startTime = start.clone();
csVPanel.getViewer().clock().stopTime = stop.clone();
csVPanel.getViewer().clock().currentTime = start.clone();
csVPanel.getViewer().clock().clockRange = ClockRange.LOOP_STOP();
csVPanel.getViewer().clock().multiplier = 1.0;
double lon = -112.110693;
double lat = 36.0994841;
double radius = 0.03;
String modelURI = GWT.getModuleBaseURL() + "SampleData/models/CesiumBalloon/CesiumBalloon.glb";
EntityOptions entityOptions = new EntityOptions();
TimeIntervalOptions timeIntervalOptions = new TimeIntervalOptions();
timeIntervalOptions.start = start;
timeIntervalOptions.stop = stop;
entityOptions.availability = new TimeIntervalCollection(new TimeInterval[] { new TimeInterval(timeIntervalOptions) });
entityOptions.position = computeCirclularFlight(lon, lat, radius);
ModelGraphicsOptions modelGraphicsOptions = new ModelGraphicsOptions();
modelGraphicsOptions.uri = new ConstantProperty<>(modelURI);
modelGraphicsOptions.minimumPixelSize = new ConstantProperty<>(64);
entityOptions.model = new ModelGraphics(modelGraphicsOptions);
entity = csVPanel.getViewer().entities().add(entityOptions);
SampledPropertyInterpolationOptions sampledPropertyInterpolationOptions = new SampledPropertyInterpolationOptions();
sampledPropertyInterpolationOptions.interpolationDegree = 2;
sampledPropertyInterpolationOptions.interpolationAlgorithm = HermitePolynomialApproximation.instance();
((SampledPositionProperty) entity.position).setInterpolationOptions(sampledPropertyInterpolationOptions);
// Set initial camera position and orientation to be when in the model's reference frame.
final org.cesiumjs.cs.scene.Camera camera = csVPanel.getViewer().camera;
camera.position = new Cartesian3(0.25, 0.0, 0.0);
camera.direction = new Cartesian3(1.0, 0.0, 0.0);
camera.up = new Cartesian3(0.0, 0.0, 1.0);
camera.right = new Cartesian3(0.0, -1.0, 0.0);
csVPanel.getViewer().scene().preRender().addEventListener(new Scene.Listener() {
@Override
public void function(Scene scene, JulianDate time) {
Cartesian3 position = entity.position.getValue(time);
if (position == null || !Cesium.defined(position)) {
return;
}
Matrix4 transform;
if (!Cesium.defined(entity.orientation)) {
transform = Transforms.eastNorthUpToFixedFrame(position);
} else {
Quaternion orientation = (Quaternion) entity.orientation.getValue(time);
if (!Cesium.defined(orientation)) {
return;
}
transform = Matrix4.fromRotationTranslation(Matrix3.fromQuaternion(orientation), position);
}
// Save camera state
Cartesian3 offset = camera.position.clone();
Cartesian3 direction = camera.direction.clone();
Cartesian3 up = camera.up.clone();
// Set camera to be in model's reference frame.
camera.lookAtTransform(transform);
// Reset the camera state to the saved state so it appears fixed in the model's frame.
offset.clone(camera.position);
direction.clone(camera.direction);
up.clone(camera.up);
Cartesian3.cross(direction, up, camera.right);
}
});
// Add a few more balloons flying with the one the viewer is in.
int numBalloons = 12;
for (int i = 0; i < numBalloons; ++i) {
double balloonRadius = (Math.nextRandomNumber() * 2.0 - 1.0) * 0.01 + radius;
entityOptions = new EntityOptions();
timeIntervalOptions = new TimeIntervalOptions();
timeIntervalOptions.start = start;
timeIntervalOptions.stop = stop;
entityOptions.availability = new TimeIntervalCollection(new TimeInterval[] { new TimeInterval(timeIntervalOptions) });
entityOptions.position = computeCirclularFlight(lon, lat, balloonRadius);
modelGraphicsOptions = new ModelGraphicsOptions();
modelGraphicsOptions.uri = new ConstantProperty<>(modelURI);
modelGraphicsOptions.minimumPixelSize = new ConstantProperty<>(64);
entityOptions.model = new ModelGraphics(modelGraphicsOptions);
Entity balloon = csVPanel.getViewer().entities().add(entityOptions);
sampledPropertyInterpolationOptions = new SampledPropertyInterpolationOptions();
sampledPropertyInterpolationOptions.interpolationDegree = 2;
sampledPropertyInterpolationOptions.interpolationAlgorithm = HermitePolynomialApproximation.instance();
((SampledPositionProperty) balloon.position).setInterpolationOptions(sampledPropertyInterpolationOptions);
}
contentPanel.add(new HTML("<p>Configure viewer to add a button enabling look at a mobile device with cardboard.</p>"));
contentPanel.add(csVPanel);
initWidget(contentPanel);
}
use of org.cesiumjs.cs.datasources.properties.options.SampledPropertyInterpolationOptions in project gwt-cs by iSergio.
the class Interpolation method buildPanel.
@Override
public void buildPanel() {
csVPanel = new ViewerPanel();
csVPanel.getViewer().scene().globe.enableLighting = false;
CesiumTerrainProviderOptions cesiumTerrainProviderOptions = new CesiumTerrainProviderOptions();
cesiumTerrainProviderOptions.url = "https://assets.agi.com/stk-terrain/world";
cesiumTerrainProviderOptions.requestWaterMask = true;
cesiumTerrainProviderOptions.requestVertexNormals = true;
csVPanel.getViewer().terrainProvider = new CesiumTerrainProvider(cesiumTerrainProviderOptions);
csVPanel.getViewer().scene().globe.depthTestAgainstTerrain = true;
Math.setRandomNumberSeed(3);
_start = JulianDate.fromDate(new JsDate(2015, 2, 25, 16));
_stop = JulianDate.addSeconds(_start, 360, new JulianDate());
csVPanel.getViewer().clock().startTime = _start.clone();
csVPanel.getViewer().clock().stopTime = _stop.clone();
csVPanel.getViewer().clock().currentTime = _start.clone();
csVPanel.getViewer().clock().clockRange = ClockRange.LOOP_STOP();
csVPanel.getViewer().clock().multiplier = 10;
csVPanel.getViewer().timeline().zoomTo(_start, _stop);
PositionProperty position = computeCirclularFlight(-112.110693, 36.0994841, 0.03);
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);
PolylineGlowMaterialPropertyOptions polylineGlowMaterialPropertyOptions = new PolylineGlowMaterialPropertyOptions();
polylineGlowMaterialPropertyOptions.glowPower = new ConstantProperty<>(0.1);
polylineGlowMaterialPropertyOptions.color = new ConstantProperty<>(Color.YELLOW());
PathGraphicsOptions pathGraphicsOptions = new PathGraphicsOptions();
pathGraphicsOptions.resolution = new ConstantProperty<>(1);
pathGraphicsOptions.material = new PolylineGlowMaterialProperty(polylineGlowMaterialPropertyOptions);
pathGraphicsOptions.width = new ConstantProperty<>(10);
EntityOptions entityOptions = new EntityOptions();
entityOptions.availability = new TimeIntervalCollection(new TimeInterval[] { new TimeInterval(timeIntervalOptions) });
entityOptions.position = position;
entityOptions.orientation = new VelocityOrientationProperty(position);
entityOptions.model = new ModelGraphics(modelGraphicsOptions);
entityOptions.path = new PathGraphics(pathGraphicsOptions);
_entity = csVPanel.getViewer().entities().add(entityOptions);
ListBox interpolationsLBox = new ListBox();
interpolationsLBox.addItem("Interpolation: Linear Approximation", "0");
interpolationsLBox.addItem("Interpolation: Lagrange Polynomial Approximation", "1");
interpolationsLBox.addItem("Interpolation: Hermite Polynomial Approximation", "2");
interpolationsLBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
ListBox source = (ListBox) changeEvent.getSource();
SampledPropertyInterpolationOptions sampledPropertyInterpolationOptions = new SampledPropertyInterpolationOptions();
switch(source.getSelectedValue()) {
case "0":
sampledPropertyInterpolationOptions.interpolationDegree = 1;
sampledPropertyInterpolationOptions.interpolationAlgorithm = LinearApproximation.instance();
((SampledPositionProperty) _entity.position).setInterpolationOptions(sampledPropertyInterpolationOptions);
break;
case "1":
sampledPropertyInterpolationOptions.interpolationDegree = 5;
sampledPropertyInterpolationOptions.interpolationAlgorithm = LagrangePolynomialApproximation.instance();
((SampledPositionProperty) _entity.position).setInterpolationOptions(sampledPropertyInterpolationOptions);
break;
case "2":
sampledPropertyInterpolationOptions.interpolationDegree = 2;
sampledPropertyInterpolationOptions.interpolationAlgorithm = HermitePolynomialApproximation.instance();
((SampledPositionProperty) _entity.position).setInterpolationOptions(sampledPropertyInterpolationOptions);
break;
default:
break;
}
}
});
Button viewTopDownBtn = new Button("View Top Down");
viewTopDownBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
Viewer viewer = csVPanel.getViewer();
viewer.trackedEntity = (Entity) JsObject.undefined();
viewer.zoomTo(viewer.entities(), new HeadingPitchRange(0, Math.toRadians(-90), 0));
}
});
Button viewSideBtn = new Button("View Side");
viewSideBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
Viewer viewer = csVPanel.getViewer();
viewer.trackedEntity = (Entity) JsObject.undefined();
viewer.zoomTo(viewer.entities(), new HeadingPitchRange(Math.toRadians(-90), Math.toRadians(-15), 7500.0));
}
});
Button viewAircraftBtn = new Button("View Aircraft");
viewAircraftBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
Viewer viewer = csVPanel.getViewer();
viewer.trackedEntity = _entity;
}
});
HorizontalPanel btnHPanel = new HorizontalPanel();
btnHPanel.setSpacing(5);
btnHPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
btnHPanel.add(interpolationsLBox);
btnHPanel.add(viewTopDownBtn);
btnHPanel.add(viewSideBtn);
btnHPanel.add(viewAircraftBtn);
AbsolutePanel aPanel = new AbsolutePanel();
aPanel.add(csVPanel);
aPanel.add(btnHPanel, 20, 20);
contentPanel.add(new HTML("<p>This example shows simple Cesium application</p>"));
contentPanel.add(aPanel);
initWidget(contentPanel);
}
Aggregations