diff --git a/Apps/CesiumViewer/CesiumViewer.js b/Apps/CesiumViewer/CesiumViewer.js index 21afd11f3897..199616d58ca3 100644 --- a/Apps/CesiumViewer/CesiumViewer.js +++ b/Apps/CesiumViewer/CesiumViewer.js @@ -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 + } }); } } diff --git a/Apps/Sandcastle/gallery/Camera.html b/Apps/Sandcastle/gallery/Camera.html index 1490fd7396b4..b0531a634416 100644 --- a/Apps/Sandcastle/gallery/Camera.html +++ b/Apps/Sandcastle/gallery/Camera.html @@ -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 + } }); } diff --git a/CHANGES.md b/CHANGES.md index 073a600f972f..a9d885405199 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,12 +16,18 @@ Change Log * 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 `jsonp` use `loadJsonp` instead. It will be removed in 1.17. + * Deprecated `Camera.viewRectangle`, use `Camera.setView({destination: rectangle})` instead. It will be removed in 1.17. + * 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. * The WebGL setting of `failIfMajorPerformanceCaveat` now defaults to `false`, which is the official WebGL default. This improves compatibility with out-of-date drivers and remote desktop sessions. Cesium will run slower in these cases instead of simply failing to load. +* 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 diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index edab1b22d2bd..fc6d69ec5d05 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -5,6 +5,7 @@ define([ '../Core/Cartesian4', '../Core/Cartographic', '../Core/defaultValue', + '../Core/deprecationWarning', '../Core/defined', '../Core/defineProperties', '../Core/DeveloperError', @@ -30,6 +31,7 @@ define([ Cartesian4, Cartographic, defaultValue, + deprecationWarning, defined, defineProperties, DeveloperError, @@ -210,7 +212,7 @@ define([ this._max2Dfrustum = undefined; // set default view - this.viewRectangle(Camera.DEFAULT_VIEW_RECTANGLE, scene.mapProjection.ellipsoid); + rectangleCameraPosition3D(this, Camera.DEFAULT_VIEW_RECTANGLE, this.position, true); var mag = Cartesian3.magnitude(this.position); mag += mag * Camera.DEFAULT_VIEW_FACTOR; @@ -856,17 +858,9 @@ define([ var scratchSetViewMatrix3 = new Matrix3(); var scratchSetViewCartographic = new Cartographic(); - function setView3D(camera, cartesian, cartographic, heading, pitch, roll, ellipsoid) { - if (!defined(cartesian)) { - if (defined(cartographic)) { - cartesian = ellipsoid.cartographicToCartesian(cartographic, scratchSetViewCartesian); - } else { - cartesian = Cartesian3.clone(camera.positionWC, scratchSetViewCartesian); - } - } - + function setView3D(camera, position, heading, pitch, roll) { var currentTransform = Matrix4.clone(camera.transform, scratchSetViewTransform1); - var localTransform = Transforms.eastNorthUpToFixedFrame(cartesian, ellipsoid, scratchSetViewTransform2); + var localTransform = Transforms.eastNorthUpToFixedFrame(position, camera._projection.ellipsoid, scratchSetViewTransform2); camera._setTransform(localTransform); Cartesian3.clone(Cartesian3.ZERO, camera.position); @@ -881,17 +875,17 @@ define([ camera._setTransform(currentTransform); } - function setViewCV(camera, cartesian, cartographic, heading, pitch, roll, ellipsoid, projection) { + function setViewCV(camera, position, heading, pitch, roll, convert) { var currentTransform = Matrix4.clone(camera.transform, scratchSetViewTransform1); camera._setTransform(Matrix4.IDENTITY); - if (defined(cartesian) && !Cartesian3.equals(cartesian, camera.positionWC)) { - cartographic = ellipsoid.cartesianToCartographic(cartesian); - } - - if (defined(cartographic)) { - cartesian = projection.project(cartographic, scratchSetViewCartesian); - Cartesian3.clone(cartesian, camera.position); + if (!Cartesian3.equals(position, camera.positionWC)) { + if (convert) { + var projection = camera._projection; + var cartographic = projection.ellipsoid.cartesianToCartographic(position, scratchSetViewCartographic); + position = projection.project(cartographic, scratchSetViewCartesian); + } + Cartesian3.clone(position, camera.position); } var rotQuat = Quaternion.fromHeadingPitchRoll(heading - CesiumMath.PI_OVER_TWO, pitch, roll, scratchSetViewQuaternion); @@ -904,22 +898,23 @@ define([ camera._setTransform(currentTransform); } - function setView2D(camera, cartesian, cartographic, heading, pitch, roll, ellipsoid, projection) { - pitch = -CesiumMath.PI_OVER_TWO; - roll = 0.0; + function setView2D(camera, position, heading, convert) { + var pitch = -CesiumMath.PI_OVER_TWO; + var roll = 0.0; var currentTransform = Matrix4.clone(camera.transform, scratchSetViewTransform1); camera._setTransform(Matrix4.IDENTITY); - if (defined(cartesian) && !Cartesian3.equals(cartesian, camera.positionWC)) { - cartographic = ellipsoid.cartesianToCartographic(cartesian); - } + if (!Cartesian3.equals(position, camera.positionWC)) { + if (convert) { + var projection = camera._projection; + var cartographic = projection.ellipsoid.cartesianToCartographic(position, scratchSetViewCartographic); + position = projection.project(cartographic, scratchSetViewCartesian); + } - if (defined(cartographic)) { - cartesian = projection.project(cartographic, scratchSetViewCartesian); - Cartesian2.clone(cartesian, camera.position); + Cartesian2.clone(position, camera.position); - var newLeft = -cartographic.height * 0.5; + var newLeft = -position.z * 0.5; var newRight = -newLeft; var frustum = camera.frustum; @@ -941,64 +936,161 @@ define([ camera._setTransform(currentTransform); } + var scratchToHPRDirection = new Cartesian3(); + var scratchToHPRUp = new Cartesian3(); + var scratchToHPRRight = new Cartesian3(); + + function directionUpToHeadingPitchRoll(camera, position, orientation, result) { + var direction = Cartesian3.clone(orientation.direction, scratchToHPRDirection); + var up = Cartesian3.clone(orientation.up, scratchToHPRUp); + + if (camera._scene.mode === SceneMode.SCENE3D) { + var ellipsoid = camera._projection.ellipsoid; + var transform = Transforms.eastNorthUpToFixedFrame(position, ellipsoid, scratchHPRMatrix1); + var invTransform = Matrix4.inverseTransformation(transform, scratchHPRMatrix2); + + Matrix4.multiplyByPointAsVector(invTransform, direction, direction); + Matrix4.multiplyByPointAsVector(invTransform, up, up); + } + + var right = Cartesian3.cross(direction, up, scratchToHPRRight); + + result.heading = getHeading(direction, up); + result.pitch = getPitch(direction); + result.roll = getRoll(direction, up, right); + + return result; + } + + var scratchSetViewOptions = { + destination : undefined, + orientation : { + direction : undefined, + up : undefined, + heading : undefined, + pitch : undefined, + roll : undefined + }, + endTransform : undefined + }; + /** - * Sets the camera position and orientation with heading, pitch and roll angles. - * - * The position can be given as either a cartesian or a cartographic. If both are given, - * then the cartesian will be used. If neither is given, then the current camera position - * will be used. + * Sets the camera position, orientation and transform. * * @param {Object} options Object with the following properties: - * @param {Cartesian3} [options.position] The cartesian position of the camera. - * @param {Cartographic} [options.positionCartographic] The cartographic position of the camera. - * @param {Number} [options.heading] The heading in radians or the current heading will be used if undefined. - * @param {Number} [options.pitch] The pitch in radians or the current pitch will be used if undefined. - * @param {Number} [options.roll] The roll in radians or the current roll will be used if undefined. + * @param {Cartesian3|Rectangle} options.destination The final position of the camera in WGS84 (world) coordinates or a rectangle that would be visible from a top-down view. + * @param {Object} [options.orientation] An object that contains either direction and up properties or heading, pith and roll properties. By default, the direction will point + * towards the center of the frame in 3D and in the negative z direction in Columbus view or 2D. The up direction will point towards local north in 3D and in the positive + * y direction in Columbus view or 2D. + * @param {Matrix4} [options.endTransform] Transform matrix representing the reference frame of the camera. * * @example - * // 1. Set view with heading, pitch and roll - * camera.setView({ - * position : cartesianPosition, - * heading : Cesium.Math.toRadians(90.0), // east, default value is 0.0 (north) - * pitch : Cesium.Math.toRadians(-90), // default value (looking down) - * roll : 0.0 // default value + * // 1. Set position with a top-down view + * viewer.camera.setView({ + * destination : Cesium.Cartesian3.fromDegrees(-117.16, 32.71, 15000.0) * }); * - * // 2. Set default top-down view with a cartographic position - * camera.setView({ - * positionCartographic : cartographic + * // 2 Set view with heading, pitch and roll + * viewer.camera.setView({ + * destination : cartesianPosition, + * orientation: { + * heading : Cesium.Math.toRadians(90.0), // east, default value is 0.0 (north) + * pitch : Cesium.Math.toRadians(-90), // default value (looking down) + * roll : 0.0 // default value + * } * }); * * // 3. Change heading, pitch and roll with the camera position remaining the same. - * camera.setView({ - * heading : Cesium.Math.toRadians(90.0), // east, default value is 0.0 (north) - * pitch : Cesium.Math.toRadians(-90), // default value (looking down) - * roll : 0.0 // default value + * viewer.camera.setView({ + * orientation: { + * heading : Cesium.Math.toRadians(90.0), // east, default value is 0.0 (north) + * pitch : Cesium.Math.toRadians(-90), // default value (looking down) + * roll : 0.0 // default value + * } + * }); + * + * + * // 4. View rectangle with a top-down view + * viewer.camera.setView({ + * destination : Cesium.Rectangle.fromDegrees(west, south, east, north) + * }); + * + * // 5. Setposition with an orientation using unit vectors. + * viewer.camera.setView({ + * destination : Cesium.Cartesian3.fromDegrees(-122.19, 46.25, 5000.0), + * orientation : { + * direction : new Cesium.Cartesian3(-0.04231243104240401, -0.20123236049443421, -0.97862924300734), + * up : new Cesium.Cartesian3(-0.47934589305293746, -0.8553216253114552, 0.1966022179118339) + * } * }); */ Camera.prototype.setView = function(options) { - if (this._mode === SceneMode.MORPHING) { + options = defaultValue(options, defaultValue.EMPTY_OBJECT); + var orientation = defaultValue(options.orientation, defaultValue.EMPTY_OBJECT); + + var newOptions = scratchSetViewOptions; + var newOrientation = newOptions.orientation; + + if (defined(options.heading) || defined(options.pitch) || defined(options.roll)) { + deprecationWarning('Camera.setView options', 'options.heading/pitch/roll has been moved to options.orientation.heading/pitch/roll.'); + newOrientation.heading = defaultValue(options.heading, this.heading); + newOrientation.pitch = defaultValue(options.pitch, this.pitch); + newOrientation.roll = defaultValue(options.roll, this.roll); + } else { + newOrientation.heading = orientation.heading; + newOrientation.pitch = orientation.pitch; + newOrientation.roll = orientation.roll; + newOrientation.direction = orientation.direction; + newOrientation.up = orientation.up; + } + + if (defined(options.position)) { + deprecationWarning('Camera.setView options', 'options.position has been renamed to options.destination.'); + options.destination = options.position; + } else if (defined(options.positionCartographic)) { + deprecationWarning('Camera.setView options', 'options.positionCartographic has been deprecated. Convert to a Cartesian3 and use options.position instead.'); + var projection = this._projection; + var ellipsoid = projection.ellipsoid; + options.destination = ellipsoid.cartographicToCartesian(options.positionCartographic, scratchSetViewCartesian); + } else { + newOptions.destination = options.destination; + } + + newOptions.endTransform = options.endTransform; + + options = newOptions; + orientation = newOrientation; + + var mode = this._mode; + if (mode === SceneMode.MORPHING) { return; } - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + if (defined(options.endTransform)) { + this._setTransform(options.endTransform); + } - var heading = defaultValue(options.heading, this.heading); - var pitch = defaultValue(options.pitch, this.pitch); - var roll = defaultValue(options.roll, this.roll); + var convert = true; + var destination = defaultValue(options.destination, Cartesian3.clone(this.positionWC, scratchSetViewCartesian)); + if (defined(destination) && defined(destination.west)) { + destination = this.getRectangleCameraCoordinates(destination, scratchSetViewCartesian); + convert = false; + } - var cartesian = options.position; - var cartographic = options.positionCartographic; + if (defined(orientation.direction)) { + orientation = directionUpToHeadingPitchRoll(this, destination, orientation, scratchSetViewOptions.orientation); + } - var projection = this._projection; - var ellipsoid = projection.ellipsoid; + var heading = defaultValue(orientation.heading, 0.0); + var pitch = defaultValue(orientation.pitch, -CesiumMath.PI_OVER_TWO); + var roll = defaultValue(orientation.roll, 0.0); - if (this._mode === SceneMode.SCENE3D) { - setView3D(this, cartesian, cartographic, heading, pitch, roll, ellipsoid); - } else if (this._mode === SceneMode.SCENE2D) { - setView2D(this, cartesian, cartographic, heading, pitch, roll, ellipsoid, projection); + if (mode === SceneMode.SCENE3D) { + setView3D(this, destination, heading, pitch, roll); + } else if (mode === SceneMode.SCENE2D) { + setView2D(this, destination, heading, convert); } else { - setViewCV(this, cartesian, cartographic, heading, pitch, roll, ellipsoid, projection); + setViewCV(this, destination, heading, pitch, roll, convert); } }; @@ -1747,15 +1839,14 @@ define([ var defaultRF = {direction: new Cartesian3(), right: new Cartesian3(), up: new Cartesian3()}; var viewRectangle3DEllipsoidGeodesic; - function rectangleCameraPosition3D (camera, rectangle, ellipsoid, result, positionOnly) { - if (!defined(result)) { - result = new Cartesian3(); - } + function computeD(direction, upOrRight, corner, tanThetaOrPhi) { + var opposite = Math.abs(Cartesian3.dot(upOrRight, corner)); + return opposite / tanThetaOrPhi - Cartesian3.dot(direction, corner); + } - var cameraRF = camera; - if (positionOnly) { - cameraRF = defaultRF; - } + function rectangleCameraPosition3D (camera, rectangle, result, updateCamera) { + var ellipsoid = camera._projection.ellipsoid; + var cameraRF = updateCamera ? camera : defaultRF; var north = rectangle.north; var south = rectangle.south; @@ -1839,11 +1930,6 @@ define([ var tanPhi = Math.tan(camera.frustum.fovy * 0.5); var tanTheta = camera.frustum.aspectRatio * tanPhi; - function computeD(direction, upOrRight, corner, tanThetaOrPhi) { - var opposite = Math.abs(Cartesian3.dot(upOrRight, corner)); - return opposite / tanThetaOrPhi - Cartesian3.dot(direction, corner); - } - var d = Math.max( computeD(direction, up, northWest, tanPhi), computeD(direction, up, southEast, tanPhi), @@ -1881,62 +1967,52 @@ define([ var viewRectangleCVCartographic = new Cartographic(); var viewRectangleCVNorthEast = new Cartesian3(); var viewRectangleCVSouthWest = new Cartesian3(); - function rectangleCameraPositionColumbusView(camera, rectangle, projection, result, positionOnly) { - var north = rectangle.north; - var south = rectangle.south; - var east = rectangle.east; - var west = rectangle.west; + function rectangleCameraPositionColumbusView(camera, rectangle, result) { + var projection = camera._projection; + if (rectangle.west > rectangle.east) { + rectangle = Rectangle.MAX_VALUE; + } var transform = camera._actualTransform; var invTransform = camera._actualInvTransform; var cart = viewRectangleCVCartographic; - cart.longitude = east; - cart.latitude = north; + cart.longitude = rectangle.east; + cart.latitude = rectangle.north; var northEast = projection.project(cart, viewRectangleCVNorthEast); Matrix4.multiplyByPoint(transform, northEast, northEast); Matrix4.multiplyByPoint(invTransform, northEast, northEast); - cart.longitude = west; - cart.latitude = south; + cart.longitude = rectangle.west; + cart.latitude = rectangle.south; var southWest = projection.project(cart, viewRectangleCVSouthWest); Matrix4.multiplyByPoint(transform, southWest, southWest); Matrix4.multiplyByPoint(invTransform, southWest, southWest); var tanPhi = Math.tan(camera.frustum.fovy * 0.5); var tanTheta = camera.frustum.aspectRatio * tanPhi; - if (!defined(result)) { - result = new Cartesian3(); - } result.x = (northEast.x - southWest.x) * 0.5 + southWest.x; result.y = (northEast.y - southWest.y) * 0.5 + southWest.y; result.z = Math.max((northEast.x - southWest.x) / tanTheta, (northEast.y - southWest.y) / tanPhi) * 0.5; - if (!positionOnly) { - var direction = Cartesian3.clone(Cartesian3.UNIT_Z, camera.direction); - Cartesian3.negate(direction, direction); - Cartesian3.clone(Cartesian3.UNIT_X, camera.right); - Cartesian3.clone(Cartesian3.UNIT_Y, camera.up); - } - return result; } var viewRectangle2DCartographic = new Cartographic(); var viewRectangle2DNorthEast = new Cartesian3(); var viewRectangle2DSouthWest = new Cartesian3(); - function rectangleCameraPosition2D (camera, rectangle, projection, result, positionOnly) { - var north = rectangle.north; - var south = rectangle.south; - var east = rectangle.east; - var west = rectangle.west; + function rectangleCameraPosition2D (camera, rectangle, result) { + var projection = camera._projection; + if (rectangle.west > rectangle.east) { + rectangle = Rectangle.MAX_VALUE; + } var cart = viewRectangle2DCartographic; - cart.longitude = east; - cart.latitude = north; + cart.longitude = rectangle.east; + cart.latitude = rectangle.north; var northEast = projection.project(cart, viewRectangle2DNorthEast); - cart.longitude = west; - cart.latitude = south; + cart.longitude = rectangle.west; + cart.latitude = rectangle.south; var southWest = projection.project(cart, viewRectangle2DSouthWest); var width = Math.abs(northEast.x - southWest.x) * 0.5; @@ -1955,31 +2031,16 @@ define([ height = Math.max(2.0 * right, 2.0 * top); - if (!defined(result)) { - result = new Cartesian3(); - } result.x = (northEast.x - southWest.x) * 0.5 + southWest.x; result.y = (northEast.y - southWest.y) * 0.5 + southWest.y; - if (positionOnly) { - cart = projection.unproject(result, cart); - cart.height = height; - result = projection.project(cart, result); - } else { - var frustum = camera.frustum; - frustum.right = right; - frustum.left = -right; - frustum.top = top; - frustum.bottom = -top; - - var direction = Cartesian3.clone(Cartesian3.UNIT_Z, camera.direction); - Cartesian3.negate(direction, direction); - Cartesian3.clone(Cartesian3.UNIT_X, camera.right); - Cartesian3.clone(Cartesian3.UNIT_Y, camera.up); - } + cart = projection.unproject(result, cart); + cart.height = height; + result = projection.project(cart, result); return result; } + /** * Get the camera position needed to view an rectangle on an ellipsoid or map * @@ -1993,13 +2054,18 @@ define([ throw new DeveloperError('rectangle is required'); } //>>includeEnd('debug'); + var mode = this._mode; - if (this._mode === SceneMode.SCENE3D) { - return rectangleCameraPosition3D(this, rectangle, this._projection.ellipsoid, result, true); - } else if (this._mode === SceneMode.COLUMBUS_VIEW) { - return rectangleCameraPositionColumbusView(this, rectangle, this._projection, result, true); - } else if (this._mode === SceneMode.SCENE2D) { - return rectangleCameraPosition2D(this, rectangle, this._projection, result, true); + if (!defined(result)) { + result = new Cartesian3(); + } + + if (mode === SceneMode.SCENE3D) { + return rectangleCameraPosition3D(this, rectangle, result); + } else if (mode === SceneMode.COLUMBUS_VIEW) { + return rectangleCameraPositionColumbusView(this, rectangle, result); + } else if (mode === SceneMode.SCENE2D) { + return rectangleCameraPosition2D(this, rectangle, result); } return undefined; @@ -2009,27 +2075,21 @@ define([ * View a rectangle on an ellipsoid or map. * * @param {Rectangle} rectangle The rectangle to view. - * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid to view. + * + * @deprecated */ - Camera.prototype.viewRectangle = function(rectangle, ellipsoid) { + Camera.prototype.viewRectangle = function(rectangle) { + deprecationWarning('Camera.viewRectangle', 'Camera.viewRectangle has been deprecated. Use Camera.setView({ destination:rectangle }) instead'); + //>>includeStart('debug', pragmas.debug); if (!defined(rectangle)) { throw new DeveloperError('rectangle is required.'); } //>>includeEnd('debug'); - ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84); - if (this._mode !== SceneMode.SCENE3D && rectangle.west > rectangle.east) { - rectangle = Rectangle.MAX_VALUE; - } - - if (this._mode === SceneMode.SCENE3D) { - rectangleCameraPosition3D(this, rectangle, ellipsoid, this.position); - } else if (this._mode === SceneMode.COLUMBUS_VIEW) { - rectangleCameraPositionColumbusView(this, rectangle, this._projection, this.position); - } else if (this._mode === SceneMode.SCENE2D) { - rectangleCameraPosition2D(this, rectangle, this._projection, this.position); - } + this.setView({ + destination: rectangle + }); }; var pickEllipsoid3DRay = new Ray(); @@ -2368,10 +2428,6 @@ define([ easingFunction : undefined }; - var scratchFlyDirection = new Cartesian3(); - var scratchFlyUp = new Cartesian3(); - var scratchFlyRight = new Cartesian3(); - /** * Flies the camera from its current position to a new position. * @@ -2423,7 +2479,6 @@ define([ */ Camera.prototype.flyTo = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); - var destination = options.destination; //>>includeStart('debug', pragmas.debug); if (!defined(destination)) { @@ -2431,49 +2486,39 @@ define([ } //>>includeEnd('debug'); - var scene = this._scene; - - var isRectangle = defined(destination.west); - if (isRectangle) { - if (scene.mode !== SceneMode.SCENE3D && destination.west > destination.east) { - destination = Rectangle.MAX_VALUE; - } - destination = scene.camera.getRectangleCameraCoordinates(destination, scratchFlyToDestination); + var mode = this._mode; + if (mode === SceneMode.MORPHING) { + return; } - var heading; - var pitch; - var roll; - var orientation = defaultValue(options.orientation, defaultValue.EMPTY_OBJECT); - if (defined(orientation.heading)) { - heading = orientation.heading; - pitch = orientation.pitch; - roll = orientation.roll; - } else if (defined(orientation.direction)) { - var direction = Cartesian3.clone(orientation.direction, scratchFlyDirection); - var up = Cartesian3.clone(orientation.up, scratchFlyUp); - - if (scene.mode === SceneMode.SCENE3D) { - var ellipsoid = this._projection.ellipsoid; - var transform = Transforms.eastNorthUpToFixedFrame(destination, ellipsoid, scratchHPRMatrix1); - var invTransform = Matrix4.inverseTransformation(transform, scratchHPRMatrix2); - - Matrix4.multiplyByPointAsVector(invTransform, direction, direction); - Matrix4.multiplyByPointAsVector(invTransform, up, up); + if (defined(orientation.direction)) { + orientation = directionUpToHeadingPitchRoll(this, destination, orientation, scratchSetViewOptions.orientation); + } + + if (defined(options.duration) && options.duration <= 0.0) { + var setViewOptions = scratchSetViewOptions; + setViewOptions.destination = options.destination; + setViewOptions.orientation.heading = orientation.heading; + setViewOptions.orientation.pitch = orientation.pitch; + setViewOptions.orientation.roll = orientation.roll; + setViewOptions.endTransform = options.endTransform; + this.setView(setViewOptions); + if (typeof options.complete === 'function'){ + options.complete(); } + return; + } - var right = Cartesian3.cross(direction, up, scratchFlyRight); - - heading = getHeading(direction, up); - pitch = getPitch(direction); - roll = getRoll(direction, up, right); + var isRectangle = defined(destination.west); + if (isRectangle) { + destination = this.getRectangleCameraCoordinates(destination, scratchFlyToDestination); } newOptions.destination = destination; - newOptions.heading = heading; - newOptions.pitch = pitch; - newOptions.roll = roll; + newOptions.heading = orientation.heading; + newOptions.pitch = orientation.pitch; + newOptions.roll = orientation.roll; newOptions.duration = options.duration; newOptions.complete = options.complete; newOptions.cancel = options.cancel; @@ -2482,6 +2527,7 @@ define([ newOptions.maximumHeight = options.maximumHeight; newOptions.easingFunction = options.easingFunction; + var scene = this._scene; scene.tweens.add(CameraFlightPath.createTween(scene, newOptions)); }; diff --git a/Source/Scene/CameraFlightPath.js b/Source/Scene/CameraFlightPath.js index 912747fb4895..82928c4aa720 100644 --- a/Source/Scene/CameraFlightPath.js +++ b/Source/Scene/CameraFlightPath.js @@ -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); @@ -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; @@ -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) + } }); }; @@ -191,9 +196,7 @@ define([ var camera = scene.camera; var start = Cartesian3.clone(camera.position, scratchStart); - var startPitch = camera.pitch; var startHeading = adjustAngleForLERP(camera.heading, heading); - var startRoll = adjustAngleForLERP(camera.roll, roll); var startHeight = camera.frustum.right - camera.frustum.left; var heightFunction = createHeightFunction(camera, destination, startHeight, destination.z, optionAltitude); @@ -202,9 +205,9 @@ 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) + } }); Cartesian2.lerp(start, destination, time, camera.position); @@ -263,20 +266,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); } @@ -293,9 +295,8 @@ 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 pitch = defaultValue(options.pitch, -CesiumMath.PI_OVER_TWO); var roll = defaultValue(options.roll, 0.0); var controller = scene.screenSpaceCameraController; @@ -310,7 +311,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); diff --git a/Source/Widgets/Geocoder/GeocoderViewModel.js b/Source/Widgets/Geocoder/GeocoderViewModel.js index 3552b986fb69..2a377bac67e8 100644 --- a/Source/Widgets/Geocoder/GeocoderViewModel.js +++ b/Source/Widgets/Geocoder/GeocoderViewModel.js @@ -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) { diff --git a/Source/Widgets/HomeButton/HomeButtonViewModel.js b/Source/Widgets/HomeButton/HomeButtonViewModel.js index 657df1065c35..920d3d5ab4b9 100644 --- a/Source/Widgets/HomeButton/HomeButtonViewModel.js +++ b/Source/Widgets/HomeButton/HomeButtonViewModel.js @@ -25,6 +25,7 @@ define([ createCommand) { "use strict"; + var pitchScratch = new Cartesian3(); function viewHome(scene, duration) { var mode = scene.mode; @@ -48,11 +49,6 @@ define([ scene.camera.flyTo({ destination : destination, - orientation : { - heading : 0.0, - pitch : -Math.PI * 0.5, - roll : 0.0 - }, duration : duration, endTransform : Matrix4.IDENTITY }); @@ -60,14 +56,12 @@ define([ 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, diff --git a/Specs/Scene/CameraFlightPathSpec.js b/Specs/Scene/CameraFlightPathSpec.js index dac21de78b7a..fbddbb971a13 100644 --- a/Specs/Scene/CameraFlightPathSpec.js +++ b/Specs/Scene/CameraFlightPathSpec.js @@ -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() { @@ -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, { @@ -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)); diff --git a/Specs/Scene/CameraSpec.js b/Specs/Scene/CameraSpec.js index e9aed4eec5cf..1203f3ad61be 100644 --- a/Specs/Scene/CameraSpec.js +++ b/Specs/Scene/CameraSpec.js @@ -203,7 +203,9 @@ defineSuite([ var newHeading = CesiumMath.toRadians(45.0); camera.setView({ - heading : newHeading + orientation: { + heading : newHeading + } }); expect(camera.positionCartographic).toEqual(positionCartographic); @@ -224,7 +226,9 @@ defineSuite([ var newHeading = CesiumMath.toRadians(45.0); camera.setView({ - heading : newHeading + orientation: { + heading : newHeading + } }); expect(camera.positionCartographic).toEqual(positionCartographic); @@ -243,7 +247,9 @@ defineSuite([ var heading = camera.heading; var newHeading = CesiumMath.toRadians(45.0); camera.setView({ - heading : newHeading + orientation: { + heading : newHeading + } }); expect(camera.heading).not.toEqual(heading); @@ -262,13 +268,21 @@ defineSuite([ var positionCartographic = camera.positionCartographic; - camera.setView({ heading : CesiumMath.PI }); + camera.setView({ + orientation: { + heading : CesiumMath.PI + } + }); expect(camera.positionCartographic).toEqual(positionCartographic); expect(camera.heading).toEqualEpsilon(CesiumMath.PI, CesiumMath.EPSILON8); expect(camera.up.z).toBeLessThan(0.0); - camera.setView({ heading : CesiumMath.TWO_PI }); + camera.setView({ + orientation: { + heading : CesiumMath.TWO_PI + } + }); expect(camera.positionCartographic).toEqual(positionCartographic); expect(camera.heading).toEqualEpsilon(CesiumMath.TWO_PI, CesiumMath.EPSILON8); @@ -339,7 +353,9 @@ defineSuite([ var newPitch = CesiumMath.toRadians(45.0); camera.setView({ - pitch : newPitch + orientation: { + pitch : newPitch + } }); expect(camera.positionCartographic).toEqual(positionCartographic); @@ -360,7 +376,9 @@ defineSuite([ var newPitch = CesiumMath.toRadians(45.0); camera.setView({ - pitch : newPitch + orientation: { + pitch : newPitch + } }); expect(camera.positionCartographic).toEqual(positionCartographic); @@ -431,10 +449,12 @@ defineSuite([ it('get roll returns correct value past 90 degrees', function() { var roll = CesiumMath.toRadians(110.0); camera.setView({ - position : Cartesian3.fromDegrees(-72.0, 40.0, 20.0), - heading : 0.0, - pitch : 0.0, - roll : roll + destination : Cartesian3.fromDegrees(-72.0, 40.0, 20.0), + orientation: { + heading : 0.0, + pitch : 0.0, + roll : roll + } }); expect(camera.roll).toEqualEpsilon(roll, CesiumMath.EPSILON14); @@ -453,7 +473,11 @@ defineSuite([ var newRoll = CesiumMath.PI_OVER_FOUR; camera.setView({ - roll : newRoll + orientation: { + pitch: camera.pitch, + roll : newRoll, + heading: camera.heading + } }); expect(camera.positionCartographic).toEqual(positionCartographic); @@ -470,11 +494,15 @@ defineSuite([ camera.right = Cartesian3.cross(camera.direction, camera.up, new Cartesian3()); var roll = camera.roll; - var positionCartographic = camera.positionCartographic; + var positionCartographic = Cartographic.clone(camera.positionCartographic); var newRoll = CesiumMath.PI_OVER_FOUR; camera.setView({ - roll : newRoll + orientation: { + pitch: camera.pitch, + roll : newRoll, + heading: camera.heading + } }); expect(camera.positionCartographic).toEqual(positionCartographic); @@ -488,40 +516,6 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('setView with cartographic in 2D', function() { - var ellipsoid = Ellipsoid.WGS84; - var projection = new GeographicProjection(ellipsoid); - var maxRadii = ellipsoid.maximumRadius; - - camera._mode = SceneMode.SCENE2D; - camera._projection = projection; - - var frustum = new OrthographicFrustum(); - frustum.right = maxRadii * Math.PI; - frustum.left = -frustum.right; - frustum.top = frustum.right * (scene.drawingBufferHeight / scene.drawingBufferWidth); - frustum.bottom = -frustum.top; - frustum.near = 0.01 * maxRadii; - frustum.far = 60.0 * maxRadii; - camera.frustum = frustum; - - var ratio = frustum.top / frustum.right; - var cart = Cartographic.fromDegrees(-75.0, 42.0, 100.0); - camera.setView({ - heading : 0.0, - pitch : -CesiumMath.PI_OVER_TWO, - roll : 0.0, - positionCartographic : cart - }); - - expect(Cartesian2.fromCartesian3(camera.position, new Cartesian2())).toEqualEpsilon(Cartesian2.fromCartesian3(projection.project(cart), new Cartesian2()), CesiumMath.EPSILON11); - expect(camera.direction).toEqualEpsilon(Cartesian3.negate(Cartesian3.UNIT_Z, new Cartesian3()), CesiumMath.EPSILON6); - expect(camera.up).toEqualEpsilon(Cartesian3.UNIT_Y, CesiumMath.EPSILON6); - expect(camera.right).toEqualEpsilon(Cartesian3.UNIT_X, CesiumMath.EPSILON6); - expect(frustum.right - frustum.left).toEqualEpsilon(cart.height, CesiumMath.EPSILON6); - expect(frustum.top / frustum.right).toEqual(ratio); - }); - it('setView with cartesian in 2D', function() { var ellipsoid = Ellipsoid.WGS84; var projection = new GeographicProjection(ellipsoid); @@ -542,10 +536,7 @@ defineSuite([ var ratio = frustum.top / frustum.right; var cartesian = Cartesian3.fromDegrees(-75.0, 42.0, 100.0); camera.setView({ - heading : 0.0, - pitch : -CesiumMath.PI_OVER_TWO, - roll : 0.0, - position : cartesian + destination : cartesian }); var cart = ellipsoid.cartesianToCartographic(cartesian); @@ -557,27 +548,6 @@ defineSuite([ expect(frustum.top / frustum.right).toEqual(ratio); }); - it('setView with cartographic in Columbus View', function() { - var ellipsoid = Ellipsoid.WGS84; - var projection = new GeographicProjection(ellipsoid); - - camera._mode = SceneMode.COLUMBUS_VIEW; - camera._projection = projection; - - var cart = Cartographic.fromDegrees(-75.0, 42.0, 100.0); - camera.setView({ - heading : 0.0, - pitch : -CesiumMath.PI_OVER_TWO, - roll : 0.0, - positionCartographic : cart - }); - - expect(camera.position).toEqualEpsilon(projection.project(cart), CesiumMath.EPSILON11); - expect(camera.direction).toEqualEpsilon(Cartesian3.negate(Cartesian3.UNIT_Z, new Cartesian3()), CesiumMath.EPSILON6); - expect(camera.up).toEqualEpsilon(Cartesian3.UNIT_Y, CesiumMath.EPSILON6); - expect(camera.right).toEqualEpsilon(Cartesian3.UNIT_X, CesiumMath.EPSILON6); - }); - it('setView with cartesian in Columbus View', function() { var ellipsoid = Ellipsoid.WGS84; var projection = new GeographicProjection(ellipsoid); @@ -587,10 +557,7 @@ defineSuite([ var cartesian = Cartesian3.fromDegrees(-75.0, 42.0, 100.0); camera.setView({ - heading : 0.0, - pitch : -CesiumMath.PI_OVER_TWO, - roll : 0.0, - position : cartesian + destination : cartesian }); var cart = ellipsoid.cartesianToCartographic(cartesian); @@ -600,27 +567,6 @@ defineSuite([ expect(camera.right).toEqualEpsilon(Cartesian3.UNIT_X, CesiumMath.EPSILON6); }); - it('setView with cartographic in 3D', function() { - var ellipsoid = Ellipsoid.WGS84; - var projection = new GeographicProjection(ellipsoid); - - camera._mode = SceneMode.SCENE3D; - camera._projection = projection; - - var cart = Cartographic.fromDegrees(-75.0, 0.0, 100.0); - camera.setView({ - heading : 0.0, - pitch : -CesiumMath.PI_OVER_TWO, - roll : 0.0, - positionCartographic : cart - }); - - expect(camera.position).toEqualEpsilon(ellipsoid.cartographicToCartesian(cart), CesiumMath.EPSILON6); - expect(camera.direction).toEqualEpsilon(Cartesian3.normalize(Cartesian3.negate(camera.position, new Cartesian3()), new Cartesian3()), CesiumMath.EPSILON6); - expect(camera.up).toEqualEpsilon(Cartesian3.UNIT_Z, CesiumMath.EPSILON6); - expect(camera.right).toEqualEpsilon(Cartesian3.cross(camera.direction, camera.up, new Cartesian3()), CesiumMath.EPSILON6); - }); - it('setView with cartesian in 3D', function() { var ellipsoid = Ellipsoid.WGS84; var projection = new GeographicProjection(ellipsoid); @@ -630,10 +576,7 @@ defineSuite([ var cartesian = Cartesian3.fromDegrees(-75.0, 0.0, 100.0); camera.setView({ - heading : 0.0, - pitch : -CesiumMath.PI_OVER_TWO, - roll : 0.0, - position : cartesian + destination : cartesian }); expect(camera.positionCartographic).toEqualEpsilon(ellipsoid.cartesianToCartographic(cartesian), CesiumMath.EPSILON6); @@ -649,10 +592,12 @@ defineSuite([ var roll = CesiumMath.toRadians(45.0); camera.setView({ - position : position, - heading : heading, - pitch : pitch, - roll : roll + destination : position, + orientation: { + heading : heading, + pitch : pitch, + roll : roll + } }); expect(camera.position).toEqualEpsilon(position, CesiumMath.EPSILON6); @@ -668,10 +613,12 @@ defineSuite([ var roll = CesiumMath.toRadians(45.0); camera.setView({ - position : position, - heading : heading, - pitch : pitch, - roll : roll + destination : position, + orientation: { + heading : heading, + pitch : pitch, + roll : roll + } }); expect(camera.position).toEqualEpsilon(position, CesiumMath.EPSILON6); @@ -681,7 +628,13 @@ defineSuite([ heading = CesiumMath.toRadians(200.0); - camera.setView({heading : heading}); + camera.setView({ + orientation: { + pitch: camera.pitch, + roll : camera.roll, + heading : heading + } + }); expect(camera.position).toEqualEpsilon(position, CesiumMath.EPSILON6); expect(camera.heading).toEqualEpsilon(heading, CesiumMath.EPSILON6); @@ -696,10 +649,12 @@ defineSuite([ var roll = CesiumMath.toRadians(45.0); camera.setView({ - position : position, - heading : heading, - pitch : pitch, - roll : roll + destination : position, + orientation: { + heading : heading, + pitch : pitch, + roll : roll + } }); expect(camera.position).toEqualEpsilon(position, CesiumMath.EPSILON6); @@ -709,7 +664,13 @@ defineSuite([ pitch = CesiumMath.toRadians(-50.0); - camera.setView({pitch : pitch}); + camera.setView({ + orientation: { + pitch : pitch, + roll : camera.roll, + heading: camera.heading + } + }); expect(camera.position).toEqualEpsilon(position, CesiumMath.EPSILON6); expect(camera.heading).toEqualEpsilon(heading, CesiumMath.EPSILON6); @@ -724,10 +685,12 @@ defineSuite([ var roll = CesiumMath.toRadians(45.0); camera.setView({ - position : position, - heading : heading, - pitch : pitch, - roll : roll + destination : position, + orientation: { + heading : heading, + pitch : pitch, + roll : roll + } }); expect(camera.position).toEqualEpsilon(position, CesiumMath.EPSILON6); @@ -737,7 +700,13 @@ defineSuite([ roll = CesiumMath.toRadians(200.0); - camera.setView({roll : roll}); + camera.setView({ + orientation: { + roll : roll, + heading: camera.heading, + pitch: camera.pitch + } + }); expect(camera.position).toEqualEpsilon(position, CesiumMath.EPSILON6); expect(camera.heading).toEqualEpsilon(heading, CesiumMath.EPSILON6); @@ -745,6 +714,26 @@ defineSuite([ expect(camera.roll).toEqualEpsilon(roll, CesiumMath.EPSILON6); }); + it('setView with direction, up', function() { + scene.mode = SceneMode.SCENE3D; + + var direction = Cartesian3.negate(Cartesian3.UNIT_Z, new Cartesian3()); + var up = Cartesian3.clone(Cartesian3.UNIT_Y); + + var options = { + destination : Cartesian3.fromDegrees(-117.16, 32.71, 0.0), + orientation : { + direction : direction, + up : up + }, + duration : 0.001 + }; + camera.setView(options); + + expect(camera.direction).toEqualEpsilon(direction, CesiumMath.EPSILON6); + expect(camera.up).toEqualEpsilon(up, CesiumMath.EPSILON6); + }); + it('worldToCameraCoordinates throws without cartesian', function() { expect(function() { camera.worldToCameraCoordinates(); @@ -1452,61 +1441,55 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('viewRectangle throws without rectangle', function() { - expect(function () { - camera.viewRectangle(); - }).toThrowDeveloperError(); - }); - - it('views rectangle in 3D (1)', function() { + it('setView rectangle in 3D (1)', function() { var rectangle = new Rectangle( -Math.PI, -CesiumMath.PI_OVER_TWO, Math.PI, CesiumMath.PI_OVER_TWO); - camera.viewRectangle(rectangle); + camera.setView({destination: rectangle}); expect(camera.position).toEqualEpsilon(new Cartesian3(14680290.639204923, 0.0, 0.0), CesiumMath.EPSILON6); expect(camera.direction).toEqualEpsilon(Cartesian3.negate(Cartesian3.UNIT_X, new Cartesian3()), CesiumMath.EPSILON10); expect(camera.up).toEqualEpsilon(Cartesian3.UNIT_Z, CesiumMath.EPSILON10); expect(camera.right).toEqualEpsilon(Cartesian3.UNIT_Y, CesiumMath.EPSILON10); }); - it('views rectangle in 3D (2)', function() { + it('setView rectangle in 3D (2)', function() { var rectangle = new Rectangle( CesiumMath.toRadians(21.25), CesiumMath.toRadians(41.23), CesiumMath.toRadians(21.51), CesiumMath.toRadians(41.38)); - camera.viewRectangle(rectangle, Ellipsoid.WGS84); + camera.setView({destination: rectangle}); expect(camera.position).toEqualEpsilon(new Cartesian3(4481555.454147325, 1754498.0086281248, 4200627.581953675), CesiumMath.EPSILON6); - expect(camera.direction).toEqualEpsilon(new Cartesian3(-0.6995108433013301, -0.27385366401082994, -0.6600672320390594), CesiumMath.EPSILON10); - expect(camera.up).toEqualEpsilon(new Cartesian3(-0.6146434679470263, -0.24062867269250837, 0.75120652898407), CesiumMath.EPSILON10); + expect(camera.direction).toEqualEpsilon(new Cartesian3(-0.6995046749050446, -0.27385124912628594, -0.6600747708691498), CesiumMath.EPSILON10); + expect(camera.up).toEqualEpsilon(new Cartesian3(-0.6146504879783901, -0.2406314209863035, 0.7511999047271233), CesiumMath.EPSILON10); expect(camera.right).toEqualEpsilon(new Cartesian3(-0.36455176232452213, 0.9311831251617939, 0), CesiumMath.EPSILON10); }); - it('views rectangle in 3D (3)', function() { + it('setView rectangle in 3D (3)', function() { var rectangle = new Rectangle( CesiumMath.toRadians(90.0), CesiumMath.toRadians(-50.0), CesiumMath.toRadians(157.0), CesiumMath.toRadians(0.0)); - camera.viewRectangle(rectangle); + camera.setView({destination: rectangle}); expect(camera.position).toEqualEpsilon(new Cartesian3(-6017603.25625715, 9091606.78076493, -5075070.862292178), CesiumMath.EPSILON6); - expect(camera.direction).toEqualEpsilon(new Cartesian3(0.5000640869795608, -0.7555144216716235, 0.4232420909591703), CesiumMath.EPSILON10); - expect(camera.up).toEqualEpsilon(new Cartesian3(-0.23360296374117637, 0.35293557895291494, 0.9060166292295686), CesiumMath.EPSILON10); + expect(camera.direction).toEqualEpsilon(new Cartesian3(0.49978034145251155, -0.7550857289433265, 0.42434084442077485), CesiumMath.EPSILON10); + expect(camera.up).toEqualEpsilon(new Cartesian3(-0.2342094064143758, 0.35385181388649406, 0.905502538790623), CesiumMath.EPSILON10); expect(camera.right).toEqualEpsilon(new Cartesian3(-0.8338858220671682, -0.5519369853120581, 0), CesiumMath.EPSILON10); }); - it('views rectangle in 3D (4)', function() { + it('setView rectangle in 3D (4)', function() { var rectangle = new Rectangle( CesiumMath.toRadians(90.0), CesiumMath.toRadians(-62.0), CesiumMath.toRadians(174.0), CesiumMath.toRadians(-4.0)); - camera.viewRectangle(rectangle); + camera.setView({destination: rectangle}); expect(camera.position).toEqualEpsilon(new Cartesian3(-7307919.685704952, 8116267.060310548, -7085995.891547672), CesiumMath.EPSILON6); - expect(camera.direction).toEqualEpsilon(new Cartesian3(0.5607858365117034, -0.622815768168856, 0.5455453826109309), CesiumMath.EPSILON10); - expect(camera.up).toEqualEpsilon(new Cartesian3(-0.3650411126627274, 0.4054192281503986, 0.8380812821629494), CesiumMath.EPSILON10); + expect(camera.direction).toEqualEpsilon(new Cartesian3(0.5602119862713765, -0.6221784429103113, 0.5468605998017956), CesiumMath.EPSILON10); + expect(camera.up).toEqualEpsilon(new Cartesian3(-0.3659211647391443, 0.40639662500016843, 0.8372236764356468), CesiumMath.EPSILON10); expect(camera.right).toEqualEpsilon(new Cartesian3(-0.7431448254773944, -0.6691306063588581, 0), CesiumMath.EPSILON10); }); @@ -1516,14 +1499,14 @@ defineSuite([ -CesiumMath.PI_OVER_TWO, -0.1, CesiumMath.PI_OVER_TWO); - camera.viewRectangle(rectangle); + camera.setView({destination: rectangle}); expect(camera.position).toEqualEpsilon(new Cartesian3(-14680290.639204923, 0.0, 0.0), CesiumMath.EPSILON6); expect(camera.direction).toEqualEpsilon(Cartesian3.UNIT_X, CesiumMath.EPSILON10); expect(camera.up).toEqualEpsilon(Cartesian3.UNIT_Z, CesiumMath.EPSILON10); expect(camera.right).toEqualEpsilon(Cartesian3.negate(Cartesian3.UNIT_Y, new Cartesian3()), CesiumMath.EPSILON10); }); - it('views rectangle in 2D with larger longitude', function() { + it('setView rectangle in 2D with larger longitude', function() { var frustum = new OrthographicFrustum(); frustum.left = -10.0; frustum.right = 10.0; @@ -1544,7 +1527,7 @@ defineSuite([ camera._mode = SceneMode.SCENE2D; camera._projection = projection; - camera.viewRectangle(rectangle); + camera.setView({destination: rectangle}); expect(camera.position.x).toEqual(0); expect(camera.position.y).toEqual(0); @@ -1554,7 +1537,7 @@ defineSuite([ expect(frustum.bottom + expected <= CesiumMath.EPSILON14).toEqual(true); }); - it('views rectangle in 2D with larger latitude', function() { + it('setView rectangle in 2D with larger latitude', function() { var frustum = new OrthographicFrustum(); frustum.left = -10.0; frustum.right = 10.0; @@ -1575,7 +1558,7 @@ defineSuite([ camera._mode = SceneMode.SCENE2D; camera._projection = projection; - camera.viewRectangle(rectangle); + camera.setView({destination: rectangle}); expect(camera.position.x).toEqual(0); expect(camera.position.y).toEqual(0); @@ -1585,7 +1568,7 @@ defineSuite([ expect(frustum.bottom + expected <= CesiumMath.EPSILON14).toEqual(true); }); - it('views rectangle in Columbus View', function() { + it('setView rectangle in Columbus View', function() { var rectangle = new Rectangle( -CesiumMath.PI_OVER_TWO, -CesiumMath.PI_OVER_TWO, @@ -1594,7 +1577,7 @@ defineSuite([ var projection = new GeographicProjection(); camera._mode = SceneMode.COLUMBUS_VIEW; camera._projection = projection; - camera.viewRectangle(rectangle); + camera.setView({destination: rectangle}); expect(camera.position).toEqualEpsilon(new Cartesian3(0.0, 0.0, 23137321.67119748), CesiumMath.EPSILON8); expect(camera.direction).toEqualEpsilon(new Cartesian3(0.0, 0.0, -1.0), CesiumMath.EPSILON2); expect(camera.up).toEqualEpsilon(new Cartesian3(0.0, 1.0, 0.0), CesiumMath.EPSILON2); @@ -2133,7 +2116,7 @@ defineSuite([ spyOn(CameraFlightPath, 'createTween').and.returnValue({ startObject : {}, stopObject: {}, - duration : 0.0 + duration : 0.001 }); var options = { @@ -2181,6 +2164,26 @@ defineSuite([ expect(camera.roll).toEqualEpsilon(roll, CesiumMath.EPSILON6); }); + it('flyTo with direction, up', function() { + scene.mode = SceneMode.SCENE3D; + + var direction = Cartesian3.negate(Cartesian3.UNIT_Z, new Cartesian3()); + var up = Cartesian3.clone(Cartesian3.UNIT_Y); + + var options = { + destination : Cartesian3.fromDegrees(-117.16, 32.71, 0.0), + orientation : { + direction : direction, + up : up + }, + duration : 0.0 + }; + camera.flyTo(options); + + expect(camera.direction).toEqualEpsilon(direction, CesiumMath.EPSILON6); + expect(camera.up).toEqualEpsilon(up, CesiumMath.EPSILON6); + }); + it('viewBoundingSphere', function() { scene.mode = SceneMode.SCENE3D; diff --git a/Specs/Scene/ScreenSpaceCameraControllerSpec.js b/Specs/Scene/ScreenSpaceCameraControllerSpec.js index 1180265705ff..ba362289d95b 100644 --- a/Specs/Scene/ScreenSpaceCameraControllerSpec.js +++ b/Specs/Scene/ScreenSpaceCameraControllerSpec.js @@ -1020,7 +1020,7 @@ defineSuite([ updateController(); camera.setView({ - position : Cartesian3.fromDegrees(-72.0, 40.0, 1.0) + destination : Cartesian3.fromDegrees(-72.0, 40.0, 1.0) }); updateController(); @@ -1035,7 +1035,7 @@ defineSuite([ updateController(); camera.setView({ - position : Cartesian3.fromDegrees(-72.0, 40.0, 1.0) + destination : Cartesian3.fromDegrees(-72.0, 40.0, 1.0) }); updateController(); @@ -1051,7 +1051,7 @@ defineSuite([ updateController(); camera.setView({ - position : Cartesian3.fromDegrees(-72.0, 40.0, -10.0) + destination : Cartesian3.fromDegrees(-72.0, 40.0, -10.0) }); updateController(); @@ -1067,7 +1067,7 @@ defineSuite([ updateController(); camera.setView({ - position : Cartesian3.fromDegrees(-72.0, 40.0, -10.0) + destination : Cartesian3.fromDegrees(-72.0, 40.0, -10.0) }); updateController(); diff --git a/Specs/Widgets/Geocoder/GeocoderViewModelSpec.js b/Specs/Widgets/Geocoder/GeocoderViewModelSpec.js index d9bdfdfa8784..e1b217b0db09 100644 --- a/Specs/Widgets/Geocoder/GeocoderViewModelSpec.js +++ b/Specs/Widgets/Geocoder/GeocoderViewModelSpec.js @@ -119,7 +119,7 @@ defineSuite([ expect(spyListener.calls.count()).toBe(1); - viewModel.duration = 1.5; + viewModel.flightDuration = 1.5; viewModel.serachText = '2.0, 2.0'; viewModel.search();