# Set camera to view from entity

**URL:** <https://community.cesium.com/t/set-camera-to-view-from-entity/6461>\
**Category:** CesiumJS\
**Created:** [January 15, 2018, 9:22pm UTC](https://community.cesium.com/t/set-camera-to-view-from-entity/6461 "2018-01-15T21:22:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![srtrotter](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/srtrotter/32/33970_2.png) [@srtrotter](https://community.cesium.com/u/srtrotter)\
**Post date:** [January 15, 2018, 9:22pm UTC](https://community.cesium.com/t/set-camera-to-view-from-entity/6461/1 "2018-01-15T21:22:02Z")

</div>

I'd like to set the camera view to be looking from the perspective of an entity. For example, if an aircraft is flying, I want the camera to be positioned at the aircraft looking out from the cockpit. When the aircraft rolls, the camera should roll to.

I'm using camera.setView() and am succesfully setting the position, but I can't get the orientation quite right. I'm hoping someone can set me straight. Perhaps there is an easier way than what I am attempting?

Here's my code:

function set\_camera(entity\_id, time) {  
&nbsp;&nbsp;&nbsp;var entity = viewer.entities.getById(entity\_id);  
&nbsp;&nbsp;&nbsp;var position = entity.position.getValue(time, new Cesium.Cartesian3());  
&nbsp;&nbsp;&nbsp;var q\_R\_ecef\_to\_body = entity.orientation.getValue(time, new Cesium.Quaternion());  
&nbsp;&nbsp;&nbsp;var q\_T\_ecef\_to\_body = Cesium.Quaternion.conjugate(q\_R\_ecef\_to\_body, new Cesium.Quaternion());

&nbsp;&nbsp;&nbsp;var r4\_T\_ned\_to\_ecef = Cesium.Transforms.northEastDownToFixedFrame(position);  
&nbsp;&nbsp;&nbsp;var r3\_T\_ned\_to\_ecef = Cesium.Matrix4.getRotation(r4\_T\_ned\_to\_ecef, new Cesium.Matrix3);  
&nbsp;&nbsp;&nbsp;var q\_T\_ned\_to\_ecef = Cesium.Quaternion.normalize(Cesium.Quaternion.fromRotationMatrix(r3\_T\_ned\_to\_ecef), new Cesium.Quaternion());  
&nbsp;&nbsp;&nbsp;var q\_T\_ned\_to\_body = Cesium.Quaternion.multiply(q\_T\_ecef\_to\_body, q\_T\_ned\_to\_ecef, new Cesium.Quaternion());

&nbsp;&nbsp;&nbsp;var hpr = Cesium.HeadingPitchRoll.fromQuaternion(q\_T\_ned\_to\_body, new Cesium.HeadingPitchRoll());

&nbsp;&nbsp;&nbsp;var camera = viewer.camera;  
&nbsp;&nbsp;&nbsp;camera.setView({  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;destination: position,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;orientation: {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;heading: hpr.heading,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pitch: hpr.pitch,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;roll: hpr.roll  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;)};  
}

Any guidance would be appreciated. Thanks!  
-Steven

---

<div class="post-metadata">

**Author:** ![tkazik](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/tkazik/32/2305_2.png) [@tkazik](https://community.cesium.com/u/tkazik)\
**Post date:** [November 4, 2019, 6:10pm UTC](https://community.cesium.com/t/set-camera-to-view-from-entity/6461/2 "2019-11-04T18:10:38Z")

</div>

Hi Steven

This is exactly what I am looking for.

Did you have some success in the meantime?

Thanks for letting me know

Tim

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [November 4, 2019, 6:27pm UTC](https://community.cesium.com/t/set-camera-to-view-from-entity/6461/3 "2019-11-04T18:27:18Z")

</div>

This thread has a code snippet for figuring out an entity’s orientation:

[https://groups.google.com/d/msg/cesium-dev/xPOMVgEbids/VlwQuis3CAAJ](https://groups.google.com/d/msg/cesium-dev/xPOMVgEbids/VlwQuis3CAAJ)

---

<div class="post-metadata">

**Author:** ![srtrotter](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/srtrotter/32/33970_2.png) [@srtrotter](https://community.cesium.com/u/srtrotter)\
**Post date:** [November 4, 2019, 6:31pm UTC](https://community.cesium.com/t/set-camera-to-view-from-entity/6461/4 "2019-11-04T18:31:12Z")

</div>

Tim, I’m afraid I never did get this working perfectly. I ended up going a different route and didn’t need to do this anymore. I believe the code I posted was close, but just missing something regarding the orientation. Perhaps the code Omar just posted will get you what you need. Best of luck!
