Skip to content

Commit

Permalink
Merge pull request #9970 from CesiumGS/camera-changed-fix
Browse files Browse the repository at this point in the history
updating Camera.changed to account for changes in heading
  • Loading branch information
lilleyse authored Dec 10, 2021
2 parents 4d5e3d8 + 667afdc commit e9ec65d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Fixed handling of vec3 vertex colors in `ModelExperimental`. [#9955](https://github.com/CesiumGS/cesium/pull/9955)
- Fixed handling of Draco quantized vec3 vertex colors in `ModelExperimental`. [#9957](https://github.com/CesiumGS/cesium/pull/9957)
- Fixed handling of vec3 vertex colors in `CustomShaderPipelineStage`. [#9964](https://github.com/CesiumGS/cesium/pull/9964)
- Fixes how `Camera.changed` handles changes in `heading`. [#9970](https://github.com/CesiumGS/cesium/pull/9970)
- Fixed handling of subtree root transforms in `Implicit3DTileContent`. [#9971](https://github.com/CesiumGS/cesium/pull/9971)
- Fixed issue in `ModelExperimental` where indices were not the correct data type after draco decode. [#9974](https://github.com/CesiumGS/cesium/pull/9974)
- Fixed WMS 1.3.0 `GetMap` `bbox` parameter so that it follows the axis ordering as defined in the EPSG database. [#9797](https://github.com/CesiumGS/cesium/pull/9797)
Expand Down
20 changes: 20 additions & 0 deletions Source/Scene/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ function Camera(scene) {
this._changedPosition = undefined;
this._changedDirection = undefined;
this._changedFrustum = undefined;
this._changedHeading = undefined;

/**
* The amount the camera has to change before the <code>changed</code> event is raised. The value is a percentage in the [0, 1] range.
Expand Down Expand Up @@ -361,6 +362,25 @@ Camera.prototype._updateCameraChanged = function () {

var percentageChanged = camera.percentageChanged;

var currentHeading = camera.heading;

if (!defined(camera._changedHeading)) {
camera._changedHeading = currentHeading;
}

var delta =
Math.abs(camera._changedHeading - currentHeading) % CesiumMath.TWO_PI;
delta = delta > CesiumMath.PI ? CesiumMath.TWO_PI - delta : delta;

// Since delta is computed as the shortest distance between two angles
// the percentage is relative to the half circle.
var headingChangedPercentage = delta / Math.PI;

if (headingChangedPercentage > percentageChanged) {
camera._changed.raiseEvent(headingChangedPercentage);
camera._changedHeading = currentHeading;
}

if (camera._mode === SceneMode.SCENE2D) {
if (!defined(camera._changedFrustum)) {
camera._changedPosition = Cartesian3.clone(
Expand Down
26 changes: 25 additions & 1 deletion Specs/Scene/SceneSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,30 @@ describe(
s.destroyForSpecs();
});

it("raises the camera changed event on heading changed", function () {
var s = createScene();

var spyListener = jasmine.createSpy("listener");
s.camera.changed.addEventListener(spyListener);

s.initializeFrame();
s.render();

s.camera.twistLeft(CesiumMath.PI * (s.camera.percentageChanged + 0.1));

s.initializeFrame();
s.render();

expect(spyListener.calls.count()).toBe(1);

var args = spyListener.calls.allArgs();
expect(args.length).toEqual(1);
expect(args[0].length).toEqual(1);
expect(args[0][0]).toBeGreaterThan(s.camera.percentageChanged);

s.destroyForSpecs();
});

it("raises the camera changed event on position changed", function () {
var s = createScene();

Expand All @@ -1318,7 +1342,7 @@ describe(
s.initializeFrame();
s.render();

s.camera.moveLeft(
s.camera.moveUp(
s.camera.positionCartographic.height *
(s.camera.percentageChanged + 0.1)
);
Expand Down

0 comments on commit e9ec65d

Please sign in to comment.