Search in sources :

Example 1 with Camera

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

the class Picking method pickPosition.

private void pickPosition() {
    ModelGraphicsOptions modelGraphicsOptions = new ModelGraphicsOptions();
    modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/CesiumMilkTruck/CesiumMilkTruck-kmc.gltf");
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-123.0744619, 44.0503706));
    entityOptions.name = "milktruck";
    entityOptions.model = new ModelGraphics(modelGraphicsOptions);
    final Entity modelEntity = viewerPanel.getViewer().entities().add(new Entity(entityOptions));
    viewerPanel.getViewer().zoomTo(modelEntity);
    LabelGraphicsOptions labelGraphicsOptions = new LabelGraphicsOptions();
    labelGraphicsOptions.show = new ConstantProperty<>(false);
    labelGraphicsOptions.horizontalOrigin = new ConstantProperty<>(HorizontalOrigin.LEFT());
    entityOptions = new EntityOptions();
    entityOptions.label = new LabelGraphics(labelGraphicsOptions);
    final Entity labelEntity = viewerPanel.getViewer().entities().add(new Entity(entityOptions));
    _handler = new ScreenSpaceEventHandler(viewerPanel.getViewer().scene().canvas());
    _handler.setInputAction(new ScreenSpaceEventHandler.Listener<MouseMoveEvent>() {

        @Override
        public void function(MouseMoveEvent event) {
            boolean foundPosition = false;
            Scene scene = viewerPanel.getViewer().scene();
            PickedObject pickedObject = scene.pick(event.endPosition);
            if (scene.pickPositionSupported() && pickedObject != null && pickedObject.id == modelEntity) {
                Cartesian3 cartesian = viewerPanel.getViewer().scene().pickPosition(event.endPosition);
                if (cartesian != null) {
                    Cartographic cartographic = Cartographic.fromCartesian(cartesian);
                    String lon = new BigDecimal(Math.toDegrees(cartographic.longitude)).setScale(2, RoundingMode.HALF_EVEN).toString();
                    String lat = new BigDecimal(Math.toDegrees(cartographic.latitude)).setScale(2, RoundingMode.HALF_EVEN).toString();
                    String height = new BigDecimal(cartographic.height).setScale(2, RoundingMode.HALF_EVEN).toString();
                    labelEntity.position = new ConstantPositionProperty(cartesian);
                    labelEntity.label.show = new ConstantProperty<>(true);
                    labelEntity.label.text = new ConstantProperty<>("(" + lon + ", " + lat + ", " + height + ")");
                    Camera camera = scene.camera();
                    labelEntity.label.eyeOffset = new ConstantProperty<>(new Cartesian3(0.0, 0.0, ((PerspectiveFrustum) camera.frustum).near * 1.5 - (double) Cartesian3.distance(cartesian, camera.position)));
                    foundPosition = true;
                }
            }
            if (!foundPosition) {
                labelEntity.label.show = new ConstantProperty<>(false);
            }
        }
    }, ScreenSpaceEventType.MOUSE_MOVE());
}
Also used : Entity(org.cesiumjs.cs.datasources.Entity) MouseMoveEvent(org.cesiumjs.cs.core.events.MouseMoveEvent) LabelGraphics(org.cesiumjs.cs.datasources.graphics.LabelGraphics) Scene(org.cesiumjs.cs.scene.Scene) ModelGraphics(org.cesiumjs.cs.datasources.graphics.ModelGraphics) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions) BigDecimal(java.math.BigDecimal) ModelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions) Camera(org.cesiumjs.cs.scene.Camera) LabelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.LabelGraphicsOptions)

Example 2 with Camera

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

the class AtmosphereColor method buildPanel.

