# camera.lookAt.range

**URL:** <https://community.cesium.com/t/camera-lookat-range/2005>\
**Category:** CesiumJS\
**Created:** [February 13, 2015, 10:21am UTC](https://community.cesium.com/t/camera-lookat-range/2005 "2015-02-13T10:21:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Entin](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@Alexander\_Entin](https://community.cesium.com/u/Alexander_Entin)\
**Post date:** [February 13, 2015, 10:21am UTC](https://community.cesium.com/t/camera-lookat-range/2005/1 "2015-02-13T10:21:02Z")

</div>

Gents,

I need to know how far camera is looking.

I think of something like:

C.Cartesian3.distance(C.camera.position, C.camera.pickEllipsoid(new C.Cartesian2(C.canvas.width/2, C.canvas.height/2)))

But how to account for terrain?

Thank you.

---

<div class="post-metadata">

**Author:** ![Hyper\_Sonic](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hyper_sonic/32/2255_2.png) [@Hyper\_Sonic](https://community.cesium.com/u/Hyper_Sonic)\
**Post date:** [February 13, 2015, 11:03am UTC](https://community.cesium.com/t/camera-lookat-range/2005/2 "2015-02-13T11:03:58Z")

</div>

If you want to get pick position onto a terrain surface use

var ray = scene.camera.getPickRay(new Cesium.Cartesian2( viewer.canvas.clientWidth / 2,viewer.canvas.clientHeight / 2));  
var pos = scene.globe.pick(ray, scene);

``

If you want to get pick position onto an Ellipsoid surface use

var pos = viewer.camera.pickEllipsoid(new Cesium.Cartesian2( viewer.canvas.clientWidth / 2,viewer.canvas.clientHeight / 2));

``

Then get range using

var CC3 = Cesium.Cartesian3;  
var range = CC3.magnitude(CC3.subtract(camera.position,pos,new CC3()));

``

pickEllipsoid picks ellipsoid regardless of terrain being on or off.

getPickRay will pick terrain if it’s on, otherwise it will pick ellipsoid.

(this all assumes 3D mode)

---

<div class="post-metadata">

**Author:** ![Alexander\_Entin](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@Alexander\_Entin](https://community.cesium.com/u/Alexander_Entin)\
**Post date:** [February 13, 2015, 1:24pm UTC](https://community.cesium.com/t/camera-lookat-range/2005/3 "2015-02-13T13:24:15Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![Hyper\_Sonic](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hyper_sonic/32/2255_2.png) [@Hyper\_Sonic](https://community.cesium.com/u/Hyper_Sonic)\
**Post date:** [February 13, 2015, 1:52pm UTC](https://community.cesium.com/t/camera-lookat-range/2005/4 "2015-02-13T13:52:14Z")

</div>

You’re welcome. Looking at the code I noticed that pickEllipsoid also calls camera.getPickRay. However what it does with the ray is different.

IntersectionTests.rayEllipsoid(ray, ellipsoid);

``

Yields the distance to the ellipsoid (t.)

Ray.getPoint(ray, t, result);

``

Determines the end point of the ray if you travel t distance along the ray from its origin in the ray’s direction.

---

<div class="post-metadata">

**Author:** ![Hyper\_Sonic](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hyper_sonic/32/2255_2.png) [@Hyper\_Sonic](https://community.cesium.com/u/Hyper_Sonic)\
**Post date:** [February 13, 2015, 2:38pm UTC](https://community.cesium.com/t/camera-lookat-range/2005/5 "2015-02-13T14:38:11Z")

</div>

Perhaps there should be a Camera.prototype.pickTerrain modeled after Camera.prototype.pickEllipsoid.

There’s a switch within pickEllipsoid:

pickEllipsoid3D

pickMap2D

pickMapColumbusView

So within pickTerrain there could also be a similar switch

-pickTerrain3D

-pickTerrain2d

-pickTerrainColumbusView

Each of these sub functions pick terrain properly for their mode.

-pickTerrain3D would use scene.globe.pick

-Columbus View can have terrain, does scene.globe.pick work in this mode?

-2DMode currently has no terrain option so it would just pick the flat surface.

It seems that 2D is Columbus View with projection switched from Perspective to Orthographic. If you could pitch in 2D mode then terrain in 2D would make sense.
