From 6b200e64a7fed8345b597dc400983bc10e63ca16 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Thu, 15 Oct 2015 11:49:58 -0400 Subject: [PATCH 01/16] init new setview params --- Source/Scene/Camera.js | 192 ++++++++++++------ Source/Scene/CameraFlightPath.js | 16 +- Source/Widgets/Geocoder/GeocoderViewModel.js | 32 +-- .../Widgets/HomeButton/HomeButtonViewModel.js | 10 +- 4 files changed, 144 insertions(+), 106 deletions(-) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index 4c03716f8140..f4a1b0070dc5 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, @@ -941,15 +943,45 @@ define([ camera._setTransform(currentTransform); } + function directionUpToHeadingPitchRoll(camera, position, orientation) { + var direction = Cartesian3.clone(orientation.direction, scratchFlyDirection); + var up = Cartesian3.clone(orientation.up, scratchFlyUp); + + 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, scratchFlyRight); + + return { + heading: getHeading(direction, up), + pitch: getPitch(direction), + roll: getRoll(direction, up, right) + }; + } + /** - * Sets the camera position and orientation with heading, pitch and roll angles. + * Flies the camera from its current position to a new position. * - * 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. + * @param {Object} options Object with the following properties: + * @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 the camera will be in when the flight is completed. + * + * @exception {DeveloperError} If either direction or up is given, then both are required. + */ + /** + * 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 {Cartesian3|Rectangle} options.position The final position of the camera in WGS84 (world) coordinates or a rectangle that would be visible from a top-down view. * @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. @@ -977,28 +1009,62 @@ define([ * }); */ Camera.prototype.setView = function(options) { - if (this._mode === SceneMode.MORPHING) { + options = defaultValue(options, defaultValue.EMPTY_OBJECT); + var orientation = defaultValue(options.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.'); + orientation.heading = options.heading; + orientation.pitch = options.pitch; + orientation.roll = options.roll; + } + if (defined(options.positionCartographic)){ + deprecationWarning('Camera.setView options', 'options.positionCartographic has been deprecated. Convert to a Cartesian3 and use options.position instead.'); + } + + var mode = this._mode; + if (mode === SceneMode.MORPHING) { return; } + var projection = this._projection; + var ellipsoid = projection.ellipsoid; + var position = options.position; + if (!defined(position) && defined(options.positionCartographic)){ + position = ellipsoid.cartographicToCartesian(options.positionCartographic); + } - 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); + if (defined(position) && defined(position.west)) { + if (mode !== SceneMode.SCENE3D && position.west > position.east) { + position = Rectangle.MAX_VALUE; + } + if (mode === SceneMode.SCENE3D) { + rectangleCameraPosition3D(this, position, ellipsoid, this.position); + } else if (mode === SceneMode.COLUMBUS_VIEW) { + rectangleCameraPositionColumbusView(this, position, projection, this.position); + } else if (mode === SceneMode.SCENE2D) { + rectangleCameraPosition2D(this, position, projection, this.position); + } + //TODO: apply orientation + return; + } - var cartesian = options.position; - var cartographic = options.positionCartographic; + if (defined(orientation.direction)) { + orientation = directionUpToHeadingPitchRoll(this, position, orientation); + } - var projection = this._projection; - var ellipsoid = projection.ellipsoid; + var heading = defaultValue(orientation.heading, this.heading); + var pitch = defaultValue(orientation.pitch, this.pitch); + var roll = defaultValue(orientation.roll, this.roll); - 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, position, undefined, heading, pitch, roll, ellipsoid); + } else if (mode === SceneMode.SCENE2D) { + setView2D(this, position, undefined, heading, pitch, roll, ellipsoid, projection); } else { - setViewCV(this, cartesian, cartographic, heading, pitch, roll, ellipsoid, projection); + setViewCV(this, position, undefined, heading, pitch, roll, ellipsoid, projection); } }; @@ -1882,6 +1948,9 @@ define([ var viewRectangleCVNorthEast = new Cartesian3(); var viewRectangleCVSouthWest = new Cartesian3(); function rectangleCameraPositionColumbusView(camera, rectangle, projection, result, positionOnly) { + if (rectangle.west > rectangle.east) { + rectangle = Rectangle.MAX_VALUE; + } var north = rectangle.north; var south = rectangle.south; var east = rectangle.east; @@ -1926,6 +1995,9 @@ define([ var viewRectangle2DNorthEast = new Cartesian3(); var viewRectangle2DSouthWest = new Cartesian3(); function rectangleCameraPosition2D (camera, rectangle, projection, result, positionOnly) { + if (rectangle.west > rectangle.east) { + rectangle = Rectangle.MAX_VALUE; + } var north = rectangle.north; var south = rectangle.south; var east = rectangle.east; @@ -1993,12 +2065,12 @@ define([ throw new DeveloperError('rectangle is required'); } //>>includeEnd('debug'); - - if (this._mode === SceneMode.SCENE3D) { + var mode = this._mode; + if (mode === SceneMode.SCENE3D) { return rectangleCameraPosition3D(this, rectangle, this._projection.ellipsoid, result, true); - } else if (this._mode === SceneMode.COLUMBUS_VIEW) { + } else if (mode === SceneMode.COLUMBUS_VIEW) { return rectangleCameraPositionColumbusView(this, rectangle, this._projection, result, true); - } else if (this._mode === SceneMode.SCENE2D) { + } else if (mode === SceneMode.SCENE2D) { return rectangleCameraPosition2D(this, rectangle, this._projection, result, true); } @@ -2010,19 +2082,18 @@ define([ * * @param {Rectangle} rectangle The rectangle to view. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid to view. + * + * @deprecated */ Camera.prototype.viewRectangle = function(rectangle, ellipsoid) { + deprecationWarning('Camera.viewRectangle', 'Camera.viewRectangle has been deprecated. Use Camera.setView (options.position = 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; - } - + ellipsoid = defaultValue(ellipsoid, this._projection.ellipsoid); if (this._mode === SceneMode.SCENE3D) { rectangleCameraPosition3D(this, rectangle, ellipsoid, this.position); } else if (this._mode === SceneMode.COLUMBUS_VIEW) { @@ -2423,57 +2494,45 @@ define([ */ Camera.prototype.flyTo = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); - var destination = options.destination; //>>includeStart('debug', pragmas.debug); if (!defined(destination)) { throw new DeveloperError('destination is required.'); } //>>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); + } - var right = Cartesian3.cross(direction, up, scratchFlyRight); + if (defined(options.duration) && options.duration <= 0.0) { + this.setView({ + position: options.destination, + orientation: { + heading: defaultValue(orientation.heading, 0.0), + pitch: mode !== SceneMode.SCENE2D ? defaultValue(orientation.pitch, -CesiumMath.PI_OVER_TWO) : -CesiumMath.PI_OVER_TWO, + roll: defaultValue(orientation.roll, 0.0) + }, + endTransform: options.endTransform + }); + if (typeof options.complete === 'function'){ + options.complete(); + } + } - 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 +2541,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..b3665553189d 100644 --- a/Source/Scene/CameraFlightPath.js +++ b/Source/Scene/CameraFlightPath.js @@ -263,20 +263,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,7 +292,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); diff --git a/Source/Widgets/Geocoder/GeocoderViewModel.js b/Source/Widgets/Geocoder/GeocoderViewModel.js index 28d92d788e60..3b1a9beabf50 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, From 807a42a1f2bb0c12e9477393c7beaddbc91325dc Mon Sep 17 00:00:00 2001 From: hpinkos Date: Thu, 15 Oct 2015 13:00:37 -0400 Subject: [PATCH 02/16] begin cleanup private functions --- Source/Scene/Camera.js | 80 +++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index f4a1b0070dc5..f8f8779a68c0 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -858,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); @@ -883,18 +875,23 @@ define([ camera._setTransform(currentTransform); } - function setViewCV(camera, cartesian, cartographic, heading, pitch, roll, ellipsoid, projection) { + function setViewCV(camera, position, heading, pitch, roll) { 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)) { + var projection = camera._projection; + var cartographic = projection.ellipsoid.cartesianToCartographic(position, scratchSetViewCartographic); + position = projection.project(cartographic, scratchSetViewCartesian); + Cartesian3.clone(position, camera.position); + } - if (defined(cartographic)) { - cartesian = projection.project(cartographic, scratchSetViewCartesian); - Cartesian3.clone(cartesian, camera.position); + /* if (convert) { + ellipsoid.cartesianToCartographic(destination, scratchCartographic); + destination = projection.project(scratchCartographic, scratchDestination); } +*/ var rotQuat = Quaternion.fromHeadingPitchRoll(heading - CesiumMath.PI_OVER_TWO, pitch, roll, scratchSetViewQuaternion); var rotMat = Matrix3.fromQuaternion(rotQuat, scratchSetViewMatrix3); @@ -906,20 +903,18 @@ define([ camera._setTransform(currentTransform); } - function setView2D(camera, cartesian, cartographic, heading, pitch, roll, ellipsoid, projection) { + function setView2D(camera, position, heading, pitch, roll) { pitch = -CesiumMath.PI_OVER_TWO; 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 (defined(cartographic)) { - cartesian = projection.project(cartographic, scratchSetViewCartesian); - Cartesian2.clone(cartesian, camera.position); + if (!Cartesian3.equals(position, camera.positionWC)) { + var projection = camera._projection; + var cartographic = projection.ellipsoid.cartesianToCartographic(position, scratchSetViewCartographic); + position = projection.project(cartographic, scratchSetViewCartesian); + Cartesian2.clone(position, camera.position); var newLeft = -cartographic.height * 0.5; var newRight = -newLeft; @@ -1041,17 +1036,18 @@ define([ position = Rectangle.MAX_VALUE; } if (mode === SceneMode.SCENE3D) { - rectangleCameraPosition3D(this, position, ellipsoid, this.position); + rectangleCameraPosition3D(this, position, this.position); } else if (mode === SceneMode.COLUMBUS_VIEW) { - rectangleCameraPositionColumbusView(this, position, projection, this.position); + rectangleCameraPositionColumbusView(this, position, this.position); } else if (mode === SceneMode.SCENE2D) { - rectangleCameraPosition2D(this, position, projection, this.position); + rectangleCameraPosition2D(this, position, this.position); } //TODO: apply orientation return; } if (defined(orientation.direction)) { + position = defaultValue(position, Cartesian3.clone(this.positionWC, scratchSetViewCartesian)); orientation = directionUpToHeadingPitchRoll(this, position, orientation); } @@ -1059,12 +1055,14 @@ define([ var pitch = defaultValue(orientation.pitch, this.pitch); var roll = defaultValue(orientation.roll, this.roll); + position = defaultValue(position, Cartesian3.clone(this.positionWC, scratchSetViewCartesian)); + if (mode === SceneMode.SCENE3D) { - setView3D(this, position, undefined, heading, pitch, roll, ellipsoid); + setView3D(this, position, heading, pitch, roll); } else if (mode === SceneMode.SCENE2D) { - setView2D(this, position, undefined, heading, pitch, roll, ellipsoid, projection); + setView2D(this, position, heading, pitch, roll); } else { - setViewCV(this, position, undefined, heading, pitch, roll, ellipsoid, projection); + setViewCV(this, position, heading, pitch, roll); } }; @@ -1813,11 +1811,11 @@ define([ var defaultRF = {direction: new Cartesian3(), right: new Cartesian3(), up: new Cartesian3()}; var viewRectangle3DEllipsoidGeodesic; - function rectangleCameraPosition3D (camera, rectangle, ellipsoid, result, positionOnly) { + function rectangleCameraPosition3D (camera, rectangle, result, positionOnly) { if (!defined(result)) { result = new Cartesian3(); } - + var ellipsoid = camera._projection.ellipsoid; var cameraRF = camera; if (positionOnly) { cameraRF = defaultRF; @@ -1947,7 +1945,8 @@ define([ var viewRectangleCVCartographic = new Cartographic(); var viewRectangleCVNorthEast = new Cartesian3(); var viewRectangleCVSouthWest = new Cartesian3(); - function rectangleCameraPositionColumbusView(camera, rectangle, projection, result, positionOnly) { + function rectangleCameraPositionColumbusView(camera, rectangle, result, positionOnly) { + var projection = camera._projection; if (rectangle.west > rectangle.east) { rectangle = Rectangle.MAX_VALUE; } @@ -1994,7 +1993,8 @@ define([ var viewRectangle2DCartographic = new Cartographic(); var viewRectangle2DNorthEast = new Cartesian3(); var viewRectangle2DSouthWest = new Cartesian3(); - function rectangleCameraPosition2D (camera, rectangle, projection, result, positionOnly) { + function rectangleCameraPosition2D (camera, rectangle, result, positionOnly) { + var projection = camera._projection; if (rectangle.west > rectangle.east) { rectangle = Rectangle.MAX_VALUE; } @@ -2067,11 +2067,11 @@ define([ //>>includeEnd('debug'); var mode = this._mode; if (mode === SceneMode.SCENE3D) { - return rectangleCameraPosition3D(this, rectangle, this._projection.ellipsoid, result, true); + return rectangleCameraPosition3D(this, rectangle, result, true); } else if (mode === SceneMode.COLUMBUS_VIEW) { - return rectangleCameraPositionColumbusView(this, rectangle, this._projection, result, true); + return rectangleCameraPositionColumbusView(this, rectangle, result, true); } else if (mode === SceneMode.SCENE2D) { - return rectangleCameraPosition2D(this, rectangle, this._projection, result, true); + return rectangleCameraPosition2D(this, rectangle, result, true); } return undefined; @@ -2095,11 +2095,11 @@ define([ ellipsoid = defaultValue(ellipsoid, this._projection.ellipsoid); if (this._mode === SceneMode.SCENE3D) { - rectangleCameraPosition3D(this, rectangle, ellipsoid, this.position); + rectangleCameraPosition3D(this, rectangle, this.position); } else if (this._mode === SceneMode.COLUMBUS_VIEW) { - rectangleCameraPositionColumbusView(this, rectangle, this._projection, this.position); + rectangleCameraPositionColumbusView(this, rectangle, this.position); } else if (this._mode === SceneMode.SCENE2D) { - rectangleCameraPosition2D(this, rectangle, this._projection, this.position); + rectangleCameraPosition2D(this, rectangle, this.position); } }; From d61326a0959d72d867e487c90323a118824d7ae1 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Thu, 15 Oct 2015 14:01:17 -0400 Subject: [PATCH 03/16] testing --- Source/Scene/Camera.js | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index f8f8779a68c0..d669d0315481 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -887,12 +887,6 @@ define([ } - /* if (convert) { - ellipsoid.cartesianToCartographic(destination, scratchCartographic); - destination = projection.project(scratchCartographic, scratchDestination); - } -*/ - var rotQuat = Quaternion.fromHeadingPitchRoll(heading - CesiumMath.PI_OVER_TWO, pitch, roll, scratchSetViewQuaternion); var rotMat = Matrix3.fromQuaternion(rotQuat, scratchSetViewMatrix3); @@ -1811,10 +1805,12 @@ define([ var defaultRF = {direction: new Cartesian3(), right: new Cartesian3(), up: new Cartesian3()}; var viewRectangle3DEllipsoidGeodesic; + function computeD(direction, upOrRight, corner, tanThetaOrPhi) { + var opposite = Math.abs(Cartesian3.dot(upOrRight, corner)); + return opposite / tanThetaOrPhi - Cartesian3.dot(direction, corner); + } + function rectangleCameraPosition3D (camera, rectangle, result, positionOnly) { - if (!defined(result)) { - result = new Cartesian3(); - } var ellipsoid = camera._projection.ellipsoid; var cameraRF = camera; if (positionOnly) { @@ -1903,11 +1899,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), @@ -2027,16 +2018,13 @@ 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) { + result.x = (northEast.x - southWest.x) * 0.5 + southWest.x; + result.y = (northEast.y - southWest.y) * 0.5 + southWest.y; + cart = projection.unproject(result, cart); cart.height = height; - result = projection.project(cart, result); + return projection.project(cart, result); } else { var frustum = camera.frustum; frustum.right = right; @@ -2049,8 +2037,6 @@ define([ Cartesian3.clone(Cartesian3.UNIT_X, camera.right); Cartesian3.clone(Cartesian3.UNIT_Y, camera.up); } - - return result; } /** * Get the camera position needed to view an rectangle on an ellipsoid or map @@ -2066,6 +2052,7 @@ define([ } //>>includeEnd('debug'); var mode = this._mode; + result = defaultValue(result, new Cartesian3()); if (mode === SceneMode.SCENE3D) { return rectangleCameraPosition3D(this, rectangle, result, true); } else if (mode === SceneMode.COLUMBUS_VIEW) { From 2b22c4819985fa1c9aae332b12529b05a3efe408 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Thu, 15 Oct 2015 14:36:00 -0400 Subject: [PATCH 04/16] fix tests --- Source/Scene/Camera.js | 14 +++++++------- Specs/Widgets/Geocoder/GeocoderViewModelSpec.js | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index d669d0315481..7a9226456b02 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -2018,13 +2018,13 @@ define([ height = Math.max(2.0 * right, 2.0 * top); - if (positionOnly) { - result.x = (northEast.x - southWest.x) * 0.5 + southWest.x; - result.y = (northEast.y - southWest.y) * 0.5 + southWest.y; + 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; - return projection.project(cart, result); + result = projection.project(cart, result); } else { var frustum = camera.frustum; frustum.right = right; @@ -2037,6 +2037,8 @@ define([ Cartesian3.clone(Cartesian3.UNIT_X, camera.right); Cartesian3.clone(Cartesian3.UNIT_Y, camera.up); } + + return result; } /** * Get the camera position needed to view an rectangle on an ellipsoid or map @@ -2069,11 +2071,8 @@ define([ * * @param {Rectangle} rectangle The rectangle to view. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid to view. - * - * @deprecated */ Camera.prototype.viewRectangle = function(rectangle, ellipsoid) { - deprecationWarning('Camera.viewRectangle', 'Camera.viewRectangle has been deprecated. Use Camera.setView (options.position = rectangle) instead.'); //>>includeStart('debug', pragmas.debug); if (!defined(rectangle)) { throw new DeveloperError('rectangle is required.'); @@ -2509,6 +2508,7 @@ define([ if (typeof options.complete === 'function'){ options.complete(); } + return; } var isRectangle = defined(destination.west); 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(); From 3e00723be9e9ccf2335f0c00985c0fd886f58517 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Thu, 15 Oct 2015 16:44:55 -0400 Subject: [PATCH 05/16] fix view rectangle --- Source/Scene/Camera.js | 79 ++++++++++++++++----------------------- Specs/Scene/CameraSpec.js | 26 ++++++++++--- 2 files changed, 53 insertions(+), 52 deletions(-) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index 7a9226456b02..0a6dc24e9201 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -884,7 +884,6 @@ define([ 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); @@ -978,16 +977,13 @@ define([ * * @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 - * }); - * - * // 2. Set default top-down view with a cartographic position - * camera.setView({ - * positionCartographic : cartographic + * `({ + * 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. @@ -1002,12 +998,16 @@ define([ var orientation = defaultValue(options.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.'); - orientation.heading = options.heading; - orientation.pitch = options.pitch; - orientation.roll = options.roll; + orientation.heading = defaultValue(options.heading, this.heading); + orientation.pitch = defaultValue(options.pitch, this.pitch); + orientation.roll = defaultValue(options.roll, this.roll); } if (defined(options.positionCartographic)){ + deprecationWarning('Camera.setView options', 'options.position has been renamed to options.destination.'); + } + if (defined(options.position)){ deprecationWarning('Camera.setView options', 'options.positionCartographic has been deprecated. Convert to a Cartesian3 and use options.position instead.'); + options.destination = options.position; } var mode = this._mode; @@ -1016,47 +1016,38 @@ define([ } var projection = this._projection; var ellipsoid = projection.ellipsoid; - var position = options.position; - if (!defined(position) && defined(options.positionCartographic)){ - position = ellipsoid.cartographicToCartesian(options.positionCartographic); + var destination = options.destination; + var convert = true; + if (!defined(destination) && defined(options.positionCartographic)){ + destination = ellipsoid.cartographicToCartesian(options.positionCartographic); + } if (defined(options.endTransform)) { this._setTransform(options.endTransform); } - if (defined(position) && defined(position.west)) { - if (mode !== SceneMode.SCENE3D && position.west > position.east) { - position = Rectangle.MAX_VALUE; - } - if (mode === SceneMode.SCENE3D) { - rectangleCameraPosition3D(this, position, this.position); - } else if (mode === SceneMode.COLUMBUS_VIEW) { - rectangleCameraPositionColumbusView(this, position, this.position); - } else if (mode === SceneMode.SCENE2D) { - rectangleCameraPosition2D(this, position, this.position); - } - //TODO: apply orientation - return; + if (defined(destination) && defined(destination.west)) { + destination = this.viewRectangle(destination); } if (defined(orientation.direction)) { - position = defaultValue(position, Cartesian3.clone(this.positionWC, scratchSetViewCartesian)); - orientation = directionUpToHeadingPitchRoll(this, position, orientation); + destination = defaultValue(destination, Cartesian3.clone(this.positionWC, scratchSetViewCartesian)); + orientation = directionUpToHeadingPitchRoll(this, destination, orientation); } - var heading = defaultValue(orientation.heading, this.heading); - var pitch = defaultValue(orientation.pitch, this.pitch); - var roll = defaultValue(orientation.roll, this.roll); + var heading = defaultValue(orientation.heading, 0.0); + var pitch = mode !== SceneMode.SCENE2D ? defaultValue(orientation.pitch, -CesiumMath.PI_OVER_TWO) : -CesiumMath.PI_OVER_TWO; + var roll = defaultValue(orientation.roll, 0.0); - position = defaultValue(position, Cartesian3.clone(this.positionWC, scratchSetViewCartesian)); + destination = defined(destination) ? destination : Cartesian3.clone(this.positionWC, scratchSetViewCartesian); if (mode === SceneMode.SCENE3D) { - setView3D(this, position, heading, pitch, roll); + setView3D(this, destination, heading, pitch, roll); } else if (mode === SceneMode.SCENE2D) { - setView2D(this, position, heading, pitch, roll); + setView2D(this, destination, heading, pitch, roll); } else { - setViewCV(this, position, heading, pitch, roll); + setViewCV(this, destination, heading, pitch, roll); } }; @@ -2070,16 +2061,14 @@ 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. */ - Camera.prototype.viewRectangle = function(rectangle, ellipsoid) { + Camera.prototype.viewRectangle = function(rectangle) { //>>includeStart('debug', pragmas.debug); if (!defined(rectangle)) { throw new DeveloperError('rectangle is required.'); } //>>includeEnd('debug'); - ellipsoid = defaultValue(ellipsoid, this._projection.ellipsoid); if (this._mode === SceneMode.SCENE3D) { rectangleCameraPosition3D(this, rectangle, this.position); } else if (this._mode === SceneMode.COLUMBUS_VIEW) { @@ -2498,11 +2487,7 @@ define([ if (defined(options.duration) && options.duration <= 0.0) { this.setView({ position: options.destination, - orientation: { - heading: defaultValue(orientation.heading, 0.0), - pitch: mode !== SceneMode.SCENE2D ? defaultValue(orientation.pitch, -CesiumMath.PI_OVER_TWO) : -CesiumMath.PI_OVER_TWO, - roll: defaultValue(orientation.roll, 0.0) - }, + orientation: orientation, endTransform: options.endTransform }); if (typeof options.complete === 'function'){ diff --git a/Specs/Scene/CameraSpec.js b/Specs/Scene/CameraSpec.js index 9af7d2099310..36bcd4a813a1 100644 --- a/Specs/Scene/CameraSpec.js +++ b/Specs/Scene/CameraSpec.js @@ -453,7 +453,9 @@ defineSuite([ var newRoll = CesiumMath.PI_OVER_FOUR; camera.setView({ - roll : newRoll + pitch: camera.pitch, + roll : newRoll, + heading: camera.heading }); expect(camera.positionCartographic).toEqual(positionCartographic); @@ -474,7 +476,9 @@ defineSuite([ var newRoll = CesiumMath.PI_OVER_FOUR; camera.setView({ - roll : newRoll + pitch: camera.pitch, + roll : newRoll, + heading: camera.heading }); expect(camera.positionCartographic).toEqual(positionCartographic); @@ -681,7 +685,11 @@ defineSuite([ heading = CesiumMath.toRadians(200.0); - camera.setView({heading : heading}); + camera.setView({ + pitch: camera.pitch, + roll : camera.roll, + heading : heading + }); expect(camera.position).toEqualEpsilon(position, CesiumMath.EPSILON6); expect(camera.heading).toEqualEpsilon(heading, CesiumMath.EPSILON6); @@ -709,7 +717,11 @@ defineSuite([ pitch = CesiumMath.toRadians(-50.0); - camera.setView({pitch : pitch}); + camera.setView({ + pitch : pitch, + roll : camera.roll, + heading: camera.heading + }); expect(camera.position).toEqualEpsilon(position, CesiumMath.EPSILON6); expect(camera.heading).toEqualEpsilon(heading, CesiumMath.EPSILON6); @@ -737,7 +749,11 @@ defineSuite([ roll = CesiumMath.toRadians(200.0); - camera.setView({roll : roll}); + camera.setView({ + roll : roll, + heading: camera.heading, + pitch: camera.pitch + }); expect(camera.position).toEqualEpsilon(position, CesiumMath.EPSILON6); expect(camera.heading).toEqualEpsilon(heading, CesiumMath.EPSILON6); From 58263ecc818a9615b0399c01a15d7976b93951d5 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Thu, 15 Oct 2015 17:03:00 -0400 Subject: [PATCH 06/16] camera flight only orientation change --- Source/Scene/CameraFlightPath.js | 43 ++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/Source/Scene/CameraFlightPath.js b/Source/Scene/CameraFlightPath.js index b3665553189d..1ba13f74a604 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) + } }); }; @@ -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); @@ -308,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(heading, camera.heading, CesiumMath.EPSILON10) && + CesiumMath.equalsEpsilon(pitch, camera.pitch, CesiumMath.EPSILON10) && + CesiumMath.equalsEpsilon(roll, camera.roll, CesiumMath.EPSILON10)); if (empty) { return emptyFlight(complete, cancel); From 5885d2b9671ba4642185f86aa41c6fc77bfbcd8a Mon Sep 17 00:00:00 2001 From: hpinkos Date: Thu, 15 Oct 2015 17:32:35 -0400 Subject: [PATCH 07/16] fix camera flight spec --- Source/Scene/CameraFlightPath.js | 6 ++--- Specs/Scene/CameraFlightPathSpec.js | 38 +++++++++++++++++------------ 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/Source/Scene/CameraFlightPath.js b/Source/Scene/CameraFlightPath.js index 1ba13f74a604..dfe97e5c1092 100644 --- a/Source/Scene/CameraFlightPath.js +++ b/Source/Scene/CameraFlightPath.js @@ -317,9 +317,9 @@ define([ empty = empty || (scene.mode !== SceneMode.SCENE2D && Cartesian3.equalsEpsilon(destination, camera.position, CesiumMath.EPSILON10) && - CesiumMath.equalsEpsilon(heading, camera.heading, CesiumMath.EPSILON10) && - CesiumMath.equalsEpsilon(pitch, camera.pitch, CesiumMath.EPSILON10) && - CesiumMath.equalsEpsilon(roll, camera.roll, 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/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)); From 71fc767265a9a5cf082941414dea884cb1a6bf34 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Thu, 15 Oct 2015 18:07:29 -0400 Subject: [PATCH 08/16] new tests --- Specs/Scene/CameraSpec.js | 314 +++++++++++++++++++++++--------------- 1 file changed, 190 insertions(+), 124 deletions(-) diff --git a/Specs/Scene/CameraSpec.js b/Specs/Scene/CameraSpec.js index 36bcd4a813a1..2137def126da 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,9 +473,11 @@ defineSuite([ var newRoll = CesiumMath.PI_OVER_FOUR; camera.setView({ - pitch: camera.pitch, - roll : newRoll, - heading: camera.heading + orientation: { + pitch: camera.pitch, + roll : newRoll, + heading: camera.heading + } }); expect(camera.positionCartographic).toEqual(positionCartographic); @@ -476,9 +498,11 @@ defineSuite([ var newRoll = CesiumMath.PI_OVER_FOUR; camera.setView({ - pitch: camera.pitch, - roll : newRoll, - heading: camera.heading + orientation: { + pitch: camera.pitch, + roll : newRoll, + heading: camera.heading + } }); expect(camera.positionCartographic).toEqual(positionCartographic); @@ -492,7 +516,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('setView with cartographic in 2D', function() { + it('setView with cartesian in 2D', function() { var ellipsoid = Ellipsoid.WGS84; var projection = new GeographicProjection(ellipsoid); var maxRadii = ellipsoid.maximumRadius; @@ -510,15 +534,13 @@ defineSuite([ camera.frustum = frustum; var ratio = frustum.top / frustum.right; - var cart = Cartographic.fromDegrees(-75.0, 42.0, 100.0); + var cartesian = Cartesian3.fromDegrees(-75.0, 42.0, 100.0); camera.setView({ - heading : 0.0, - pitch : -CesiumMath.PI_OVER_TWO, - roll : 0.0, - positionCartographic : cart + destination : cartesian }); - expect(Cartesian2.fromCartesian3(camera.position, new Cartesian2())).toEqualEpsilon(Cartesian2.fromCartesian3(projection.project(cart), new Cartesian2()), CesiumMath.EPSILON11); + var cart = ellipsoid.cartesianToCartographic(cartesian); + expect(camera.positionCartographic).toEqualEpsilon(cart, CesiumMath.EPSILON6); 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); @@ -526,124 +548,114 @@ defineSuite([ expect(frustum.top / frustum.right).toEqual(ratio); }); - it('setView with cartesian in 2D', function() { + it('setView with cartesian in Columbus View', function() { var ellipsoid = Ellipsoid.WGS84; var projection = new GeographicProjection(ellipsoid); - var maxRadii = ellipsoid.maximumRadius; - camera._mode = SceneMode.SCENE2D; + camera._mode = SceneMode.COLUMBUS_VIEW; 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 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); - expect(camera.positionCartographic).toEqualEpsilon(cart, CesiumMath.EPSILON6); + expect(camera.positionCartographic).toEqualEpsilon(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); - expect(frustum.right - frustum.left).toEqualEpsilon(cart.height, CesiumMath.EPSILON6); - expect(frustum.top / frustum.right).toEqual(ratio); }); - it('setView with cartographic in Columbus View', function() { + it('setView with cartesian in 3D', function() { var ellipsoid = Ellipsoid.WGS84; var projection = new GeographicProjection(ellipsoid); - camera._mode = SceneMode.COLUMBUS_VIEW; + camera._mode = SceneMode.SCENE3D; camera._projection = projection; - var cart = Cartographic.fromDegrees(-75.0, 42.0, 100.0); + var cartesian = Cartesian3.fromDegrees(-75.0, 0.0, 100.0); camera.setView({ - heading : 0.0, - pitch : -CesiumMath.PI_OVER_TWO, - roll : 0.0, - positionCartographic : cart + destination : cartesian }); - 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); + expect(camera.positionCartographic).toEqualEpsilon(ellipsoid.cartesianToCartographic(cartesian), 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 Columbus View', function() { - var ellipsoid = Ellipsoid.WGS84; - var projection = new GeographicProjection(ellipsoid); - camera._mode = SceneMode.COLUMBUS_VIEW; - camera._projection = projection; + it('setView with rectangle in 2D', function() { + var frustum = new OrthographicFrustum(); + frustum.left = -10.0; + frustum.right = 10.0; + frustum.bottom = -10.0; + frustum.top = 10.0; + frustum.near = 1.0; + frustum.far = 21.0; + camera.frustum = frustum; - var cartesian = Cartesian3.fromDegrees(-75.0, 42.0, 100.0); + var rectangle = new Rectangle( + -CesiumMath.PI_OVER_TWO, + -CesiumMath.PI_OVER_FOUR, + CesiumMath.PI_OVER_TWO, + CesiumMath.PI_OVER_FOUR); + var projection = new GeographicProjection(); + var edge = projection.project(new Cartographic(CesiumMath.PI_OVER_TWO, CesiumMath.PI_OVER_FOUR)); + var expected = Math.max(edge.x, edge.y); + + camera._mode = SceneMode.SCENE2D; + camera._projection = projection; camera.setView({ - heading : 0.0, - pitch : -CesiumMath.PI_OVER_TWO, - roll : 0.0, - position : cartesian + destination: rectangle }); - var cart = ellipsoid.cartesianToCartographic(cartesian); - expect(camera.positionCartographic).toEqualEpsilon(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); + expect(camera.position.x).toEqual(0); + expect(camera.position.y).toEqual(0); + expect(frustum.right - expected <= CesiumMath.EPSILON14).toEqual(true); + expect(frustum.left + expected <= CesiumMath.EPSILON14).toEqual(true); + expect(frustum.top - expected <= CesiumMath.EPSILON14).toEqual(true); + expect(frustum.bottom + expected <= CesiumMath.EPSILON14).toEqual(true); }); - it('setView with cartographic in 3D', function() { - var ellipsoid = Ellipsoid.WGS84; - var projection = new GeographicProjection(ellipsoid); - - camera._mode = SceneMode.SCENE3D; + it('setView with rectangle in Columbus View', function() { + var rectangle = new Rectangle( + -CesiumMath.PI_OVER_TWO, + -CesiumMath.PI_OVER_TWO, + CesiumMath.PI_OVER_TWO, + CesiumMath.PI_OVER_TWO); + var projection = new GeographicProjection(); + camera._mode = SceneMode.COLUMBUS_VIEW; 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 + 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); + expect(camera.right).toEqualEpsilon(new Cartesian3(1.0, 0.0, 0.0), CesiumMath.EPSILON10); - 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); - + it('setView with rectangle in 3D', function() { camera._mode = SceneMode.SCENE3D; - camera._projection = projection; + + var rectangle = new Rectangle( + -Math.PI, + -CesiumMath.PI_OVER_TWO, + Math.PI, + CesiumMath.PI_OVER_TWO); 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 : rectangle }); - expect(camera.positionCartographic).toEqualEpsilon(ellipsoid.cartesianToCartographic(cartesian), 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); + 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('setView right rotation order', function() { @@ -653,10 +665,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); @@ -672,10 +686,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); @@ -686,9 +702,11 @@ defineSuite([ heading = CesiumMath.toRadians(200.0); camera.setView({ - pitch: camera.pitch, - roll : camera.roll, - heading : heading + orientation: { + pitch: camera.pitch, + roll : camera.roll, + heading : heading + } }); expect(camera.position).toEqualEpsilon(position, CesiumMath.EPSILON6); @@ -704,10 +722,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); @@ -718,9 +738,11 @@ defineSuite([ pitch = CesiumMath.toRadians(-50.0); camera.setView({ - pitch : pitch, - roll : camera.roll, - heading: camera.heading + orientation: { + pitch : pitch, + roll : camera.roll, + heading: camera.heading + } }); expect(camera.position).toEqualEpsilon(position, CesiumMath.EPSILON6); @@ -736,10 +758,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); @@ -750,9 +774,11 @@ defineSuite([ roll = CesiumMath.toRadians(200.0); camera.setView({ - roll : roll, - heading: camera.heading, - pitch: camera.pitch + orientation: { + roll : roll, + heading: camera.heading, + pitch: camera.pitch + } }); expect(camera.position).toEqualEpsilon(position, CesiumMath.EPSILON6); @@ -761,6 +787,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(); @@ -2149,7 +2195,7 @@ defineSuite([ spyOn(CameraFlightPath, 'createTween').and.returnValue({ startObject : {}, stopObject: {}, - duration : 0.0 + duration : 0.001 }); var options = { @@ -2197,6 +2243,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; From da284567482fac6524b6949c48a6abd257fccda2 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Thu, 15 Oct 2015 18:42:19 -0400 Subject: [PATCH 09/16] update doc and changes --- Apps/CesiumViewer/CesiumViewer.js | 10 +++--- Apps/Sandcastle/gallery/Camera.html | 8 +++-- CHANGES.md | 5 +++ Source/Scene/Camera.js | 55 ++++++++++++++++++----------- 4 files changed, 50 insertions(+), 28 deletions(-) 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 7a53b5e8c3db..4f8971a23c0c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,11 @@ Change Log * Made `EllipsoidPrimitive` private, use `EllipsoidGeometry` or `Entity.ellipsoid` instead. * Deprecated `RectanglePrimitive`, use `RectangleGeometry` or `Entity.rectangle` instead. It will be removed in 1.17. * Deprecated `EllipsoidPrimitive`, use `EllipsoidGeometry` or `Entity.ellipsoid` instead. It will be removed in 1.17. + * Deprecated `Camera.setView`, use `EllipsoidGeometry` or `Entity.ellipsoid` 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`. diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index 0a6dc24e9201..5260aeb4e43f 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -212,7 +212,7 @@ define([ this._max2Dfrustum = undefined; // set default view - this.viewRectangle(Camera.DEFAULT_VIEW_RECTANGLE, scene.mapProjection.ellipsoid); + this.viewRectangle(Camera.DEFAULT_VIEW_RECTANGLE); var mag = Cartesian3.magnitude(this.position); mag += mag * Camera.DEFAULT_VIEW_FACTOR; @@ -954,29 +954,23 @@ define([ } /** - * Flies the camera from its current position to a new position. + * Sets the camera position, orientation and transform. * * @param {Object} options Object with the following properties: + * @param {Object} options Object with the following properties: * @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 the camera will be in when the flight is completed. * - * @exception {DeveloperError} If either direction or up is given, then both are required. - */ - /** - * Sets the camera position, orientation and transform. - * - * @param {Object} options Object with the following properties: - * @param {Cartesian3|Rectangle} options.position The final position of the camera in WGS84 (world) coordinates or a rectangle that would be visible from a top-down view. - * @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. - * * @example - * // 1. Set view with heading, pitch and roll + * // 1. Set position with a top-down view + * viewer.camera.setView({ + * destination : Cesium.Cartesian3.fromDegrees(-117.16, 32.71, 15000.0) + * }); + * + * // 2 Set view with heading, pitch and roll * `({ * destination : cartesianPosition, * orientation: { @@ -988,9 +982,26 @@ define([ * * // 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 + * 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) { @@ -2031,6 +2042,7 @@ define([ return result; } + /** * Get the camera position needed to view an rectangle on an ellipsoid or map * @@ -2069,11 +2081,12 @@ define([ } //>>includeEnd('debug'); - if (this._mode === SceneMode.SCENE3D) { + var mode = this._mode; + if (mode === SceneMode.SCENE3D) { rectangleCameraPosition3D(this, rectangle, this.position); - } else if (this._mode === SceneMode.COLUMBUS_VIEW) { + } else if (mode === SceneMode.COLUMBUS_VIEW) { rectangleCameraPositionColumbusView(this, rectangle, this.position); - } else if (this._mode === SceneMode.SCENE2D) { + } else if (mode === SceneMode.SCENE2D) { rectangleCameraPosition2D(this, rectangle, this.position); } }; From ad6710b7437cbacd603ed54f64f4110833bbb681 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Thu, 15 Oct 2015 18:50:32 -0400 Subject: [PATCH 10/16] add to changes --- CHANGES.md | 1 + Specs/Scene/ScreenSpaceCameraControllerSpec.js | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4f8971a23c0c..f0a1adf767c9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,6 +21,7 @@ Change Log * 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 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(); From cff1e058d678b8a1b5b973444ec6ad6c5563b595 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Fri, 16 Oct 2015 11:17:48 -0400 Subject: [PATCH 11/16] deprecate camera.viewRectangle --- CHANGES.md | 2 +- Source/Scene/Camera.js | 34 +++++++++++++++++++-------- Specs/Scene/CameraSpec.js | 48 +++++++++++++++++---------------------- 3 files changed, 46 insertions(+), 38 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b95e6f0f5a47..116297ceb6cb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,11 +15,11 @@ 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. * 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. + * Deprecated `Camera.viewRectangle`, use `Camera.setView({destination: rectangle})` instead. It will be removed in 1.17. * 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`. diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index 2aa881fc453c..f7e7c6a276f2 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -212,7 +212,15 @@ define([ this._max2Dfrustum = undefined; // set default view - this.viewRectangle(Camera.DEFAULT_VIEW_RECTANGLE); + var rectangle = Camera.DEFAULT_VIEW_RECTANGLE; + var mode = this._mode; + if (mode === SceneMode.SCENE3D) { + rectangleCameraPosition3D(this, rectangle, this.position); + } else if (mode === SceneMode.COLUMBUS_VIEW) { + rectangleCameraPositionColumbusView(this, rectangle, this.position); + } else if (mode === SceneMode.SCENE2D) { + rectangleCameraPosition2D(this, rectangle, this.position); + } var mag = Cartesian3.magnitude(this.position); mag += mag * Camera.DEFAULT_VIEW_FACTOR; @@ -1039,7 +1047,14 @@ define([ } if (defined(destination) && defined(destination.west)) { - destination = this.viewRectangle(destination); + if (mode === SceneMode.SCENE3D) { + rectangleCameraPosition3D(this, destination, this.position); + } else if (mode === SceneMode.COLUMBUS_VIEW) { + rectangleCameraPositionColumbusView(this, destination, this.position); + } else if (mode === SceneMode.SCENE2D) { + rectangleCameraPosition2D(this, destination, this.position); + } + destination = undefined; } if (defined(orientation.direction)) { @@ -2073,22 +2088,21 @@ define([ * View a rectangle on an ellipsoid or map. * * @param {Rectangle} rectangle The rectangle to view. + * + * @deprecated */ 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'); - var mode = this._mode; - if (mode === SceneMode.SCENE3D) { - rectangleCameraPosition3D(this, rectangle, this.position); - } else if (mode === SceneMode.COLUMBUS_VIEW) { - rectangleCameraPositionColumbusView(this, rectangle, this.position); - } else if (mode === SceneMode.SCENE2D) { - rectangleCameraPosition2D(this, rectangle, this.position); - } + this.setView({ + destination: rectangle + }); }; var pickEllipsoid3DRay = new Ray(); diff --git a/Specs/Scene/CameraSpec.js b/Specs/Scene/CameraSpec.js index 45ff5be12941..a34805326c27 100644 --- a/Specs/Scene/CameraSpec.js +++ b/Specs/Scene/CameraSpec.js @@ -1514,61 +1514,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); }); @@ -1578,14 +1572,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; @@ -1606,7 +1600,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); @@ -1616,7 +1610,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; @@ -1637,7 +1631,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); @@ -1647,7 +1641,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, @@ -1656,7 +1650,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); From c313e85b6da4edfb40dbbd09c02683f326d26a39 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Fri, 16 Oct 2015 11:25:15 -0400 Subject: [PATCH 12/16] cleanup --- Source/Scene/Camera.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index f7e7c6a276f2..c23c79861eda 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -1046,6 +1046,7 @@ define([ this._setTransform(options.endTransform); } + destination = defaultValue(destination, Cartesian3.clone(this.positionWC, scratchSetViewCartesian)); if (defined(destination) && defined(destination.west)) { if (mode === SceneMode.SCENE3D) { rectangleCameraPosition3D(this, destination, this.position); @@ -1054,11 +1055,10 @@ define([ } else if (mode === SceneMode.SCENE2D) { rectangleCameraPosition2D(this, destination, this.position); } - destination = undefined; + destination = Cartesian3.clone(this.positionWC, scratchSetViewCartesian); } if (defined(orientation.direction)) { - destination = defaultValue(destination, Cartesian3.clone(this.positionWC, scratchSetViewCartesian)); orientation = directionUpToHeadingPitchRoll(this, destination, orientation); } @@ -1066,8 +1066,6 @@ define([ var pitch = mode !== SceneMode.SCENE2D ? defaultValue(orientation.pitch, -CesiumMath.PI_OVER_TWO) : -CesiumMath.PI_OVER_TWO; var roll = defaultValue(orientation.roll, 0.0); - destination = defined(destination) ? destination : Cartesian3.clone(this.positionWC, scratchSetViewCartesian); - if (mode === SceneMode.SCENE3D) { setView3D(this, destination, heading, pitch, roll); } else if (mode === SceneMode.SCENE2D) { From 7431a395f111bed99419eb469323df9580cc3971 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Fri, 16 Oct 2015 12:25:17 -0400 Subject: [PATCH 13/16] fix setview rectangle 2d --- Source/Scene/Camera.js | 41 ++++++++++++++++---------------- Source/Scene/CameraFlightPath.js | 2 +- Specs/Scene/CameraSpec.js | 8 +++---- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index c23c79861eda..1b1709fd169f 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -883,14 +883,16 @@ define([ camera._setTransform(currentTransform); } - function setViewCV(camera, position, heading, pitch, roll) { + function setViewCV(camera, position, heading, pitch, roll, convert) { var currentTransform = Matrix4.clone(camera.transform, scratchSetViewTransform1); camera._setTransform(Matrix4.IDENTITY); if (!Cartesian3.equals(position, camera.positionWC)) { - var projection = camera._projection; - var cartographic = projection.ellipsoid.cartesianToCartographic(position, scratchSetViewCartographic); - position = projection.project(cartographic, scratchSetViewCartesian); + if (convert) { + var projection = camera._projection; + var cartographic = projection.ellipsoid.cartesianToCartographic(position, scratchSetViewCartographic); + position = projection.project(cartographic, scratchSetViewCartesian); + } Cartesian3.clone(position, camera.position); } @@ -904,7 +906,7 @@ define([ camera._setTransform(currentTransform); } - function setView2D(camera, position, heading, pitch, roll) { + function setView2D(camera, position, heading, pitch, roll, convert) { pitch = -CesiumMath.PI_OVER_TWO; roll = 0.0; @@ -912,12 +914,15 @@ define([ camera._setTransform(Matrix4.IDENTITY); if (!Cartesian3.equals(position, camera.positionWC)) { - var projection = camera._projection; - var cartographic = projection.ellipsoid.cartesianToCartographic(position, scratchSetViewCartographic); - position = projection.project(cartographic, scratchSetViewCartesian); + if (convert) { + var projection = camera._projection; + var cartographic = projection.ellipsoid.cartesianToCartographic(position, scratchSetViewCartographic); + position = projection.project(cartographic, scratchSetViewCartesian); + } + Cartesian2.clone(position, camera.position); - var newLeft = -cartographic.height * 0.5; + var newLeft = -position.z * 0.5; var newRight = -newLeft; var frustum = camera.frustum; @@ -1036,7 +1041,6 @@ define([ var projection = this._projection; var ellipsoid = projection.ellipsoid; var destination = options.destination; - var convert = true; if (!defined(destination) && defined(options.positionCartographic)){ destination = ellipsoid.cartographicToCartesian(options.positionCartographic); @@ -1046,16 +1050,11 @@ define([ this._setTransform(options.endTransform); } + var convert = true; destination = defaultValue(destination, Cartesian3.clone(this.positionWC, scratchSetViewCartesian)); if (defined(destination) && defined(destination.west)) { - if (mode === SceneMode.SCENE3D) { - rectangleCameraPosition3D(this, destination, this.position); - } else if (mode === SceneMode.COLUMBUS_VIEW) { - rectangleCameraPositionColumbusView(this, destination, this.position); - } else if (mode === SceneMode.SCENE2D) { - rectangleCameraPosition2D(this, destination, this.position); - } - destination = Cartesian3.clone(this.positionWC, scratchSetViewCartesian); + destination = this.getRectangleCameraCoordinates(destination, new Cartesian3()); + convert = false; } if (defined(orientation.direction)) { @@ -1063,15 +1062,15 @@ define([ } var heading = defaultValue(orientation.heading, 0.0); - var pitch = mode !== SceneMode.SCENE2D ? defaultValue(orientation.pitch, -CesiumMath.PI_OVER_TWO) : -CesiumMath.PI_OVER_TWO; + var pitch = defaultValue(orientation.pitch, -CesiumMath.PI_OVER_TWO); var roll = defaultValue(orientation.roll, 0.0); if (mode === SceneMode.SCENE3D) { setView3D(this, destination, heading, pitch, roll); } else if (mode === SceneMode.SCENE2D) { - setView2D(this, destination, heading, pitch, roll); + setView2D(this, destination, heading, pitch, roll, convert); } else { - setViewCV(this, destination, heading, pitch, roll); + setViewCV(this, destination, heading, pitch, roll, convert); } }; diff --git a/Source/Scene/CameraFlightPath.js b/Source/Scene/CameraFlightPath.js index dfe97e5c1092..1340fee0870e 100644 --- a/Source/Scene/CameraFlightPath.js +++ b/Source/Scene/CameraFlightPath.js @@ -300,7 +300,7 @@ define([ } 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; diff --git a/Specs/Scene/CameraSpec.js b/Specs/Scene/CameraSpec.js index a34805326c27..3120cc55c762 100644 --- a/Specs/Scene/CameraSpec.js +++ b/Specs/Scene/CameraSpec.js @@ -613,10 +613,10 @@ defineSuite([ expect(camera.position.x).toEqual(0); expect(camera.position.y).toEqual(0); - expect(frustum.right - expected <= CesiumMath.EPSILON14).toEqual(true); - expect(frustum.left + expected <= CesiumMath.EPSILON14).toEqual(true); - expect(frustum.top - expected <= CesiumMath.EPSILON14).toEqual(true); - expect(frustum.bottom + expected <= CesiumMath.EPSILON14).toEqual(true); + expect(frustum.right).toEqualEpsilon(expected, CesiumMath.EPSILON14); + expect(frustum.left).toEqualEpsilon(-expected, CesiumMath.EPSILON14); + expect(frustum.top).toEqualEpsilon(expected, CesiumMath.EPSILON14); + expect(frustum.bottom).toEqualEpsilon(-expected, CesiumMath.EPSILON14); }); it('setView with rectangle in Columbus View', function() { From 14115de89aee13feeac86719c61070d495f73de7 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Fri, 16 Oct 2015 13:01:34 -0400 Subject: [PATCH 14/16] cleanup default view --- Source/Scene/Camera.js | 88 +++++++++----------------------- Source/Scene/CameraFlightPath.js | 6 +-- 2 files changed, 24 insertions(+), 70 deletions(-) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index 1b1709fd169f..f8209cd2b1f2 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -212,15 +212,7 @@ define([ this._max2Dfrustum = undefined; // set default view - var rectangle = Camera.DEFAULT_VIEW_RECTANGLE; - var mode = this._mode; - if (mode === SceneMode.SCENE3D) { - rectangleCameraPosition3D(this, rectangle, this.position); - } else if (mode === SceneMode.COLUMBUS_VIEW) { - rectangleCameraPositionColumbusView(this, rectangle, this.position); - } else if (mode === SceneMode.SCENE2D) { - rectangleCameraPosition2D(this, rectangle, this.position); - } + rectangleCameraPosition3D(this, Camera.DEFAULT_VIEW_RECTANGLE, this.position, true); var mag = Cartesian3.magnitude(this.position); mag += mag * Camera.DEFAULT_VIEW_FACTOR; @@ -906,9 +898,9 @@ define([ camera._setTransform(currentTransform); } - function setView2D(camera, position, heading, pitch, roll, convert) { - 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); @@ -1068,7 +1060,7 @@ define([ if (mode === SceneMode.SCENE3D) { setView3D(this, destination, heading, pitch, roll); } else if (mode === SceneMode.SCENE2D) { - setView2D(this, destination, heading, pitch, roll, convert); + setView2D(this, destination, heading, convert); } else { setViewCV(this, destination, heading, pitch, roll, convert); } @@ -1824,12 +1816,9 @@ define([ return opposite / tanThetaOrPhi - Cartesian3.dot(direction, corner); } - function rectangleCameraPosition3D (camera, rectangle, result, positionOnly) { + function rectangleCameraPosition3D (camera, rectangle, result, updateCamera) { var ellipsoid = camera._projection.ellipsoid; - var cameraRF = camera; - if (positionOnly) { - cameraRF = defaultRF; - } + var cameraRF = updateCamera ? camera : defaultRF; var north = rectangle.north; var south = rectangle.south; @@ -1950,70 +1939,52 @@ define([ var viewRectangleCVCartographic = new Cartographic(); var viewRectangleCVNorthEast = new Cartesian3(); var viewRectangleCVSouthWest = new Cartesian3(); - function rectangleCameraPositionColumbusView(camera, rectangle, result, positionOnly) { + function rectangleCameraPositionColumbusView(camera, rectangle, result) { var projection = camera._projection; if (rectangle.west > rectangle.east) { rectangle = Rectangle.MAX_VALUE; } - var north = rectangle.north; - var south = rectangle.south; - var east = rectangle.east; - var west = rectangle.west; 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, result, positionOnly) { + function rectangleCameraPosition2D (camera, rectangle, result) { var projection = camera._projection; if (rectangle.west > rectangle.east) { rectangle = Rectangle.MAX_VALUE; } - var north = rectangle.north; - var south = rectangle.south; - var east = rectangle.east; - var west = rectangle.west; 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; @@ -2035,22 +2006,9 @@ define([ 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; } @@ -2071,11 +2029,11 @@ define([ var mode = this._mode; result = defaultValue(result, new Cartesian3()); if (mode === SceneMode.SCENE3D) { - return rectangleCameraPosition3D(this, rectangle, result, true); + return rectangleCameraPosition3D(this, rectangle, result); } else if (mode === SceneMode.COLUMBUS_VIEW) { - return rectangleCameraPositionColumbusView(this, rectangle, result, true); + return rectangleCameraPositionColumbusView(this, rectangle, result); } else if (mode === SceneMode.SCENE2D) { - return rectangleCameraPosition2D(this, rectangle, result, true); + return rectangleCameraPosition2D(this, rectangle, result); } return undefined; diff --git a/Source/Scene/CameraFlightPath.js b/Source/Scene/CameraFlightPath.js index 1340fee0870e..82928c4aa720 100644 --- a/Source/Scene/CameraFlightPath.js +++ b/Source/Scene/CameraFlightPath.js @@ -196,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); @@ -208,9 +206,7 @@ define([ camera.setView({ orientation: { - heading : CesiumMath.lerp(startHeading, heading, time), - pitch : CesiumMath.lerp(startPitch, pitch, time), - roll : CesiumMath.lerp(startRoll, roll, time) + heading : CesiumMath.lerp(startHeading, heading, time) } }); From 17c5a794f6d808e5475a01304fb65f0c73c72e34 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Fri, 16 Oct 2015 13:05:26 -0400 Subject: [PATCH 15/16] remove duplicate tests --- Specs/Scene/CameraSpec.js | 73 --------------------------------------- 1 file changed, 73 deletions(-) diff --git a/Specs/Scene/CameraSpec.js b/Specs/Scene/CameraSpec.js index 3120cc55c762..26c74b924e30 100644 --- a/Specs/Scene/CameraSpec.js +++ b/Specs/Scene/CameraSpec.js @@ -585,79 +585,6 @@ defineSuite([ expect(camera.right).toEqualEpsilon(Cartesian3.cross(camera.direction, camera.up, new Cartesian3()), CesiumMath.EPSILON6); }); - - it('setView with rectangle in 2D', function() { - var frustum = new OrthographicFrustum(); - frustum.left = -10.0; - frustum.right = 10.0; - frustum.bottom = -10.0; - frustum.top = 10.0; - frustum.near = 1.0; - frustum.far = 21.0; - camera.frustum = frustum; - - var rectangle = new Rectangle( - -CesiumMath.PI_OVER_TWO, - -CesiumMath.PI_OVER_FOUR, - CesiumMath.PI_OVER_TWO, - CesiumMath.PI_OVER_FOUR); - var projection = new GeographicProjection(); - var edge = projection.project(new Cartographic(CesiumMath.PI_OVER_TWO, CesiumMath.PI_OVER_FOUR)); - var expected = Math.max(edge.x, edge.y); - - camera._mode = SceneMode.SCENE2D; - camera._projection = projection; - camera.setView({ - destination: rectangle - }); - - expect(camera.position.x).toEqual(0); - expect(camera.position.y).toEqual(0); - expect(frustum.right).toEqualEpsilon(expected, CesiumMath.EPSILON14); - expect(frustum.left).toEqualEpsilon(-expected, CesiumMath.EPSILON14); - expect(frustum.top).toEqualEpsilon(expected, CesiumMath.EPSILON14); - expect(frustum.bottom).toEqualEpsilon(-expected, CesiumMath.EPSILON14); - }); - - it('setView with rectangle in Columbus View', function() { - var rectangle = new Rectangle( - -CesiumMath.PI_OVER_TWO, - -CesiumMath.PI_OVER_TWO, - CesiumMath.PI_OVER_TWO, - CesiumMath.PI_OVER_TWO); - var projection = new GeographicProjection(); - camera._mode = SceneMode.COLUMBUS_VIEW; - camera._projection = projection; - 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); - expect(camera.right).toEqualEpsilon(new Cartesian3(1.0, 0.0, 0.0), CesiumMath.EPSILON10); - - }); - - it('setView with rectangle in 3D', function() { - camera._mode = SceneMode.SCENE3D; - - var rectangle = new Rectangle( - -Math.PI, - -CesiumMath.PI_OVER_TWO, - Math.PI, - CesiumMath.PI_OVER_TWO); - - var cartesian = Cartesian3.fromDegrees(-75.0, 0.0, 100.0); - 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('setView right rotation order', function() { var position = Cartesian3.fromDegrees(-117.16, 32.71, 0.0); var heading = CesiumMath.toRadians(180.0); From b60eec46a4a4d07de8a8beed7a7247663170ada3 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Wed, 21 Oct 2015 13:49:18 -0400 Subject: [PATCH 16/16] Minor doc/formatting/scratch variable fixes. --- Source/Scene/Camera.js | 118 ++++++++++++++++++++++++-------------- Specs/Scene/CameraSpec.js | 2 +- 2 files changed, 76 insertions(+), 44 deletions(-) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index f8209cd2b1f2..fc6d69ec5d05 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -936,9 +936,13 @@ define([ camera._setTransform(currentTransform); } - function directionUpToHeadingPitchRoll(camera, position, orientation) { - var direction = Cartesian3.clone(orientation.direction, scratchFlyDirection); - var up = Cartesian3.clone(orientation.up, scratchFlyUp); + 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; @@ -949,25 +953,36 @@ define([ Matrix4.multiplyByPointAsVector(invTransform, up, up); } - var right = Cartesian3.cross(direction, up, scratchFlyRight); + var right = Cartesian3.cross(direction, up, scratchToHPRRight); - return { - heading: getHeading(direction, up), - pitch: getPitch(direction), - roll: getRoll(direction, up, right) - }; + 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, orientation and transform. * * @param {Object} options Object with the following properties: - * @param {Object} options Object with the following properties: * @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 the camera will be in when the flight is completed. + * @param {Matrix4} [options.endTransform] Transform matrix representing the reference frame of the camera. * * @example * // 1. Set position with a top-down view @@ -976,7 +991,7 @@ define([ * }); * * // 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) @@ -986,7 +1001,7 @@ define([ * }); * * // 3. Change heading, pitch and roll with the camera position remaining the same. - * camera.setView({ + * 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) @@ -1011,46 +1026,59 @@ define([ */ Camera.prototype.setView = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); - var orientation = defaultValue(options.orientation, {}); - if (defined(options.heading) || defined(options.pitch) || defined(options.roll)){ + 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.'); - orientation.heading = defaultValue(options.heading, this.heading); - orientation.pitch = defaultValue(options.pitch, this.pitch); - orientation.roll = defaultValue(options.roll, this.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.positionCartographic)){ + + if (defined(options.position)) { deprecationWarning('Camera.setView options', 'options.position has been renamed to options.destination.'); - } - if (defined(options.position)){ - deprecationWarning('Camera.setView options', 'options.positionCartographic has been deprecated. Convert to a Cartesian3 and use options.position instead.'); 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; } - var projection = this._projection; - var ellipsoid = projection.ellipsoid; - var destination = options.destination; - if (!defined(destination) && defined(options.positionCartographic)){ - destination = ellipsoid.cartographicToCartesian(options.positionCartographic); - - } if (defined(options.endTransform)) { this._setTransform(options.endTransform); } var convert = true; - destination = defaultValue(destination, Cartesian3.clone(this.positionWC, scratchSetViewCartesian)); + var destination = defaultValue(options.destination, Cartesian3.clone(this.positionWC, scratchSetViewCartesian)); if (defined(destination) && defined(destination.west)) { - destination = this.getRectangleCameraCoordinates(destination, new Cartesian3()); + destination = this.getRectangleCameraCoordinates(destination, scratchSetViewCartesian); convert = false; } if (defined(orientation.direction)) { - orientation = directionUpToHeadingPitchRoll(this, destination, orientation); + orientation = directionUpToHeadingPitchRoll(this, destination, orientation, scratchSetViewOptions.orientation); } var heading = defaultValue(orientation.heading, 0.0); @@ -2027,7 +2055,11 @@ define([ } //>>includeEnd('debug'); var mode = this._mode; - result = defaultValue(result, new Cartesian3()); + + if (!defined(result)) { + result = new Cartesian3(); + } + if (mode === SceneMode.SCENE3D) { return rectangleCameraPosition3D(this, rectangle, result); } else if (mode === SceneMode.COLUMBUS_VIEW) { @@ -2396,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. * @@ -2457,21 +2485,25 @@ define([ throw new DeveloperError('destination is required.'); } //>>includeEnd('debug'); + var mode = this._mode; if (mode === SceneMode.MORPHING) { return; } + var orientation = defaultValue(options.orientation, defaultValue.EMPTY_OBJECT); if (defined(orientation.direction)) { - orientation = directionUpToHeadingPitchRoll(this, destination, orientation); + orientation = directionUpToHeadingPitchRoll(this, destination, orientation, scratchSetViewOptions.orientation); } if (defined(options.duration) && options.duration <= 0.0) { - this.setView({ - position: options.destination, - orientation: orientation, - endTransform: options.endTransform - }); + 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(); } diff --git a/Specs/Scene/CameraSpec.js b/Specs/Scene/CameraSpec.js index 26c74b924e30..1203f3ad61be 100644 --- a/Specs/Scene/CameraSpec.js +++ b/Specs/Scene/CameraSpec.js @@ -494,7 +494,7 @@ 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({