Skip to content

Commit

Permalink
Maintain camera heading, pitch, and roll on zoom CesiumGS#4639
Browse files Browse the repository at this point in the history
  • Loading branch information
wallw-teal committed Jul 26, 2017
1 parent 769b09a commit e48d1c4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Source/Scene/ScreenSpaceCameraController.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,13 @@ define([
var scratchCartesian = new Cartesian3();
var scratchCartesianTwo = new Cartesian3();
var scratchCartesianThree = new Cartesian3();
var scratchZoomViewOptions = {
orientation: {
heading: 0,
pitch: 0,
roll: 0
}
};

function handleZoom(object, startPosition, movement, zoomFactor, distanceMeasure, unitPositionDotDirection) {
var percentage = 1.0;
Expand Down Expand Up @@ -485,6 +492,11 @@ define([
var camera = scene.camera;
var mode = scene.mode;

var orientation = scratchZoomViewOptions.orientation;
orientation.heading = camera.heading;
orientation.pitch = camera.pitch;
orientation.roll = camera.roll;

if (camera.frustum instanceof OrthographicFrustum) {
if (Math.abs(distance) > 0.0) {
camera.zoomIn(distance);
Expand Down Expand Up @@ -646,6 +658,7 @@ define([
Cartesian3.cross(camera.direction, camera.up, camera.right);
Cartesian3.cross(camera.right, camera.direction, camera.up);

camera.setView(scratchZoomViewOptions);
return;
}

Expand Down Expand Up @@ -691,6 +704,8 @@ define([
} else {
camera.zoomIn(distance);
}

camera.setView(scratchZoomViewOptions);
}

var translate2DStart = new Ray();
Expand Down
12 changes: 12 additions & 0 deletions Specs/Scene/ScreenSpaceCameraControllerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,19 +849,31 @@ defineSuite([
it('zoom in 3D with wheel', function() {
setUp3D();
var position = Cartesian3.clone(camera.position);
var heading = camera.heading;
var pitch = camera.pitch;
var roll = camera.roll;

simulateMouseWheel(120);
updateController();
expect(Cartesian3.magnitude(position)).toBeGreaterThan(Cartesian3.magnitude(camera.position));
expect(camera.heading).toBeCloseTo(heading, 10);
expect(camera.pitch).toBeCloseTo(pitch, 10);
expect(camera.roll).toBeCloseTo(roll, 10);
});

it('zoom out in 3D with wheel', function() {
setUp3D();
var position = Cartesian3.clone(camera.position);
var heading = camera.heading;
var pitch = camera.pitch;
var roll = camera.roll;

simulateMouseWheel(-120);
updateController();
expect(Cartesian3.magnitude(position)).toBeLessThan(Cartesian3.magnitude(camera.position));
expect(camera.heading).toBeCloseTo(heading, 10);
expect(camera.pitch).toBeCloseTo(pitch, 10);
expect(camera.roll).toBeCloseTo(roll, 10);
});

it('zoom in 3D with orthographic projection', function() {
Expand Down

0 comments on commit e48d1c4

Please sign in to comment.