Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easy API to select a non-earth ellipsoid #4245

Closed
hpinkos opened this issue Aug 29, 2016 · 8 comments · Fixed by #12000
Closed

Easy API to select a non-earth ellipsoid #4245

hpinkos opened this issue Aug 29, 2016 · 8 comments · Fixed by #12000

Comments

@hpinkos
Copy link
Contributor

hpinkos commented Aug 29, 2016

Users on the forum want to use non-earth ellipsoids but it is unclear how they have to set it.

@emackey
Copy link
Contributor

emackey commented Aug 29, 2016

Unfortunately it's not as simple as we might like. You must tell the imageryProvider and the mapProjection about your choice of ellipsoid. The CesiumWidget.globe will automatically grab it from scene.mapProjection if it needs it.

In this demo, the hover text is Cartesian3 in meters, so you can see it's the Moon's radius and not the Earth.

// First, select your favorite ellipsoid.
var ellipsoid = Cesium.Ellipsoid.MOON;

var imagery = new Cesium.SingleTileImageryProvider({
    // Your imagery provider needs the ellipsoid.  Specify it here.
    ellipsoid: ellipsoid,
    url: Cesium.buildModuleUrl('Assets/Textures/moonSmall.jpg')
});

var viewer = new Cesium.Viewer('cesiumContainer', {
    // The CesiumWidget and the Globe get Ellipsoid from Scene.mapProjection.
    mapProjection: new Cesium.GeographicProjection(ellipsoid),
    // Don't forget your imagery provider that uses the ellipsoid.
    imageryProvider: imagery,
    // Set some other options too.
    selectionIndicator : false,
    infoBox : false,
    baseLayerPicker: false,
    geocoder: false,
    skyAtmosphere: false
});

var scene = viewer.scene;
var handler;

var entity = viewer.entities.add({
    label : {
        show : false
    }
});

handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(movement) {
    var cartesian = viewer.camera.pickEllipsoid(movement.endPosition, scene.globe.ellipsoid);
    if (cartesian) {
        var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
        var longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(2);
        var latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(2);

        entity.position = cartesian;
        entity.label.show = true;
        entity.label.text = '(' + cartesian.x.toFixed(0) + ', ' + cartesian.y.toFixed(0) +
            ', ' + cartesian.z.toFixed(0) + ')';
    } else {
        entity.label.show = false;
    }
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

I vote to close this, or change it to a doc issue.

@hpinkos hpinkos changed the title Camera unusable for non-earth ellispoid Document how to select a non-earth ellipsoid Aug 29, 2016
@hpinkos
Copy link
Contributor Author

hpinkos commented Aug 29, 2016

Thanks @emackey! I updated this issue and labeled it doc

@mramato
Copy link
Contributor

mramato commented Aug 30, 2016

I think we could do a lot better codewise here. My official recommendation for updating the ellipsoid is actually a hack'; simply set Ellipsoid.WGS84 to whatever ellipsoid values you want at the start of your app and then Cesium is guaranteed to use it everywhere. For single-ellipsoid apps, this is by far the easiest way to do it. Because of this, I think it might be worth introducing Ellipsoid.Default and just having that be WGS84 by default and use Ellipsoid.Default everywhere in Cesium. Then my "hack" can become the official way to change the default ellipsoid and the only reason you would need t specify it otherwise is if you have multiple scenes with multiple ellipsoids in your app.

@mramato
Copy link
Contributor

mramato commented Aug 30, 2016

Of course there could be a flaw in my plan, but I'm not sure what it could be.

@emackey
Copy link
Contributor

emackey commented Aug 30, 2016

I find this hack tempting, but there are potential issues. Cesium is already very reliant on the concept of a default ellipsoid, and uses WGS84 to initialize several scratch variables hidden in closures around the codebase (for example: GeographicProjection is constructed and saved as scratch in BoundingSphere and RectangleGeometryLibrary. Likewise, EllipseGeometry constructs one that gets saved in CircleGeometry, even though the latter appears to be constructing a unit sphere and yet contains a hidden default reference to WGS84. You can find these and more such examples by modifying WGS84 to be null in original source code, and then attempting to run the moon code above).

Resetting the default ellipsoid in user code, even if done before constructing a viewer, cannot happen in time to reset all of these pre-constructed scratch variables. Specifying the ellipsoid manually, in each and every place it is needed, is currently the only way to have some hope that the factory default doesn't creep in anywhere... but I don't know of any way to enforce that with tests such that newly-added default ellipsoid references get detected somehow. Perhaps we assign Ellipsoid.Default to be the unit sphere during startup, and then reset it to WGS84 just before handing off to user code? That might force these issues to the surface, since any code holding onto a unit sphere would presumably be obviously wrong for the Earth.

I still have long-term hope of visualizing interplanetary missions in Cesium with multiple central bodies in one window. We'll need to have a good way to avoid reliance on defaults for that.

@pjcozzi
Copy link
Contributor

pjcozzi commented Jan 2, 2017

CC #4069

@OmarShehata
Copy link
Contributor

Looks like the ground atmosphere has to be turned off for this to work now: viewer.scene.globe.showGroundAtmosphere = false; see #8000

@jumpjack
Copy link

news about multiple globes/ellipsoids for planets representation?

@ggetz ggetz added the onramping label Dec 9, 2022
@ggetz ggetz changed the title Document how to select a non-earth ellipsoid Easy API to select a non-earth ellipsoid May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants