Skip to content

Commit

Permalink
Tweak camera flight path height computation and add a test for the ma…
Browse files Browse the repository at this point in the history
…ximumHeight parameter.
  • Loading branch information
bagnell committed Mar 8, 2016
1 parent 54e64bb commit 7f2e768
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Source/Scene/CameraFlightPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ define([
var altitude = optionAltitude;
var maxHeight = Math.max(startHeight, endHeight);

if (!defined(optionAltitude)) {
if (!defined(altitude)) {
var start = camera.position;
var end = destination;
var up = camera.up;
Expand All @@ -76,7 +76,7 @@ define([
altitude = Math.min(getAltitude(frustum, verticalDistance, horizontalDistance) * 0.20, 1000000000.0);
}

if ((defined(optionAltitude) && optionAltitude < altitude) || maxHeight < altitude) {
if (maxHeight < altitude) {
var power = 8.0;
var factor = 1000000.0;

Expand Down
41 changes: 41 additions & 0 deletions Specs/Scene/CameraFlightPathSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,4 +382,45 @@ defineSuite([
flight.complete();
expect(camera.position).toEqualEpsilon(endPosition, CesiumMath.EPSILON12);
});

it('does not go above the maximum height', function() {
var camera = scene.camera;

var startPosition = Cartesian3.fromDegrees(0.0, 0.0, 1000.0);
var endPosition = Cartesian3.fromDegrees(10.0, 0.0, 1000.0);
var duration = 5.0;

camera.setView({
destination : startPosition
});

var flight = CameraFlightPath.createTween(scene, {
destination : endPosition,
duration : duration
});

var maximumHeight = Number.NEGATIVE_INFINITY;
var i;
for (i = 0; i <= duration; ++i) {
flight.update({ time : i });
maximumHeight = Math.max(maximumHeight, camera.positionCartographic.height);
}

maximumHeight *= 0.5;

camera.setView({
destination : startPosition
});

flight = CameraFlightPath.createTween(scene, {
destination : endPosition,
duration : duration,
maximumHeight : maximumHeight
});

for (i = 0; i <= duration; ++i) {
flight.update({ time : i });
expect(camera.positionCartographic.height).toBeLessThan(maximumHeight);
}
});
}, 'WebGL');

0 comments on commit 7f2e768

Please sign in to comment.