diff --git a/CHANGES.md b/CHANGES.md index 9e29bfe3909a..0e9176c17f89 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ Change Log * Added ability to show tile urls in the 3D Tiles Inspector. [#5592](https://github.com/AnalyticalGraphicsInc/cesium/pull/5592) * Added behavior to `Cesium3DTilesInspector` that selects the first tileset hovered over if no tilest is specified. [#5139](https://github.com/AnalyticalGraphicsInc/cesium/issues/5139) +* Added ability to provide a `width` and `height` to `scene.pick`. [#5602](https://github.com/AnalyticalGraphicsInc/cesium/pull/5602) ### 1.35.2 - 2017-07-11 diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index c5b0760c6be6..c35d3099ac1b 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -83,6 +83,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu * [Joel Depooter](https://github.com/JDepooter) * [Bentley Systems, Inc.](https://www.bentley.com) * [Paul Connelly](https://github.com/pmconne) + * [Jason Crow](https://github.com/jason-crow) * [Flightradar24 AB](https://www.flightradar24.com) * [Aleksei Kalmykov](https://github.com/kalmykov) diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 9c52f0f7c97d..d9fb50af9bbb 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -2793,17 +2793,22 @@ define([ * }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); * * @param {Cartesian2} windowPosition Window coordinates to perform picking on. + * @param {Number} [width=3] Width of the pick rectangle. + * @param {Number} [height=3] Height of the pick rectangle. * @returns {Object} Object containing the picked primitive. * * @exception {DeveloperError} windowPosition is undefined. */ - Scene.prototype.pick = function(windowPosition) { + Scene.prototype.pick = function(windowPosition, width, height) { //>>includeStart('debug', pragmas.debug); if(!defined(windowPosition)) { throw new DeveloperError('windowPosition is undefined.'); } //>>includeEnd('debug'); + rectangleWidth = defaultValue(width, 3.0); + rectangleHeight = defaultValue(height, rectangleWidth); + var context = this._context; var us = context.uniformState; var frameState = this._frameState; @@ -2825,7 +2830,8 @@ define([ scratchRectangle.x = drawingBufferPosition.x - ((rectangleWidth - 1.0) * 0.5); scratchRectangle.y = (this.drawingBufferHeight - drawingBufferPosition.y) - ((rectangleHeight - 1.0) * 0.5); - + scratchRectangle.width = rectangleWidth; + scratchRectangle.height = rectangleHeight; var passState = this._pickFramebuffer.begin(scratchRectangle); updateEnvironment(this, passState); diff --git a/Specs/Scene/PickSpec.js b/Specs/Scene/PickSpec.js index 4e2028176b05..84862b392ce4 100644 --- a/Specs/Scene/PickSpec.js +++ b/Specs/Scene/PickSpec.js @@ -10,7 +10,8 @@ defineSuite([ 'Scene/PerspectiveFrustum', 'Scene/Primitive', 'Scene/SceneMode', - 'Specs/createScene' + 'Specs/createScene', + 'Specs/createCanvas' ], 'Scene/Pick', function( FeatureDetection, GeometryInstance, @@ -23,7 +24,8 @@ defineSuite([ PerspectiveFrustum, Primitive, SceneMode, - createScene) { + createScene, + createCanvas) { 'use strict'; var scene; @@ -32,7 +34,9 @@ defineSuite([ var primitiveRectangle = Rectangle.fromDegrees(-1.0, -1.0, 1.0, 1.0); beforeAll(function() { - scene = createScene(); + scene = createScene({ + canvas : createCanvas(10, 10) + }); primitives = scene.primitives; camera = scene.camera; }); @@ -94,6 +98,22 @@ defineSuite([ expect(scene).toPickPrimitive(rectangle); }); + it('picks a primitive with a modified pick search area', function() { + if (FeatureDetection.isInternetExplorer()) { + // Workaround IE 11.0.9. This test fails when all tests are ran without a breakpoint here. + return; + } + + camera.setView({ + destination : Rectangle.fromDegrees(-10.0, -10.0, 10.0, 10.0) + }); + + var rectangle = createRectangle(); + + expect(scene).toPickPrimitive(rectangle, 7, 7, 5); + expect(scene).notToPick(7, 7, 3); + }); + it('does not pick primitives when show is false', function() { var rectangle = createRectangle(); rectangle.show = false; diff --git a/Specs/addDefaultMatchers.js b/Specs/addDefaultMatchers.js index 0435305e18e1..bc12f7465523 100644 --- a/Specs/addDefaultMatchers.js +++ b/Specs/addDefaultMatchers.js @@ -263,16 +263,16 @@ define([ toPickPrimitive : function(util, customEqualityTesters) { return { - compare : function(actual, expected) { - return pickPrimitiveEquals(actual, expected); + compare : function(actual, expected, x, y, width, height) { + return pickPrimitiveEquals(actual, expected, x, y, width, height); } }; }, notToPick : function(util, customEqualityTesters) { return { - compare : function(actual, expected) { - return pickPrimitiveEquals(actual, undefined); + compare : function(actual, expected, x, y, width, height) { + return pickPrimitiveEquals(actual, undefined, x, y, width, height); } }; }, @@ -465,9 +465,10 @@ define([ }; } - function pickPrimitiveEquals(actual, expected) { + function pickPrimitiveEquals(actual, expected, x, y, width, height) { var scene = actual; - var result = scene.pick(new Cartesian2(0, 0)); + var windowPosition = new Cartesian2(x, y); + var result = scene.pick(windowPosition, width, height); if (!!window.webglStub) { return {