From eeb740c2bcb5dcf8bd30d5c37148608ec9aa7738 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 2 Feb 2015 15:14:39 -0500 Subject: [PATCH 1/4] Remove globe depth rendering and fix pick culling volume in 2D. --- Source/Scene/Globe.js | 7 +------ Source/Scene/Scene.js | 6 ++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Source/Scene/Globe.js b/Source/Scene/Globe.js index 265847de3837..d4c97243abcf 100644 --- a/Source/Scene/Globe.js +++ b/Source/Scene/Globe.js @@ -801,11 +801,6 @@ define([ enabled : true } }); - this._depthCommand.renderState = context.createRenderState({ - cull : { - enabled : true - } - }); } } @@ -935,7 +930,7 @@ define([ } } - if (pass.pick) { + if (pass.pick && mode === SceneMode.SCENE3D) { // Not actually pickable, but render depth-only so primitives on the backface // of the globe are not picked. commandList.push(this._depthCommand); diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index b1297f79f4a1..f6456d7e8517 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -1432,6 +1432,7 @@ define([ var scratchDirection = new Cartesian3(); var scratchBufferDimensions = new Cartesian2(); var scratchPixelSize = new Cartesian2(); + var scratchPickVolumeMatrix4 = new Matrix4(); function getPickOrthographicCullingVolume(scene, drawingBufferPosition, width, height) { var camera = scene._camera; @@ -1445,12 +1446,17 @@ define([ var y = (2.0 / drawingBufferHeight) * (drawingBufferHeight - drawingBufferPosition.y) - 1.0; y *= (frustum.top - frustum.bottom) * 0.5; + var transform = Matrix4.clone(camera.transform, scratchPickVolumeMatrix4); + camera._setTransform(Matrix4.IDENTITY); + var origin = Cartesian3.clone(camera.position, scratchOrigin); Cartesian3.multiplyByScalar(camera.right, x, scratchDirection); Cartesian3.add(scratchDirection, origin, origin); Cartesian3.multiplyByScalar(camera.up, y, scratchDirection); Cartesian3.add(scratchDirection, origin, origin); + camera._setTransform(transform); + Cartesian3.fromElements(origin.z, origin.x, origin.y, origin); scratchBufferDimensions.x = drawingBufferWidth; From b921af230c74ff1ca0593a5b058fdf286dd6e4e0 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 2 Feb 2015 15:17:40 -0500 Subject: [PATCH 2/4] Update CHANGES.md. --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index df341023e8b2..8982da52689a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -59,6 +59,7 @@ Change Log * All Entity and related class can now be assigned using anonymous objects as well as be passed template objects. The correct underlying instance is created for you automatically. * Many Sandcastle examples have been rewritten to make use of the newly improved Entity API. * For a more detailed overview of changes to the Entity API, read [this forum thread](https://groups.google.com/d/msg/cesium-dev/ol7edT6EtZw/a2-gvI4H0IwJ) for details. +* Fixed picking in 2D. [#2447](https://github.com/AnalyticalGraphicsInc/cesium/issues/2447) ### 1.5 - 2015-01-05 From 213b3ac7c81a255636e3e461239f131714367cb4 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 2 Feb 2015 15:52:19 -0500 Subject: [PATCH 3/4] Fix rotated pick in 2D test. --- Source/Scene/Scene.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index f6456d7e8517..76055fbf6086 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -1457,8 +1457,6 @@ define([ camera._setTransform(transform); - Cartesian3.fromElements(origin.z, origin.x, origin.y, origin); - scratchBufferDimensions.x = drawingBufferWidth; scratchBufferDimensions.y = drawingBufferHeight; From 7dbce0d05b945db0b25224da096cc1e40d5cb726 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 2 Feb 2015 16:06:53 -0500 Subject: [PATCH 4/4] Fix rotated pick in 2D test part 2. --- Source/Scene/Scene.js | 2 ++ Specs/Scene/PickSpec.js | 26 +++++++++++--------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 76055fbf6086..f6456d7e8517 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -1457,6 +1457,8 @@ define([ camera._setTransform(transform); + Cartesian3.fromElements(origin.z, origin.x, origin.y, origin); + scratchBufferDimensions.x = drawingBufferWidth; scratchBufferDimensions.y = drawingBufferHeight; diff --git a/Specs/Scene/PickSpec.js b/Specs/Scene/PickSpec.js index 85499bcb4e59..c94d6b0f74a4 100644 --- a/Specs/Scene/PickSpec.js +++ b/Specs/Scene/PickSpec.js @@ -165,14 +165,11 @@ defineSuite([ var ellipsoid = scene.mapProjection.ellipsoid; var maxRadii = ellipsoid.maximumRadius; - camera.lookAtTransform(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)); - camera.position = new Cartesian3(0.0, 0.0, 2.0 * maxRadii); - camera.direction = Cartesian3.normalize(Cartesian3.negate(camera.position, new Cartesian3()), new Cartesian3()); - camera.up = Cartesian3.clone(Cartesian3.UNIT_Y); + Cartesian3.clone(Cartesian3.UNIT_Z, camera.direction); + Cartesian3.negate(camera.direction, camera.direction); + Cartesian3.negate(Cartesian3.UNIT_X, camera.up); + Cartesian3.clone(Cartesian3.UNIT_Y, camera.right); var frustum = new OrthographicFrustum(); frustum.right = maxRadii * Math.PI; @@ -187,6 +184,7 @@ defineSuite([ scene.morphTime = SceneMode.getMorphTime(scene.mode); var rectangle = createRectangle(); + scene.initializeFrame(); var pickedObject = scene.pick(new Cartesian2(0, 0)); expect(pickedObject.primitive).toEqual(rectangle); }); @@ -195,14 +193,11 @@ defineSuite([ var ellipsoid = scene.mapProjection.ellipsoid; var maxRadii = ellipsoid.maximumRadius; - camera.lookAtTransform(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)); - camera.position = new Cartesian3(0.0, 0.0, 2.0 * maxRadii); - camera.direction = Cartesian3.normalize(Cartesian3.negate(camera.position, new Cartesian3()), new Cartesian3()); - camera.up = Cartesian3.negate(Cartesian3.UNIT_X, new Cartesian3()); + Cartesian3.clone(Cartesian3.UNIT_Z, camera.direction); + Cartesian3.negate(camera.direction, camera.direction); + Cartesian3.negate(Cartesian3.UNIT_X, camera.up); + Cartesian3.clone(Cartesian3.UNIT_Y, camera.right); var frustum = new OrthographicFrustum(); frustum.right = maxRadii * Math.PI; @@ -217,7 +212,8 @@ defineSuite([ scene.morphTime = SceneMode.getMorphTime(scene.mode); var rectangle = createRectangle(); - var pickedObject = scene.pick(new Cartesian2(0, 0)); + scene.initializeFrame(); + var pickedObject = scene.pick(new Cartesian2(0.0, 0.0)); expect(pickedObject.primitive).toEqual(rectangle); }); }, 'WebGL');