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

Make Camera.setView options consistent with Camera.flyTo #3100

Merged
merged 19 commits into from
Oct 21, 2015
10 changes: 6 additions & 4 deletions Apps/CesiumViewer/CesiumViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ define([
var roll = ((splitQuery.length > 5) && (!isNaN(+splitQuery[5]))) ? CesiumMath.toRadians(+splitQuery[5]) : undefined;

viewer.camera.setView({
position: Cartesian3.fromDegrees(longitude, latitude, height),
heading: heading,
pitch: pitch,
roll: roll
destination: Cartesian3.fromDegrees(longitude, latitude, height),
orientation: {
heading: heading,
pitch: pitch,
roll: roll
}
});
}
}
Expand Down
8 changes: 5 additions & 3 deletions Apps/Sandcastle/gallery/Camera.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@
var camera = viewer.camera;
camera.setView({
position : Cesium.Cartesian3.fromDegrees(-75.5847, 40.0397, 1000.0),
heading : -Cesium.Math.PI_OVER_TWO,
pitch : -Cesium.Math.PI_OVER_FOUR,
roll : 0.0
orientation: {
heading : -Cesium.Math.PI_OVER_TWO,
pitch : -Cesium.Math.PI_OVER_FOUR,
roll : 0.0
}
});
}

Expand Down
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ Change Log
* Deprecated `PerspectiveFrustum.getPixelSize`, use `PerspectiveFrustum.getPixelDimensions` instead. It will be removed in 1.17.
* Deprecated `PerspectiveOffCenterFrustum.getPixelSize`, use `PerspectiveOffCenterFrustum.getPixelDimensions` instead. It will be removed in 1.17.
* Deprecated `Scene\HeadingPitchRange`, use `Core\HeadingPitchRange` instead. It will be removed in 1.17.
* Deprecated `Camera.setView`, use `EllipsoidGeometry` or `Entity.ellipsoid` instead. It will be removed in 1.17.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Submit an issue for the deprecated calls.

* The following options to `Camera.setView` have been deprecated and will be removed in 1.17:
* `position`: use `destination` instead.
* `positionCartographic`: convert to a `Cartesian3` and use `destination` instead.
* `heading`, `pitch` and `roll`: use `orientation.heading/pitch/roll` instead.
* Decreased GPU memory usage in `BillboardCollection` and `LabelCollection` by using the WebGL ANGLE_instanced_arrays extension.
* Added CZML examples to Sandcastle. See the new CZML tab.
* Fixed token issue in `ArcGisMapServerImageryProvider`.
* `ImageryLayerFeatureInfo` now has an `imageryLayer` property, indicating the layer that contains the feature.
* Added `BoxOutlineGeometry.fromAxisAlignedBoundingBox` and `BoxGeometry.fromAxisAlignedBoundingBox` functions.
* Changed `Camera.setView` to take the same parameter options as `Camera.flyTo`. `options.destination` takes a rectangle, `options.orientation` works with heading/pitch/roll or direction/up, and `options.endTransform` was added.

### 1.14 - 2015-10-01

Expand Down
315 changes: 180 additions & 135 deletions Source/Scene/Camera.js

Large diffs are not rendered by default.

