Skip to content

Commit

Permalink
Merge pull request #5603 from wallw-bits/maintain-camera-heading-on-zoom
Browse files Browse the repository at this point in the history
Maintain camera heading, pitch, and roll on zoom
  • Loading branch information
pjcozzi authored Sep 8, 2017
2 parents 3646fef + 7d6d6af commit 10f78b5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Change Log
==========
### 1.38 - 2017-10-02

* Zoom about mouse now maintains camera heading, pitch, and roll [#4639](https://github.com/AnalyticalGraphicsInc/cesium/pull/5603)

### 1.37 - 2017-09-01

* Breaking changes
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
* [Jason Crow](https://github.com/jason-crow)
* [Flightradar24 AB](https://www.flightradar24.com)
* [Aleksei Kalmykov](https://github.com/kalmykov)
* [BIT Systems](http://www.caci.com/bit-systems)
* [William Wall](https://github.com/wallw-bits)
* [virtualcitySYSTEMS GmbH](https://www.virtualcitysystems.de)
* [Jannes Bolling](https://github.com/jbo023)

Expand Down
13 changes: 13 additions & 0 deletions Source/Scene/ScreenSpaceCameraController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ define([
'../Core/destroyObject',
'../Core/DeveloperError',
'../Core/Ellipsoid',
'../Core/HeadingPitchRoll',
'../Core/IntersectionTests',
'../Core/isArray',
'../Core/KeyboardEventModifier',
Expand Down Expand Up @@ -35,6 +36,7 @@ define([
destroyObject,
DeveloperError,
Ellipsoid,
HeadingPitchRoll,
IntersectionTests,
isArray,
KeyboardEventModifier,
Expand Down Expand Up @@ -446,6 +448,9 @@ define([
var scratchCartesian = new Cartesian3();
var scratchCartesianTwo = new Cartesian3();
var scratchCartesianThree = new Cartesian3();
var scratchZoomViewOptions = {
orientation: new HeadingPitchRoll()
};

function handleZoom(object, startPosition, movement, zoomFactor, distanceMeasure, unitPositionDotDirection) {
var percentage = 1.0;
Expand Down Expand Up @@ -485,6 +490,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 +656,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 +702,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 10f78b5

Please sign in to comment.