Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintain camera heading, pitch, and roll on zoom #5603

Merged
merged 7 commits into from
Sep 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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