Skip to content

Instantly share code, notes, and snippets.

@jasonbeverage
Created April 20, 2015 15:41
Show Gist options
  • Save jasonbeverage/1870b7a1148ec8c1a1a2 to your computer and use it in GitHub Desktop.
Save jasonbeverage/1870b7a1148ec8c1a1a2 to your computer and use it in GitHub Desktop.
Disable pitch in Cesium 1.6
function rotate3D(controller, startPosition, movement, constrainedAxis, rotateOnlyVertical, rotateOnlyHorizontal) {
rotateOnlyVertical = defaultValue(rotateOnlyVertical, false);
rotateOnlyHorizontal = defaultValue(rotateOnlyHorizontal, false);
var scene = controller._scene;
var camera = scene.camera;
var canvas = scene.canvas;
var oldAxis = camera.constrainedAxis;
if (defined(constrainedAxis)) {
camera.constrainedAxis = constrainedAxis;
}
var rho = Cartesian3.magnitude(camera.position);
var rotateRate = controller._rotateFactor * (rho - controller._rotateRateRangeAdjustment);
if (rotateRate > controller._maximumRotateRate) {
rotateRate = controller._maximumRotateRate;
}
if (rotateRate < controller._minimumRotateRate) {
rotateRate = controller._minimumRotateRate;
}
var phiWindowRatio = (movement.startPosition.x - movement.endPosition.x) / canvas.clientWidth;
var thetaWindowRatio = (movement.startPosition.y - movement.endPosition.y) / canvas.clientHeight;
phiWindowRatio = Math.min(phiWindowRatio, controller.maximumMovementRatio);
thetaWindowRatio = Math.min(thetaWindowRatio, controller.maximumMovementRatio);
var deltaPhi = rotateRate * phiWindowRatio * Math.PI * 2.0;
var deltaTheta = rotateRate * thetaWindowRatio * Math.PI;
// Add this to rotate3D.
// https://groups.google.com/forum/#!topic/cesium-dev/Pjrjw9asXns
if(defined(constrainedAxis)) {
// Disable pitching hopefully.
deltaTheta = 0.0;
}
if (!rotateOnlyVertical) {
camera.rotateRight(deltaPhi);
}
if (!rotateOnlyHorizontal) {
camera.rotateUp(deltaTheta);
}
camera.constrainedAxis = oldAxis;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment