# Lock Axis when rotating camera

**URL:** <https://community.cesium.com/t/lock-axis-when-rotating-camera/669>\
**Category:** CesiumJS\
**Created:** [August 15, 2013, 5:25pm UTC](https://community.cesium.com/t/lock-axis-when-rotating-camera/669 "2013-08-15T17:25:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lorenzo\_Campanis](https://avatars.discourse-cdn.com/v4/letter/l/9dc877/32.png) [@Lorenzo\_Campanis](https://community.cesium.com/u/Lorenzo_Campanis)\
**Post date:** [August 15, 2013, 5:25pm UTC](https://community.cesium.com/t/lock-axis-when-rotating-camera/669/1 "2013-08-15T17:25:32Z")

</div>

Hi,

I am looking for the best approach in locking the y-axis. So that the camera rotates left and right only.

I have looked into

> scene.getScreenSpaceCameraController().enableRotate = false;

But this locks all directions

Can we lock up and down?

Or is there some other way?

Thank you!

---

<div class="post-metadata">

**Author:** ![Matt\_Amato](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/matt_amato/32/1993_2.png) [@Matt\_Amato](https://community.cesium.com/u/Matt_Amato)\
**Post date:** [September 3, 2013, 2:56pm UTC](https://community.cesium.com/t/lock-axis-when-rotating-camera/669/2 "2013-09-03T14:56:06Z")

</div>

Lorenzo, I don’t personally know how to do it, but I’m bumping this so Dan can hopefully answer. If it’s not trivial, then I’ll write up a feature request, so that we don’t forget about it.

---

<div class="post-metadata">

**Author:** ![Dan\_Bagnell](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@Dan\_Bagnell](https://community.cesium.com/u/Dan_Bagnell)\
**Post date:** [September 3, 2013, 6:10pm UTC](https://community.cesium.com/t/lock-axis-when-rotating-camera/669/3 "2013-09-03T18:10:04Z")

</div>

Hi Lorenzo,

There is no way to restrict the camera to rotate left and right only. You could add a custom render loop where you could do this:

// perform built in camera updates

scene.initializeFrame();

var camera = scene.getCamera();

// set the camera position to be in the plane of the equator

camera.position.z = 0.0;

// reset the direction to point towards the center of the earth

Cartesian3.negate(camera.position, camera.direction);

Cartesian3.normalize(camera.direction, camera.direction);

// orient so that ‘up’ is pointing north

Cartesian3.clone(Cartesian3.UNIT\_Z, camera.up);

Cartesian3.cross(camera.direction, camera.up, camera.right);

// render scene

scene.render();

This code would only work in 3D. If you need help with 2D or Columbus view modes, let us know.

---

<div class="post-metadata">

**Author:** ![mathew.callow](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@mathew.callow](https://community.cesium.com/u/mathew.callow)\
**Post date:** [May 4, 2016, 3:35pm UTC](https://community.cesium.com/t/lock-axis-when-rotating-camera/669/4 "2016-05-04T15:35:35Z")

</div>

Hi Daniel,

I'm looking in to doing basically the same thing myself, for the purposes of making something comparable to a traditional desktop globe, tilted at an angle with a pivot through the poles.

It's been a few years, and I could see this being a feature which had been added in the mean-time. Is your method above still the best way to achieve this kind of effect?

Thanks,  
Mat

---

<div class="post-metadata">

**Author:** ![hannah](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hannah/32/4509_2.png) [@hannah](https://community.cesium.com/u/hannah)\
**Post date:** [May 5, 2016, 2:22pm UTC](https://community.cesium.com/t/lock-axis-when-rotating-camera/669/5 "2016-05-05T14:22:32Z")

</div>

Hello Mat,

I don’t think anything has been implemented to handle that type of functionality. The solution provided above should still work.

Best,

Hannah

---

<div class="post-metadata">

**Author:** ![mathew.callow](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@mathew.callow](https://community.cesium.com/u/mathew.callow)\
**Post date:** [May 5, 2016, 2:25pm UTC](https://community.cesium.com/t/lock-axis-when-rotating-camera/669/6 "2016-05-05T14:25:32Z")

</div>

Hi Hannah,

Ah, okay. The given solution seems a little rough (though that might just be my implementation!), but it works.

Thanks for letting me know!

Regards,  
Mat

---

<div class="post-metadata">

**Author:** ![pankaj.bhatotia123](https://avatars.discourse-cdn.com/v4/letter/p/b782af/32.png) [@pankaj.bhatotia123](https://community.cesium.com/u/pankaj.bhatotia123)\
**Post date:** [May 18, 2016, 12:15pm UTC](https://community.cesium.com/t/lock-axis-when-rotating-camera/669/7 "2016-05-18T12:15:22Z")

</div>

hello,  
i am trying lock the axis so camera does not roll.  
i want my camera to move left to right ant up and down (specially in VR mode). guyz please help this causes problem in my project.  
Thank you

---

<div class="post-metadata">

**Author:** ![11148](https://avatars.discourse-cdn.com/v4/letter/1/db5fbb/32.png) [@11148](https://community.cesium.com/u/11148)\
**Post date:** [March 19, 2018, 1:47am UTC](https://community.cesium.com/t/lock-axis-when-rotating-camera/669/8 "2018-03-19T01:47:35Z")

</div>

Is there a newer method for this function with the Cesium 1.43？

在 2013年8月16日星期五 UTC+8上午1:25:32，Lorenzo Campanis写道：

---

<div class="post-metadata">

**Author:** ![Gabby\_Getz](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/gabby_getz/32/7838_2.png) [@Gabby\_Getz](https://community.cesium.com/u/Gabby_Getz)\
**Post date:** [March 20, 2018, 2:08pm UTC](https://community.cesium.com/t/lock-axis-when-rotating-camera/669/9 "2018-03-20T14:08:47Z")

</div>

Not currently, I would still use the solution described above.

Thanks,

Gabby
