From 2f0b6a42df4c55c790bd44e2e556d54f471b5e2e Mon Sep 17 00:00:00 2001 From: hpinkos Date: Tue, 28 May 2013 17:45:01 -0400 Subject: [PATCH 01/11] change home button to use camera flights --- Source/Widgets/HomeButton/HomeButton.js | 2 +- .../Widgets/HomeButton/HomeButtonViewModel.js | 59 ++++++++++--------- .../HomeButton/HomeButtonViewModelSpec.js | 4 ++ 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/Source/Widgets/HomeButton/HomeButton.js b/Source/Widgets/HomeButton/HomeButton.js index 9c1c04a2ce01..d4e444cc1f5b 100644 --- a/Source/Widgets/HomeButton/HomeButton.js +++ b/Source/Widgets/HomeButton/HomeButton.js @@ -49,7 +49,7 @@ define(['./HomeButtonViewModel', * @memberof HomeButton * @type {HomeButtonViewModel} */ - this.viewModel = new HomeButtonViewModel(scene, transitioner, ellipsoid); + this.viewModel = new HomeButtonViewModel(scene, transitioner, ellipsoid, 1500); /** * Gets the container element for the widget. diff --git a/Source/Widgets/HomeButton/HomeButtonViewModel.js b/Source/Widgets/HomeButton/HomeButtonViewModel.js index a84ab018e1df..bb6da0953503 100644 --- a/Source/Widgets/HomeButton/HomeButtonViewModel.js +++ b/Source/Widgets/HomeButton/HomeButtonViewModel.js @@ -9,6 +9,7 @@ define(['../createCommand', '../../Core/Matrix4', '../../Scene/Camera', '../../Scene/CameraColumbusViewMode', + '../../Scene/CameraFlightPath', '../../Scene/PerspectiveFrustum', '../../Scene/SceneMode', '../../ThirdParty/knockout' @@ -23,12 +24,13 @@ define(['../createCommand', Matrix4, Camera, CameraColumbusViewMode, + CameraFlightPath, PerspectiveFrustum, SceneMode, knockout) { "use strict"; - function viewHome(scene, ellipsoid, transitioner) { + function viewHome(scene, ellipsoid, transitioner, flightDuration) { var mode = scene.mode; var camera = scene.getCamera(); @@ -44,41 +46,41 @@ define(['../createCommand', if (typeof transitioner !== 'undefined' && mode === SceneMode.MORPHING) { transitioner.completeMorph(); } - + var flight; + var description; if (mode === SceneMode.SCENE2D) { - camera.controller.viewExtent(Extent.MAX_VALUE); + description = { + destination: Extent.MAX_VALUE, + duration: flightDuration + }; + flight = CameraFlightPath.createAnimationExtent(scene.getFrameState(), description); + scene.getAnimations().add(flight); } else if (mode === SceneMode.SCENE3D) { var defaultCamera = new Camera(canvas); - defaultCamera.position.clone(camera.position); - defaultCamera.direction.clone(camera.direction); - defaultCamera.up.clone(camera.up); - defaultCamera.right.clone(camera.right); - defaultCamera.transform.clone(camera.transform); - defaultCamera.frustum.clone(camera.frustum); + description = { + destination: defaultCamera.position, + duration: flightDuration, + up: defaultCamera.up, + direction: defaultCamera.direction + }; + flight = CameraFlightPath.createAnimation(scene.getFrameState(), description); + scene.getAnimations().add(flight); } else if (mode === SceneMode.COLUMBUS_VIEW) { - var transform = new Matrix4(0.0, 0.0, 1.0, 0.0, - 1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 1.0); - var maxRadii = ellipsoid.getMaximumRadius(); var position = new Cartesian3(0.0, -1.0, 1.0).normalize().multiplyByScalar(5.0 * maxRadii); var direction = Cartesian3.ZERO.subtract(position).normalize(); var right = direction.cross(Cartesian3.UNIT_Z); var up = right.cross(direction); - right = direction.cross(up); - direction = up.cross(right); - var frustum = new PerspectiveFrustum(); - frustum.fovy = CesiumMath.toRadians(60.0); - frustum.aspectRatio = canvas.clientWidth / canvas.clientHeight; + description = { + destination: position, + duration: flightDuration, + up: up, + direction: direction + }; - camera.position = position; - camera.direction = direction; - camera.up = up; - camera.right = right; - camera.frustum = frustum; - camera.transform = transform; + flight = CameraFlightPath.createAnimation(scene.getFrameState(), description); + scene.getAnimations().add(flight); } } @@ -90,10 +92,11 @@ define(['../createCommand', * @param {Scene} scene The Scene instance to use. * @param {SceneTransitioner} [transitioner] The SceneTransitioner instance to use. * @param {Ellipsoid} [ellipsoid] The Scene's primary ellipsoid. + * @param {Number} [flightDuration] The duration of the camera flight (in ms) * * @exception {Scene} scene is required. */ - var HomeButtonViewModel = function(scene, transitioner, ellipsoid) { + var HomeButtonViewModel = function(scene, transitioner, ellipsoid, flightDuration) { var that = this; if (typeof scene === 'undefined') { @@ -120,12 +123,14 @@ define(['../createCommand', */ this.transitioner = transitioner; + this.flightDuration = flightDuration; + /** * The command for switching to home view. * @type Command */ this.command = createCommand(function() { - viewHome(that.scene, that.ellipsoid, that.transitioner); + viewHome(that.scene, that.ellipsoid, that.transitioner, flightDuration); }); /** diff --git a/Specs/Widgets/HomeButton/HomeButtonViewModelSpec.js b/Specs/Widgets/HomeButton/HomeButtonViewModelSpec.js index 59ab01f23fec..170cc17a933c 100644 --- a/Specs/Widgets/HomeButton/HomeButtonViewModelSpec.js +++ b/Specs/Widgets/HomeButton/HomeButtonViewModelSpec.js @@ -51,23 +51,27 @@ defineSuite([ //The actual position of the camera at the end of the command is //tied to the implementation of various camera features. it('works in 3D', function() { + scene.render(); var viewModel = new HomeButtonViewModel(scene, transitioner); viewModel.command(); }); it('works in 2D', function() { + scene.render(); var viewModel = new HomeButtonViewModel(scene, transitioner); transitioner.to2D(); viewModel.command(); }); it('works in Columbus View', function() { + scene.render(); var viewModel = new HomeButtonViewModel(scene, transitioner); transitioner.toColumbusView(); viewModel.command(); }); it('works while morphing', function() { + scene.render(); var viewModel = new HomeButtonViewModel(scene, transitioner); transitioner.morphToColumbusView(); viewModel.command(); From c7d66e3c9ca561c51a028e4556339599f5bcc2bc Mon Sep 17 00:00:00 2001 From: hpinkos Date: Wed, 29 May 2013 11:11:47 -0400 Subject: [PATCH 02/11] minor changes --- Source/Widgets/HomeButton/HomeButtonViewModel.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Source/Widgets/HomeButton/HomeButtonViewModel.js b/Source/Widgets/HomeButton/HomeButtonViewModel.js index bb6da0953503..db89d2225527 100644 --- a/Source/Widgets/HomeButton/HomeButtonViewModel.js +++ b/Source/Widgets/HomeButton/HomeButtonViewModel.js @@ -51,7 +51,7 @@ define(['../createCommand', if (mode === SceneMode.SCENE2D) { description = { destination: Extent.MAX_VALUE, - duration: flightDuration + duration: flightDuration() }; flight = CameraFlightPath.createAnimationExtent(scene.getFrameState(), description); scene.getAnimations().add(flight); @@ -59,7 +59,7 @@ define(['../createCommand', var defaultCamera = new Camera(canvas); description = { destination: defaultCamera.position, - duration: flightDuration, + duration: flightDuration(), up: defaultCamera.up, direction: defaultCamera.direction }; @@ -74,7 +74,7 @@ define(['../createCommand', description = { destination: position, - duration: flightDuration, + duration: flightDuration(), up: up, direction: direction }; @@ -92,7 +92,7 @@ define(['../createCommand', * @param {Scene} scene The Scene instance to use. * @param {SceneTransitioner} [transitioner] The SceneTransitioner instance to use. * @param {Ellipsoid} [ellipsoid] The Scene's primary ellipsoid. - * @param {Number} [flightDuration] The duration of the camera flight (in ms) + * @param {Number} [flightDuration] The duration of the camera flight in milliseconds * * @exception {Scene} scene is required. */ @@ -123,14 +123,17 @@ define(['../createCommand', */ this.transitioner = transitioner; - this.flightDuration = flightDuration; + /** + * Gets an Observable whose value is the duration in milliseconds of the flight to home position. + */ + this.flightDuration = knockout.observable(flightDuration); /** * The command for switching to home view. * @type Command */ this.command = createCommand(function() { - viewHome(that.scene, that.ellipsoid, that.transitioner, flightDuration); + viewHome(that.scene, that.ellipsoid, that.transitioner, that.flightDuration); }); /** From 5e26f3612908d581f6aaad807d41932373c5a78f Mon Sep 17 00:00:00 2001 From: hpinkos Date: Wed, 29 May 2013 13:22:51 -0400 Subject: [PATCH 03/11] doc --- Source/Widgets/HomeButton/HomeButtonViewModel.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Widgets/HomeButton/HomeButtonViewModel.js b/Source/Widgets/HomeButton/HomeButtonViewModel.js index db89d2225527..d634c0ed121a 100644 --- a/Source/Widgets/HomeButton/HomeButtonViewModel.js +++ b/Source/Widgets/HomeButton/HomeButtonViewModel.js @@ -125,6 +125,7 @@ define(['../createCommand', /** * Gets an Observable whose value is the duration in milliseconds of the flight to home position. + * @type Observable */ this.flightDuration = knockout.observable(flightDuration); From 96035139212c5438ebdbd2c1070ce2ea7acbe2bb Mon Sep 17 00:00:00 2001 From: hpinkos Date: Wed, 29 May 2013 15:22:47 -0400 Subject: [PATCH 04/11] change flight duration call --- Source/Widgets/HomeButton/HomeButtonViewModel.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Widgets/HomeButton/HomeButtonViewModel.js b/Source/Widgets/HomeButton/HomeButtonViewModel.js index d634c0ed121a..db05007252fe 100644 --- a/Source/Widgets/HomeButton/HomeButtonViewModel.js +++ b/Source/Widgets/HomeButton/HomeButtonViewModel.js @@ -51,7 +51,7 @@ define(['../createCommand', if (mode === SceneMode.SCENE2D) { description = { destination: Extent.MAX_VALUE, - duration: flightDuration() + duration: flightDuration }; flight = CameraFlightPath.createAnimationExtent(scene.getFrameState(), description); scene.getAnimations().add(flight); @@ -59,7 +59,7 @@ define(['../createCommand', var defaultCamera = new Camera(canvas); description = { destination: defaultCamera.position, - duration: flightDuration(), + duration: flightDuration, up: defaultCamera.up, direction: defaultCamera.direction }; @@ -74,7 +74,7 @@ define(['../createCommand', description = { destination: position, - duration: flightDuration(), + duration: flightDuration, up: up, direction: direction }; @@ -134,7 +134,7 @@ define(['../createCommand', * @type Command */ this.command = createCommand(function() { - viewHome(that.scene, that.ellipsoid, that.transitioner, that.flightDuration); + viewHome(that.scene, that.ellipsoid, that.transitioner, that.flightDuration()); }); /** From 6b38462b12ff88e169f8286666ef3680f76e4e8e Mon Sep 17 00:00:00 2001 From: hpinkos Date: Wed, 29 May 2013 16:42:57 -0400 Subject: [PATCH 05/11] correct camera.transform --- Source/Widgets/HomeButton/HomeButtonViewModel.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Source/Widgets/HomeButton/HomeButtonViewModel.js b/Source/Widgets/HomeButton/HomeButtonViewModel.js index db05007252fe..96c3a457ab85 100644 --- a/Source/Widgets/HomeButton/HomeButtonViewModel.js +++ b/Source/Widgets/HomeButton/HomeButtonViewModel.js @@ -48,7 +48,12 @@ define(['../createCommand', } var flight; var description; + if (mode === SceneMode.SCENE2D) { + camera.transform = new Matrix4(0, 0, 1, 0, + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 0, 1); description = { destination: Extent.MAX_VALUE, duration: flightDuration @@ -56,6 +61,12 @@ define(['../createCommand', flight = CameraFlightPath.createAnimationExtent(scene.getFrameState(), description); scene.getAnimations().add(flight); } else if (mode === SceneMode.SCENE3D) { + Cartesian3.add(camera.position, Matrix4.getTranslation(camera.transform), camera.position); + var rotation = Matrix4.getRotation(camera.transform); + rotation.multiplyByVector(camera.direction, camera.direction); + rotation.multiplyByVector(camera.up, camera.up); + rotation.multiplyByVector(camera.right, camera.right); + camera.transform = Matrix4.IDENTITY.clone(); var defaultCamera = new Camera(canvas); description = { destination: defaultCamera.position, @@ -66,6 +77,10 @@ define(['../createCommand', flight = CameraFlightPath.createAnimation(scene.getFrameState(), description); scene.getAnimations().add(flight); } else if (mode === SceneMode.COLUMBUS_VIEW) { + camera.transform = new Matrix4(0.0, 0.0, 1.0, 0.0, + 1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 1.0); var maxRadii = ellipsoid.getMaximumRadius(); var position = new Cartesian3(0.0, -1.0, 1.0).normalize().multiplyByScalar(5.0 * maxRadii); var direction = Cartesian3.ZERO.subtract(position).normalize(); From 2813901f9c24a7ecac879aea8fbcff8ca203ae80 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Wed, 29 May 2013 17:58:05 -0400 Subject: [PATCH 06/11] go to destination if duration <= 0 --- Source/Scene/AnimationCollection.js | 2 +- Source/Scene/CameraFlightPath.js | 68 +++++++++++++++++++++++++---- 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/Source/Scene/AnimationCollection.js b/Source/Scene/AnimationCollection.js index 1ba0a5610119..68a89857455e 100644 --- a/Source/Scene/AnimationCollection.js +++ b/Source/Scene/AnimationCollection.js @@ -35,7 +35,7 @@ define([ throw new DeveloperError('duration is required.'); } - if (options.duration !== 0) { + if (options.duration > 0) { var delayDuration = defaultValue(options.delayDuration, 0); var easingFunction = defaultValue(options.easingFunction, Tween.Easing.Linear.None); diff --git a/Source/Scene/CameraFlightPath.js b/Source/Scene/CameraFlightPath.js index 294eff8d034d..7849574bb7bd 100644 --- a/Source/Scene/CameraFlightPath.js +++ b/Source/Scene/CameraFlightPath.js @@ -412,6 +412,9 @@ define([ * @see Scene#getFrameState * @see Scene#getAnimations */ + var dirScratch = new Cartesian3(); + var rightScratch = new Cartesian3(); + var upScratch = new Cartesian3(); CameraFlightPath.createAnimation = function(frameState, description) { description = defaultValue(description, defaultValue.EMPTY_OBJECT); var destination = description.destination; @@ -432,9 +435,52 @@ define([ var onComplete = description.onComplete; if (Cartesian3.equalsEpsilon(destination, frameState.camera.position, CesiumMath.EPSILON6)) { + if (frameState.mode !== SceneMode.SCENE2D) { + return { + duration : 0, + onComplete : onComplete + }; + } + } + + if (duration <= 0) { + var newOnComplete = function() { + var position = destination; + if (frameState.mode === SceneMode.SCENE3D) { + dirScratch = defaultValue(description.direction, position.negate(dirScratch).normalize(dirScratch)); + rightScratch = dirScratch.cross(Cartesian3.UNIT_Z, rightScratch).normalize(rightScratch); + upScratch = defaultValue(description.up, rightScratch.cross(dirScratch, upScratch)); + } else { + dirScratch = defaultValue(description.direction, Cartesian3.UNIT_Z.negate(dirScratch)); + rightScratch = dirScratch.cross(Cartesian3.UNIT_Y, rightScratch).normalize(rightScratch); + upScratch = defaultValue(description.up, rightScratch.cross(dirScratch, upScratch)); + } + + frameState.camera.position = position; + frameState.camera.direction = dirScratch; + frameState.camera.up = upScratch; + frameState.camera.right = rightScratch; + + if (frameState.mode === SceneMode.SCENE2D) { + var zoom = frameState.camera.position.z; + + var frustum = frameState.camera.frustum; + var ratio = frustum.top / frustum.right; + + var incrementAmount = (zoom - (frustum.right - frustum.left)) * 0.5; + frustum.right += incrementAmount; + frustum.left -= incrementAmount; + frustum.top = ratio * frustum.right; + frustum.bottom = -frustum.top; + } + + if (typeof onComplete === 'function') { + onComplete(); + } + }; return { duration : 0, - onComplete : description.onComplete + onComplete : newOnComplete }; } @@ -503,10 +549,12 @@ define([ } if (Cartesian3.equalsEpsilon(c3destination, frameState.camera.position, CesiumMath.EPSILON6)) { - return { - duration : 0, - onComplete : description.onComplete - }; + if (frameState.mode !== SceneMode.SCENE2D) { + return { + duration : 0, + onComplete : description.onComplete + }; + } } var createAnimationDescription = clone(description); @@ -550,10 +598,12 @@ define([ camera.controller.getExtentCameraCoordinates(extent, c3destination); if (Cartesian3.equalsEpsilon(c3destination, frameState.camera.position, CesiumMath.EPSILON6)) { - return { - duration : 0, - onComplete : description.onComplete - }; + if (frameState.mode !== SceneMode.SCENE2D) { + return { + duration : 0, + onComplete : description.onComplete + }; + } } createAnimationDescription.destination = c3destination; From 75a55ed3017e46407b5b84cd5d84b65916ff11d4 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Wed, 29 May 2013 18:09:14 -0400 Subject: [PATCH 07/11] new camera flight path test --- Specs/Scene/CameraFlightPathSpec.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Specs/Scene/CameraFlightPathSpec.js b/Specs/Scene/CameraFlightPathSpec.js index 77eb1b7c34c0..644b40a8ceec 100644 --- a/Specs/Scene/CameraFlightPathSpec.js +++ b/Specs/Scene/CameraFlightPathSpec.js @@ -557,4 +557,26 @@ defineSuite([ expect(camera.direction).toEqual(startDirection); expect(camera.up).toEqual(startUp); }); + + it('creates an animation with 0 duration', function() { + var destination = new Cartesian3(1e9, 1e9, 1e9); + var duration = 0; + var onComplete = function() { + return true; + }; + + var flight = CameraFlightPath.createAnimation(frameState, { + destination : destination, + duration : duration, + onComplete : onComplete + }); + + expect(flight.duration).toEqual(duration); + expect(flight.onComplete).not.toEqual(onComplete); + expect(typeof flight.onUpdate).toEqual('undefined'); + expect(frameState.camera.position).not.toEqual(destination); + flight.onComplete(); + expect(frameState.camera.position).toEqual(destination); + }); + }); \ No newline at end of file From 2641c22b9ae64a79cf805a23a4d778705d7f8850 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Tue, 4 Jun 2013 14:18:17 -0400 Subject: [PATCH 08/11] index on homeButtonCameraFlight: 75a55ed new camera flight path test From e0c442796d8732f90f7ed5f7e0e7423e6df9f620 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Mon, 10 Jun 2013 16:18:45 -0400 Subject: [PATCH 09/11] don't compute animation if 2D destination is the same as current position --- Source/Scene/CameraFlightPath.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Source/Scene/CameraFlightPath.js b/Source/Scene/CameraFlightPath.js index 6fbbcaf38f3a..20ce8e92464e 100644 --- a/Source/Scene/CameraFlightPath.js +++ b/Source/Scene/CameraFlightPath.js @@ -1,5 +1,6 @@ /*global define*/ define([ + '../Core/Cartesian2', '../Core/Cartesian3', '../Core/clone', '../Core/defaultValue', @@ -14,6 +15,7 @@ define([ '../Scene/SceneMode', '../ThirdParty/Tween' ], function( + Cartesian2, Cartesian3, clone, defaultValue, @@ -436,11 +438,7 @@ define([ } } else { var currentHeight = Math.max(frustum.right - frustum.left, frustum.top - frustum.bottom); - var ellipsoid = frameState.scene2D.projection.getEllipsoid(); - var destinationHeight = ellipsoid.cartesianToCartographic(destination).height; - if (CesiumMath.equalsEpsilon(destinationHeight, currentHeight, CesiumMath.EPSILON6) && - CesiumMath.equalsEpsilon(destination.x, frameState.camera.position.x, CesiumMath.EPSILON6) && - CesiumMath.equalsEpsilon(destination.y, frameState.camera.position.y, CesiumMath.EPSILON6)) { + if (Cartesian2.equalsEpsilon(frameState.camera.position, destination, CesiumMath.EPSILON6) && CesiumMath.equalsEpsilon(currentHeight, destination.z, CesiumMath.EPSILON6)) { return { duration : 0, onComplete : onComplete From 8dca6a05de8068135a227eeb071e863b66de604c Mon Sep 17 00:00:00 2001 From: hpinkos Date: Tue, 11 Jun 2013 14:45:41 -0400 Subject: [PATCH 10/11] fix if statement --- Source/Scene/CameraFlightPath.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Source/Scene/CameraFlightPath.js b/Source/Scene/CameraFlightPath.js index 20ce8e92464e..459026416a91 100644 --- a/Source/Scene/CameraFlightPath.js +++ b/Source/Scene/CameraFlightPath.js @@ -429,39 +429,38 @@ define([ var onComplete = description.onComplete; var frustum = frameState.camera.frustum; - if (frameState.mode !== SceneMode.SCENE2D) { - if (Cartesian3.equalsEpsilon(destination, frameState.camera.position, CesiumMath.EPSILON6)) { - return { - duration : 0, - onComplete : onComplete - }; - } - } else { - var currentHeight = Math.max(frustum.right - frustum.left, frustum.top - frustum.bottom); - if (Cartesian2.equalsEpsilon(frameState.camera.position, destination, CesiumMath.EPSILON6) && CesiumMath.equalsEpsilon(currentHeight, destination.z, CesiumMath.EPSILON6)) { + if (frameState.mode === SceneMode.SCENE2D) { + if ((Cartesian2.equalsEpsilon(frameState.camera.position, destination, CesiumMath.EPSILON6)) && (CesiumMath.equalsEpsilon(Math.max(frustum.right - frustum.left, frustum.top - frustum.bottom), destination.z, CesiumMath.EPSILON6))) { return { duration : 0, onComplete : onComplete }; } + } else if (Cartesian3.equalsEpsilon(destination, frameState.camera.position, CesiumMath.EPSILON6)) { + return { + duration : 0, + onComplete : onComplete + }; } if (duration <= 0) { var newOnComplete = function() { var position = destination; if (frameState.mode === SceneMode.SCENE3D) { - dirScratch = defaultValue(description.direction, position.negate(dirScratch).normalize(dirScratch)); if (typeof description.direction === 'undefined' && typeof description.up === 'undefined'){ + dirScratch = position.negate(dirScratch).normalize(dirScratch); rightScratch = dirScratch.cross(Cartesian3.UNIT_Z, rightScratch).normalize(rightScratch); } else { + dirScratch = description.direction; rightScratch = dirScratch.cross(description.up, rightScratch).normalize(rightScratch); } upScratch = defaultValue(description.up, rightScratch.cross(dirScratch, upScratch)); } else { - dirScratch = defaultValue(description.direction, Cartesian3.UNIT_Z.negate(dirScratch)); if (typeof description.direction === 'undefined' && typeof description.up === 'undefined'){ + dirScratch = Cartesian3.UNIT_Z.negate(dirScratch); rightScratch = dirScratch.cross(Cartesian3.UNIT_Y, rightScratch).normalize(rightScratch); } else { + dirScratch = description.direction; rightScratch = dirScratch.cross(description.up, rightScratch).normalize(rightScratch); } upScratch = defaultValue(description.up, rightScratch.cross(dirScratch, upScratch)); From 309f7ed25d36e6611837f85ff3d85b0986f170c3 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Tue, 11 Jun 2013 15:04:30 -0400 Subject: [PATCH 11/11] add more tests --- Source/Scene/CameraFlightPath.js | 18 ---- Specs/Scene/CameraFlightPathSpec.js | 134 ++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+), 18 deletions(-) diff --git a/Source/Scene/CameraFlightPath.js b/Source/Scene/CameraFlightPath.js index 459026416a91..ad6d5241a04b 100644 --- a/Source/Scene/CameraFlightPath.js +++ b/Source/Scene/CameraFlightPath.js @@ -558,15 +558,6 @@ define([ throw new DeveloperError('frameState.mode cannot be SceneMode.MORPHING'); } - if (Cartesian3.equalsEpsilon(c3destination, frameState.camera.position, CesiumMath.EPSILON6)) { - if (frameState.mode !== SceneMode.SCENE2D) { - return { - duration : 0, - onComplete : description.onComplete - }; - } - } - var createAnimationDescription = clone(description); createAnimationDescription.destination = c3destination; return this.createAnimation(frameState, createAnimationDescription); @@ -607,15 +598,6 @@ define([ var camera = frameState.camera; camera.controller.getExtentCameraCoordinates(extent, c3destination); - if (Cartesian3.equalsEpsilon(c3destination, frameState.camera.position, CesiumMath.EPSILON6)) { - if (frameState.mode !== SceneMode.SCENE2D) { - return { - duration : 0, - onComplete : description.onComplete - }; - } - } - createAnimationDescription.destination = c3destination; return this.createAnimation(frameState, createAnimationDescription); }; diff --git a/Specs/Scene/CameraFlightPathSpec.js b/Specs/Scene/CameraFlightPathSpec.js index 644b40a8ceec..e388b791f197 100644 --- a/Specs/Scene/CameraFlightPathSpec.js +++ b/Specs/Scene/CameraFlightPathSpec.js @@ -579,4 +579,138 @@ defineSuite([ expect(frameState.camera.position).toEqual(destination); }); + it('duration is 0 when destination is the same as camera position in 2D', function() { + frameState.mode = SceneMode.SCENE2D; + var camera = frameState.camera; + + camera.position = new Cartesian3(0.0, 0.0, 1000.0); + camera.direction = Cartesian3.UNIT_Z.negate(); + camera.up = Cartesian3.UNIT_Y.clone(); + camera.right = camera.direction.cross(camera.up); + camera.frustum = createOrthographicFrustum(); + var frustum = camera.frustum; + var destination = camera.position.clone(); + destination.z = Math.max(frustum.right - frustum.left, frustum.top - frustum.bottom); + + var flight = CameraFlightPath.createAnimation(frameState, { + destination : destination + }); + + expect(flight.duration).toEqual(0); + }); + + it('duration is 0 when destination is the same as camera position in 3D', function() { + frameState.mode = SceneMode.SCENE3D; + var camera = frameState.camera; + + camera.position = new Cartesian3(0.0, 0.0, 1000.0); + camera.direction = Cartesian3.UNIT_Z.negate(); + camera.up = Cartesian3.UNIT_Y.clone(); + camera.right = camera.direction.cross(camera.up); + camera.frustum = createOrthographicFrustum(); + + var flight = CameraFlightPath.createAnimation(frameState, { + destination : camera.position + }); + + expect(flight.duration).toEqual(0); + }); + + it('duration is 0 when destination is the same as camera position in CV', function() { + frameState.mode = SceneMode.COLUMBUS_VIEW; + var camera = frameState.camera; + + camera.position = new Cartesian3(0.0, 0.0, 1000.0); + camera.direction = Cartesian3.UNIT_Z.negate(); + camera.up = Cartesian3.UNIT_Y.clone(); + camera.right = camera.direction.cross(camera.up); + + var flight = CameraFlightPath.createAnimation(frameState, { + destination : camera.position + }); + + expect(flight.duration).toEqual(0); + }); + + it('creates an animation in 2D 0 duration', function() { + frameState.mode = SceneMode.SCENE2D; + var camera = frameState.camera; + + camera.position = new Cartesian3(0.0, 0.0, 1000.0); + camera.direction = Cartesian3.UNIT_Z.negate(); + camera.up = Cartesian3.UNIT_Y.clone(); + camera.right = camera.direction.cross(camera.up); + camera.frustum = createOrthographicFrustum(); + + var startPosition = camera.position.clone(); + var startDirection = camera.direction.clone(); + var startUp = camera.up.clone(); + + var endPosition = startPosition.add(new Cartesian3(-6e6 * Math.PI, 6e6 * CesiumMath.PI_OVER_FOUR, 100.0)); + var endDirection = startDirection.clone(); + var endUp = startUp.negate(); + + var flight = CameraFlightPath.createAnimation(frameState, { + destination : endPosition, + direction : endDirection, + up : endUp, + duration : 0 + }); + + expect(typeof flight.onComplete).toEqual('function'); + flight.onComplete(); + expect(camera.position.x).toEqualEpsilon(endPosition.x, CesiumMath.EPSILON12); + expect(camera.position.y).toEqualEpsilon(endPosition.y, CesiumMath.EPSILON12); + expect(camera.direction).toEqualEpsilon(endDirection, CesiumMath.EPSILON12); + expect(camera.up).toEqualEpsilon(endUp, CesiumMath.EPSILON12); + expect(camera.frustum.right - camera.frustum.left).toEqual(endPosition.z); + }); + + it('creates an animation in Columbus view 0 duration', function() { + frameState.mode = SceneMode.COLUMBUS_VIEW; + var camera = frameState.camera; + + camera.position = new Cartesian3(0.0, 0.0, 1000.0); + camera.direction = Cartesian3.UNIT_Z.negate(); + camera.up = Cartesian3.UNIT_Y.clone(); + camera.right = camera.direction.cross(camera.up); + + var startPosition = camera.position.clone(); + var endPosition = startPosition.add(new Cartesian3(-6e6 * Math.PI, 6e6 * CesiumMath.PI_OVER_FOUR, 100.0)); + + var flight = CameraFlightPath.createAnimation(frameState, { + destination : endPosition, + duration : 0 + }); + + expect(typeof flight.onComplete).toEqual('function'); + flight.onComplete(); + expect(camera.position).toEqualEpsilon(endPosition, CesiumMath.EPSILON12); + }); + + it('creates an animation in 3d 0 duration', function() { + var camera = frameState.camera; + + var startPosition = camera.position.clone(); + var startDirection = camera.direction.clone(); + var startUp = camera.up.clone(); + + var endPosition = startPosition.negate(); + var endDirection = startDirection.negate(); + var endUp = startUp.negate(); + + var flight = CameraFlightPath.createAnimation(frameState, { + destination : endPosition, + direction : endDirection, + up : endUp, + duration : 0 + }); + + expect(typeof flight.onComplete).toEqual('function'); + flight.onComplete(); + expect(camera.position).toEqualEpsilon(endPosition, CesiumMath.EPSILON12); + expect(camera.direction).toEqualEpsilon(endDirection, CesiumMath.EPSILON12); + expect(camera.up).toEqualEpsilon(endUp, CesiumMath.EPSILON12); + }); + }); \ No newline at end of file