59 changes: 34 additions & 25 deletions Source/Scene/CameraFlightPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ define([
var time = value.time / duration;

camera.setView({
heading : CesiumMath.lerp(startHeading, heading, time),
pitch : CesiumMath.lerp(startPitch, pitch, time),
roll : CesiumMath.lerp(startRoll, roll, time)
orientation: {
heading : CesiumMath.lerp(startHeading, heading, time),
pitch : CesiumMath.lerp(startPitch, pitch, time),
roll : CesiumMath.lerp(startRoll, roll, time)
}
});

Cartesian2.lerp(start, destination, time, camera.position);
Expand All @@ -139,7 +141,7 @@ define([

var scratchStartCart = new Cartographic();
var scratchEndCart = new Cartographic();
var scratchCurrentPositionCart = new Cartographic();
var scratchCurrentPositionCart = new Cartesian3();

function createUpdate3D(scene, duration, destination, heading, pitch, roll, optionAltitude) {
var camera = scene.camera;
Expand Down Expand Up @@ -171,16 +173,19 @@ define([
var update = function(value) {
var time = value.time / duration;

var position = scratchCurrentPositionCart;
position.longitude = CesiumMath.lerp(startCart.longitude, destCart.longitude, time);
position.latitude = CesiumMath.lerp(startCart.latitude, destCart.latitude, time);
position.height = heightFunction(time);
var position = Cartesian3.fromRadians(
CesiumMath.lerp(startCart.longitude, destCart.longitude, time),
CesiumMath.lerp(startCart.latitude, destCart.latitude, time),
heightFunction(time)
);

camera.setView({
positionCartographic : position,
heading : CesiumMath.lerp(startHeading, heading, time),
pitch : CesiumMath.lerp(startPitch, pitch, time),
roll : CesiumMath.lerp(startRoll, roll, time)
destination : position,
orientation: {
heading : CesiumMath.lerp(startHeading, heading, time),
pitch : CesiumMath.lerp(startPitch, pitch, time),
roll : CesiumMath.lerp(startRoll, roll, time)
}
});
};

Expand All @@ -202,9 +207,11 @@ define([
var time = value.time / duration;

camera.setView({
heading : CesiumMath.lerp(startHeading, heading, time),
pitch : CesiumMath.lerp(startPitch, pitch, time),
roll : CesiumMath.lerp(startRoll, roll, time)
orientation: {
heading : CesiumMath.lerp(startHeading, heading, time),
pitch : CesiumMath.lerp(startPitch, pitch, time),
roll : CesiumMath.lerp(startRoll, roll, time)
}
});

Cartesian2.lerp(start, destination, time, camera.position);
Expand Down Expand Up @@ -263,20 +270,19 @@ define([
throw new DeveloperError('destination is required.');
}
//>>includeEnd('debug');
var mode = scene.mode;

var projection = scene.mapProjection;
var ellipsoid = projection.ellipsoid;

var maximumHeight = options.maximumHeight;
var easingFunction = options.easingFunction;

if (scene.mode === SceneMode.MORPHING) {
if (mode === SceneMode.MORPHING) {
return emptyFlight();
}

var convert = defaultValue(options.convert, true);
var projection = scene.mapProjection;
var ellipsoid = projection.ellipsoid;
var maximumHeight = options.maximumHeight;
var easingFunction = options.easingFunction;

if (convert && scene.mode !== SceneMode.SCENE3D) {
if (convert && mode !== SceneMode.SCENE3D) {
ellipsoid.cartesianToCartographic(destination, scratchCartographic);
destination = projection.project(scratchCartographic, scratchDestination);
}
Expand All @@ -293,7 +299,6 @@ define([
duration = Math.min(duration, 3.0);
}

var mode = scene.mode;
var heading = defaultValue(options.heading, 0.0);
var pitch = scene.mode !== SceneMode.SCENE2D ? defaultValue(options.pitch, -CesiumMath.PI_OVER_TWO) : -CesiumMath.PI_OVER_TWO;
var roll = defaultValue(options.roll, 0.0);
Expand All @@ -310,7 +315,11 @@ define([
empty = empty && Cartesian2.equalsEpsilon(camera.position, destination, CesiumMath.EPSILON6);
empty = empty && CesiumMath.equalsEpsilon(Math.max(frustum.right - frustum.left, frustum.top - frustum.bottom), destination.z, CesiumMath.EPSILON6);

empty = empty || (scene.mode !== SceneMode.SCENE2D && Cartesian3.equalsEpsilon(destination, camera.position, CesiumMath.EPSILON6));
empty = empty || (scene.mode !== SceneMode.SCENE2D &&
Cartesian3.equalsEpsilon(destination, camera.position, CesiumMath.EPSILON10) &&
CesiumMath.equalsEpsilon(CesiumMath.negativePiToPi(heading), CesiumMath.negativePiToPi(camera.heading), CesiumMath.EPSILON10) &&
CesiumMath.equalsEpsilon(CesiumMath.negativePiToPi(pitch), CesiumMath.negativePiToPi(camera.pitch), CesiumMath.EPSILON10) &&
CesiumMath.equalsEpsilon(CesiumMath.negativePiToPi(roll), CesiumMath.negativePiToPi(camera.roll), CesiumMath.EPSILON10));

if (empty) {
return emptyFlight(complete, cancel);
Expand Down
32 changes: 9 additions & 23 deletions Source/Widgets/Geocoder/GeocoderViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,30 +203,16 @@ define([
}
});

var scratchPosition = new Cartesian3();
function updateCamera(viewModel, destination) {
var scene = viewModel._scene;
if (viewModel._flightDuration === 0) {
var isRectangle = defined(destination.west);
if (isRectangle) {
if (scene.scene.mode !== SceneMode.SCENE3D && destination.west > destination.east) {
destination = Rectangle.MAX_VALUE;
}
destination = scene.camera.getRectangleCameraCoordinates(destination, scratchPosition);
}
viewModel._scene.camera.setView({position: destination});
viewModel._complete.raiseEvent();
} else {
viewModel._scene.camera.flyTo({
destination : destination,
complete: function() {
viewModel._complete.raiseEvent();
},
duration : viewModel._flightDuration,
endTransform : Matrix4.IDENTITY,
convert : false
});
}
viewModel._scene.camera.flyTo({
destination : destination,
complete: function() {
viewModel._complete.raiseEvent();
},
duration : viewModel._flightDuration,
endTransform : Matrix4.IDENTITY,
convert : false
});
}

function geocode(viewModel) {
Expand Down
10 changes: 2 additions & 8 deletions Source/Widgets/HomeButton/HomeButtonViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ define([
createCommand) {
"use strict";

var pitchScratch = new Cartesian3();
function viewHome(scene, duration) {
var mode = scene.mode;

Expand All @@ -48,26 +49,19 @@ define([

scene.camera.flyTo({
destination : destination,
orientation : {
heading : 0.0,
pitch : -Math.PI * 0.5,
roll : 0.0
},
duration : duration,
endTransform : Matrix4.IDENTITY
});
} else if (mode === SceneMode.COLUMBUS_VIEW) {
var maxRadii = scene.globe.ellipsoid.maximumRadius;
var position = new Cartesian3(0.0, -1.0, 1.0);
position = Cartesian3.multiplyByScalar(Cartesian3.normalize(position, position), 5.0 * maxRadii, position);
var pitch = -Math.acos(Cartesian3.normalize(position, new Cartesian3()).z);

scene.camera.flyTo({
destination : position,
duration : duration,
orientation : {
heading : 0.0,
pitch : pitch,
pitch : -Math.acos(Cartesian3.normalize(position, pitchScratch).z),
roll : 0.0
},
endTransform : Matrix4.IDENTITY,
Expand Down
38 changes: 23 additions & 15 deletions Specs/Scene/CameraFlightPathSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,26 +202,26 @@ defineSuite([
it('does not create a path to the same point', function() {
var camera = scene.camera;
camera.position = new Cartesian3(7000000.0, 0.0, 0.0);
camera.direction = Cartesian3.negate(Cartesian3.normalize(camera.position, new Cartesian3()), new Cartesian3());
camera.up = Cartesian3.clone(Cartesian3.UNIT_Z);
camera.right = Cartesian3.normalize(Cartesian3.cross(camera.direction, camera.up, new Cartesian3()), new Cartesian3());

var startPosition = Cartesian3.clone(camera.position);
var startDirection = Cartesian3.clone(camera.direction);
var startUp = Cartesian3.clone(camera.up);
var startHeading= camera.heading;
var startPitch = camera.pitch;
var startRoll = camera.roll;

var duration = 3.0;
var flight = CameraFlightPath.createTween(scene, {
destination : startPosition,
direction : startDirection,
up : startUp,
heading : startHeading,
pitch : startPitch,
roll: startRoll,
duration : duration
});

expect(flight.duration).toEqual(0);
expect(camera.position).toEqual(startPosition);
expect(camera.direction).toEqual(startDirection);
expect(camera.up).toEqual(startUp);
expect(camera.heading).toEqual(startHeading);
expect(camera.pitch).toEqual(startPitch);
expect(camera.roll).toEqual(startRoll);
});

it('creates an animation with 0 duration', function() {
Expand Down Expand Up @@ -273,9 +273,13 @@ defineSuite([
var camera = scene.camera;

camera.position = new Cartesian3(0.0, 0.0, 1000.0);
camera.direction = Cartesian3.negate(Cartesian3.UNIT_Z, new Cartesian3());
camera.up = Cartesian3.clone(Cartesian3.UNIT_Y);
camera.right = Cartesian3.cross(camera.direction, camera.up, new Cartesian3());
camera.setView({
orientation: {
heading: 0,
pitch: -CesiumMath.PI_OVER_TWO,
roll: 0
}
});
camera.frustum = createOrthographicFrustum();

var flight = CameraFlightPath.createTween(scene, {
Expand All @@ -290,9 +294,13 @@ defineSuite([
var camera = scene.camera;

camera.position = new Cartesian3(0.0, 0.0, 1000.0);
camera.direction = Cartesian3.negate(Cartesian3.UNIT_Z, new Cartesian3());
camera.up = Cartesian3.clone(Cartesian3.UNIT_Y);
camera.right = Cartesian3.cross(camera.direction, camera.up, new Cartesian3());
camera.setView({
orientation: {
heading: 0,
pitch: -CesiumMath.PI_OVER_TWO,
roll: 0
}
});

var projection = scene.mapProjection;
var endPosition = projection.ellipsoid.cartographicToCartesian(projection.unproject(camera.position));
Expand Down
Loading