Camera height in 2D

How can I get the camera height in 2D mode?

I try to use
var height = ellipsoie.cartesianToCartographic(scene.getCamera().position).height;
to get the camera height.

In 3D mode,it works well.But in 2D mode,the value of height remains the same.

You can use “positionWC” to get the camera in world coordinates, regardless of SceneMode. So your code would like like

var height = ellipsoid.cartesianToCartographic(scene.getCamera().positionWC).height;

The reason position is not what you expect in 2D is because the primary camera properties are SceneMode/ReferenceFrame/projection dependant.

thanks for your reply,Matthew.I follow you to change position to positionWC,but in 2D mode, when I zoom in to get closer to ground, the value of height still remains the same.

Sorry to hear that didn’t work, I’ll have to ask around to see why that’s the case. In the mean time, you can try the below line of code, which is 2D-specific. So check the SceneMode before using it. height will be in meters.

var height = camera.frustum.right - camera.frustum.left;

thanks very much.

hi Matthew, I guess that the value of camera's height above ground should be:

var height = (camera.frustum.right - camera.frustum.left) * 0.5 , since I found following code in UniformState.prototype.update(context, frameState){
this._frustum2DWidth = camera.frustum.right - camera.frustum.left;
this._eyeHeight2D.x = this._frustum2DWidth * 0.5;
}, and following annotation in UniformState.js:
        // In 2D, the camera height is always 12.7 million meters.
        // The apparent height is equal to half the frustum width.

Can't sure if that is correct, and wonder why change frustum instead of change camera position? And why the camera height is always 12.7 million meters ? Just a few explanation could help me understand, thanks!

在 2014年2月18日星期二UTC+8上午11时09分43秒,Matthew Amato写道:

This works pretty good. How do I get camera height for Columbus View?

The camera height is dependent on the scene mode.

For 3D:

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

For Columbus View:

var height = camera.position.z;

For 2D:

var height = (camera.frustum.right - camera.frustum.left) * 0.5;

The reason the camera is zoomed using the frustum instead of decreasing the distance in 2D is because of the nature of orthographic projection (as opposed to perspective projection used for 3D and Columbus view). If you’re interested, see the page on projections on Wikipedia for more information.



Thanks Daniel. That’s exactly what I needed!!