@Override
public void buildPanel() {
    _csVPanel = new ViewerPanel();
    Camera camera = _csVPanel.getViewer().camera;
    ViewOptions viewOptions = new ViewOptions();
    viewOptions.destinationPos = Cartesian3.fromDegrees(-75.5847, 40.0397, 1000.0);
    viewOptions.orientation = new HeadingPitchRoll(-Math.PI_OVER_TWO(), 0.2, 0.0);
    camera.setView(viewOptions);
    HorizontalPanel hueShiftHPanel = new HorizontalPanel();
    hueShiftHPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    hueShiftHPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    hueShiftHPanel.setSpacing(10);
    _hueShiftSlider = new Slider("hueShift", -100, 100, 0);
    _hueShiftSlider.setStep(1);
    _hueShiftSlider.setWidth("150px");
    _hueShiftSlider.addListener(new MSliderListener());
    _hueShiftTBox = new TextBox();
    _hueShiftTBox.addChangeHandler(new MChangeHandler());
    _hueShiftTBox.setText("0");
    _hueShiftTBox.setSize("30px", "12px");
    hueShiftHPanel.add(_hueShiftSlider);
    hueShiftHPanel.add(_hueShiftTBox);
    HorizontalPanel saturationShiftHPanel = new HorizontalPanel();
    saturationShiftHPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    saturationShiftHPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    saturationShiftHPanel.setSpacing(10);
    _saturationShiftSlider = new Slider("saturationShift", -100, 100, 0);
    _saturationShiftSlider.setStep(1);
    _saturationShiftSlider.setWidth("150px");
    _saturationShiftSlider.addListener(new MSliderListener());
    _saturationShiftTBox = new TextBox();
    _saturationShiftTBox.addChangeHandler(new MChangeHandler());
    _saturationShiftTBox.setText("0");
    _saturationShiftTBox.setSize("30px", "12px");
    saturationShiftHPanel.add(_saturationShiftSlider);
    saturationShiftHPanel.add(_saturationShiftTBox);
    HorizontalPanel brightnessShiftHPanel = new HorizontalPanel();
    brightnessShiftHPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    brightnessShiftHPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    brightnessShiftHPanel.setSpacing(10);
    _brightnessShiftSlider = new Slider("brightnessShift", -100, 100, 0);
    _brightnessShiftSlider.setStep(1);
    _brightnessShiftSlider.setWidth("150px");
    _brightnessShiftSlider.addListener(new MSliderListener());
    _brightnessShiftTBox = new TextBox();
    _brightnessShiftTBox.addChangeHandler(new MChangeHandler());
    _brightnessShiftTBox.setText("0");
    _brightnessShiftTBox.setSize("30px", "12px");
    brightnessShiftHPanel.add(_brightnessShiftSlider);
    brightnessShiftHPanel.add(_brightnessShiftTBox);
    CheckBox lightingCBox = new CheckBox();
    lightingCBox.setWidth("100px");
    lightingCBox.setValue(true);
    lightingCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
            _csVPanel.getViewer().scene().globe.enableLighting = !_csVPanel.getViewer().scene().globe.enableLighting;
        }
    });
    CheckBox fogCBox = new CheckBox();
    fogCBox.setWidth("100px");
    fogCBox.setValue(true);
    fogCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
            _csVPanel.getViewer().scene().fog.enabled = !_csVPanel.getViewer().scene().fog.enabled;
        }
    });
    FlexTable flexTable = new FlexTable();
    flexTable.setHTML(1, 0, "<font color=\"white\">hueShift</font>");
    flexTable.setWidget(1, 1, hueShiftHPanel);
    flexTable.setHTML(2, 0, "<font color=\"white\">saturationShift</font>");
    flexTable.setWidget(2, 1, saturationShiftHPanel);
    flexTable.setHTML(3, 0, "<font color=\"white\">brightnessShift</font>");
    flexTable.setWidget(3, 1, brightnessShiftHPanel);
    flexTable.setHTML(4, 0, "<font color=\"white\">Toggle Lighting</font>");
    flexTable.setWidget(4, 1, lightingCBox);
    flexTable.setHTML(5, 0, "<font color=\"white\">Toggle Fog</font>");
    flexTable.setWidget(5, 1, fogCBox);
    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(_csVPanel);
    aPanel.add(flexTable, 20, 20);
    contentPanel.add(new HTML("<p>Adjust hue, saturation, and brightness of the sky/atmosphere.</p>"));
    contentPanel.add(aPanel);
    initWidget(contentPanel);
}
Also used : ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) Slider(org.cleanlogic.showcase.client.examples.slider.Slider) HeadingPitchRoll(org.cesiumjs.cs.core.HeadingPitchRoll) ViewOptions(org.cesiumjs.cs.scene.options.ViewOptions) Camera(org.cesiumjs.cs.scene.Camera)

Aggregations

Camera (org.cesiumjs.cs.scene.Camera)2 BigDecimal (java.math.BigDecimal)1 HeadingPitchRoll (org.cesiumjs.cs.core.HeadingPitchRoll)1 MouseMoveEvent (org.cesiumjs.cs.core.events.MouseMoveEvent)1 Entity (org.cesiumjs.cs.datasources.Entity)1 LabelGraphics (org.cesiumjs.cs.datasources.graphics.LabelGraphics)1 ModelGraphics (org.cesiumjs.cs.datasources.graphics.ModelGraphics)1 LabelGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.LabelGraphicsOptions)1 ModelGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions)1 EntityOptions (org.cesiumjs.cs.datasources.options.EntityOptions)1 Scene (org.cesiumjs.cs.scene.Scene)1 ViewOptions (org.cesiumjs.cs.scene.options.ViewOptions)1 ViewerPanel (org.cesiumjs.cs.widgets.ViewerPanel)1 Slider (org.cleanlogic.showcase.client.examples.slider.Slider)1