Height of camera giving negative numbers

Hi

I am trying to calculate the height of the camera above the surface of the ellipsoid.

I have the following code but it gives negative numbers…

var camera = viewer.camera;

var cameraHeight = ellipsoid.cartesianToCartographic(camera.position).height;

console.log(cameraHeight);

This is the kind of number I am getting -6367317.724965978

I am running it on the clock tick

I cant see where I am going wrong.

Thanks

I have been doing some further investigation. I was tracking an entity by default. When I turned the tracking of the entity off, the camera height gave the correct values.

Why would the tracking of an entity change the value of the height of the camera?

Thanks

Instead of using camera.position, use camera.positionWC , which is always relative to the Earth. http://cesiumjs.org/Cesium/Build/Documentation/Camera.html

Camera position and orientation is relative to the camera’s transform. When you’re tracking, the camera’s transform is the target’s EastNorthUp transform. You’re probably just a few meters from the origin of the target’s transform. Well if you put small values into ellipsoid.cartesianToCartographic (which assumes world coordinates) you’re going to be close to the center of the Earth. The average radius of the Earth is 6,371,000 meters, which would explain the -6367317 height.

Great, that has solved it. Now to get my head round it all. Thanks!

I have also been trying to discover the current frame rate. I am still looking for a method to do that. Could you help?

Well within the onTick function just check the time in milliseconds http://www.w3schools.com/jsref/jsref_gettime.asp Save and compare for the next onTick call. This will get you ‘wall time’ which can’t be paused, as opposed to ‘simulation time’.