Skip to content

Commit

Permalink
Merge pull request #12121 from BeyondBelief96/issues/7898/expose-zoom…
Browse files Browse the repository at this point in the history
…-factor

make screenSpaceCameraController zoomFactor public.
  • Loading branch information
ggetz authored Aug 13, 2024
2 parents be2aad4 + 85534c3 commit 3efa918
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

- Made the `time` parameter optional for `Property`, using `JulianDate.now()` as default. [#12099](https://github.com/CesiumGS/cesium/pull/12099)

- Exposes `ScreenSpaceCameraController.zoomFactor` to allow adjusting the zoom factor (speed). [#9145](https://github.com/CesiumGS/cesium/pull/9145)

##### Fixes :wrench:

- Fixed cube-mapping artifacts in image-based lighting. [#12100](https://github.com/CesiumGS/cesium/pull/12100)
Expand All @@ -19,6 +21,8 @@

- Custom specular environment maps in `ImageBasedLighting` now require either a WebGL2 context or a WebGL1 context that supports the [`EXT_shader_texture_lod` extension](https://registry.khronos.org/webgl/extensions/EXT_shader_texture_lod/).

- `ScreenSpaceCameraController._zoomFactor` replaced with public zoomFactor attribute.

### 1.120 - 2024-08-01

#### @cesium/engine
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
- [Tim Schneider](https://github.com/Tim-S)
- [Vladislav Yunev](https://github.com/YunVlad)
- [Levi Montgomery](https://github.com/Levi-Montgomery)
- [Brandon Berisford](https://github.com/BeyondBelief96)
15 changes: 11 additions & 4 deletions packages/engine/Source/Scene/ScreenSpaceCameraController.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ function ScreenSpaceCameraController(scene) {
* @default {@link Number.POSITIVE_INFINITY}
*/
this.maximumZoomDistance = Number.POSITIVE_INFINITY;

/**
* A multiplier for the speed at which the camera will zoom.
* @type {Number}
* @default 5.0
*/
this.zoomFactor = 5.0;

/**
* The input that allows the user to pan around the map. This only applies in 2D and Columbus view modes.
* <p>
Expand Down Expand Up @@ -324,7 +332,6 @@ function ScreenSpaceCameraController(scene) {
);

// Constants, Make any of these public?
this._zoomFactor = 5.0;
this._rotateFactor = undefined;
this._rotateRateRangeAdjustment = undefined;
this._maximumRotateRate = 1.77;
Expand Down Expand Up @@ -1005,7 +1012,7 @@ function zoom2D(controller, startPosition, movement) {
controller,
startPosition,
movement,
controller._zoomFactor,
controller.zoomFactor,
camera.getMagnitude()
);
}
Expand Down Expand Up @@ -1763,7 +1770,7 @@ function zoomCV(controller, startPosition, movement) {
controller,
startPosition,
movement,
controller._zoomFactor,
controller.zoomFactor,
distance
);
}
Expand Down Expand Up @@ -2363,7 +2370,7 @@ function zoom3D(controller, startPosition, movement) {
controller,
startPosition,
movement,
controller._zoomFactor,
controller.zoomFactor,
distance,
Cartesian3.dot(unitPosition, camera.direction)
);
Expand Down
34 changes: 34 additions & 0 deletions packages/engine/Specs/Scene/ScreenSpaceCameraControllerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,40 @@ describe("Scene/ScreenSpaceCameraController", function () {
);
});

it("can adjust zoom factor", function () {
setUp3D();

// Zoom out
const mouseWheelMovement = -120;

// Slow zoom
const initialPosition = Cartesian3.clone(camera.position);
controller.zoomFactor = 1.0;
simulateMouseWheel(mouseWheelMovement);
updateController();
const slowZoomPosition = Cartesian3.clone(camera.position);
const slowZoomMagnitude = Cartesian3.magnitude(slowZoomPosition);

// Medium zoom
camera.position = Cartesian3.clone(initialPosition);
controller.zoomFactor = 5.0;
simulateMouseWheel(mouseWheelMovement);
updateController();
const mediumZoomPosition = Cartesian3.clone(camera.position);
const mediumZoomMagnitude = Cartesian3.magnitude(mediumZoomPosition);

// Fast zoom
camera.position = Cartesian3.clone(initialPosition);
controller.zoomFactor = 10.0;
simulateMouseWheel(mouseWheelMovement);
updateController();
const fastZoomPosition = Cartesian3.clone(camera.position);
const fastZoomMagnitude = Cartesian3.magnitude(fastZoomPosition);

expect(fastZoomMagnitude).toBeGreaterThan(mediumZoomMagnitude);
expect(mediumZoomMagnitude).toBeGreaterThan(slowZoomMagnitude);
});

it("is destroyed", function () {
expect(controller.isDestroyed()).toEqual(false);
controller.destroy();
Expand Down

0 comments on commit 3efa918

Please sign in to comment.