Lock Axis when rotating camera

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!

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.

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.

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

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

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

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

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

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

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

Thanks,

Gabby