Distance between the camera and the globe?

tl;dr: How do I get the distance from the camera to the globe (preferably to the nearest point on the surface, else the centre)?

I've been playing around with Cesium for only a couple of hours now, but I very much like what I'm seeing. I just received my Leap Motion in the mail today, and was inspired by <a href="http://blog.leapmotion.com/post/55639018480/leapinto-google-earth">Google Earth</a> to support hand-wavey input to fly the camera around.

I've made a basic start and am pretty happy so far. However I need to be able to move slower the closer I get to the surface, and for that I need to know how far away the surface is. From reading the docs, the closest I got was CameraController.getMagnitude(), but that seems to vary wildly over time, and I'm not exactly sure which vector it's measuring.

Try calling camera.getPositionWC() and converting that to Cartographic. The height property on the Cartographic is the value you want.

We’ve done some experimenting with the Leap in our SpaceApps hackathon project (https://github.com/AnalyticalGraphicsInc/EarthKAMExplorer) Feel free to check that out if you want to see what we were doing with the Leap and Cesium. It was a 48 hour project, so it’s definitely rough around the edges. If you end up with something you’re happy with, we’d love to take a pull request from you so we can add out-of-the-box Leap support in Cesium.

Thanks Matthew! Sorry for the delay, seems I didn’t get subscribed. My team is planning to build an application for rendering urban environments on top of Cesium, so I can envision some pretty cool applications for the Leap, like rotating buildings with one’s hands and such. I’ll definitely check out your code and try and find some time to put towards what is unfortunately a pretty high-risk feature.

Hello Oliver,

This is how I've been getting the distance from the camera to the ellipsoid (globe).

var cameraHeight = ellipsoid.cartesianToCartographic(scene.getCamera().position).height;

If you need a reference to the scene use:
If you need a reference to the ellipsoid use:


var cameraHeight = GetCameraHeight(widget.scene, widget.centralBody.getEllipsoid())

function GetCameraHeight(scene, ellipsoid)
    var cameraHeight = ellipsoid.cartesianToCartographic(scene.getCamera().position).height;
    return cameraHeight;

var widget = new Cesium.CesiumWidget('cesiumContainer');