Skip to content

Commit f0789fd

Browse files
committed
Merge pull request #2458 from AnalyticalGraphicsInc/pick-2D
2D Picking
2 parents 8c46dd8 + 7dbce0d commit f0789fd

File tree

4 files changed

+19
-21
lines changed

4 files changed

+19
-21
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Change Log
5959
* 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.
6060
* Many Sandcastle examples have been rewritten to make use of the newly improved Entity API.
6161
* 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.
62+
* Fixed picking in 2D. [#2447](https://github.com/AnalyticalGraphicsInc/cesium/issues/2447)
6263

6364
### 1.5 - 2015-01-05
6465

Source/Scene/Globe.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -801,11 +801,6 @@ define([
801801
enabled : true
802802
}
803803
});
804-
this._depthCommand.renderState = context.createRenderState({
805-
cull : {
806-
enabled : true
807-
}
808-
});
809804
}
810805
}
811806

@@ -935,7 +930,7 @@ define([
935930
}
936931
}
937932

938-
if (pass.pick) {
933+
if (pass.pick && mode === SceneMode.SCENE3D) {
939934
// Not actually pickable, but render depth-only so primitives on the backface
940935
// of the globe are not picked.
941936
commandList.push(this._depthCommand);

Source/Scene/Scene.js

+6
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,7 @@ define([
14321432
var scratchDirection = new Cartesian3();
14331433
var scratchBufferDimensions = new Cartesian2();
14341434
var scratchPixelSize = new Cartesian2();
1435+
var scratchPickVolumeMatrix4 = new Matrix4();
14351436

14361437
function getPickOrthographicCullingVolume(scene, drawingBufferPosition, width, height) {
14371438
var camera = scene._camera;
@@ -1445,12 +1446,17 @@ define([
14451446
var y = (2.0 / drawingBufferHeight) * (drawingBufferHeight - drawingBufferPosition.y) - 1.0;
14461447
y *= (frustum.top - frustum.bottom) * 0.5;
14471448

1449+
var transform = Matrix4.clone(camera.transform, scratchPickVolumeMatrix4);
1450+
camera._setTransform(Matrix4.IDENTITY);
1451+
14481452
var origin = Cartesian3.clone(camera.position, scratchOrigin);
14491453
Cartesian3.multiplyByScalar(camera.right, x, scratchDirection);
14501454
Cartesian3.add(scratchDirection, origin, origin);
14511455
Cartesian3.multiplyByScalar(camera.up, y, scratchDirection);
14521456
Cartesian3.add(scratchDirection, origin, origin);
14531457

1458+
camera._setTransform(transform);
1459+
14541460
Cartesian3.fromElements(origin.z, origin.x, origin.y, origin);
14551461

14561462
scratchBufferDimensions.x = drawingBufferWidth;

Specs/Scene/PickSpec.js

+11-15
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,11 @@ defineSuite([
165165
var ellipsoid = scene.mapProjection.ellipsoid;
166166
var maxRadii = ellipsoid.maximumRadius;
167167

168-
camera.lookAtTransform(new Matrix4(0.0, 0.0, 1.0, 0.0,
169-
1.0, 0.0, 0.0, 0.0,
170-
0.0, 1.0, 0.0, 0.0,
171-
0.0, 0.0, 0.0, 1.0));
172-
173168
camera.position = new Cartesian3(0.0, 0.0, 2.0 * maxRadii);
174-
camera.direction = Cartesian3.normalize(Cartesian3.negate(camera.position, new Cartesian3()), new Cartesian3());
175-
camera.up = Cartesian3.clone(Cartesian3.UNIT_Y);
169+
Cartesian3.clone(Cartesian3.UNIT_Z, camera.direction);
170+
Cartesian3.negate(camera.direction, camera.direction);
171+
Cartesian3.negate(Cartesian3.UNIT_X, camera.up);
172+
Cartesian3.clone(Cartesian3.UNIT_Y, camera.right);
176173

177174
var frustum = new OrthographicFrustum();
178175
frustum.right = maxRadii * Math.PI;
@@ -187,6 +184,7 @@ defineSuite([
187184
scene.morphTime = SceneMode.getMorphTime(scene.mode);
188185

189186
var rectangle = createRectangle();
187+
scene.initializeFrame();
190188
var pickedObject = scene.pick(new Cartesian2(0, 0));
191189
expect(pickedObject.primitive).toEqual(rectangle);
192190
});
@@ -195,14 +193,11 @@ defineSuite([
195193
var ellipsoid = scene.mapProjection.ellipsoid;
196194
var maxRadii = ellipsoid.maximumRadius;
197195

198-
camera.lookAtTransform(new Matrix4(0.0, 0.0, 1.0, 0.0,
199-
1.0, 0.0, 0.0, 0.0,
200-
0.0, 1.0, 0.0, 0.0,
201-
0.0, 0.0, 0.0, 1.0));
202-
203196
camera.position = new Cartesian3(0.0, 0.0, 2.0 * maxRadii);
204-
camera.direction = Cartesian3.normalize(Cartesian3.negate(camera.position, new Cartesian3()), new Cartesian3());
205-
camera.up = Cartesian3.negate(Cartesian3.UNIT_X, new Cartesian3());
197+
Cartesian3.clone(Cartesian3.UNIT_Z, camera.direction);
198+
Cartesian3.negate(camera.direction, camera.direction);
199+
Cartesian3.negate(Cartesian3.UNIT_X, camera.up);
200+
Cartesian3.clone(Cartesian3.UNIT_Y, camera.right);
206201

207202
var frustum = new OrthographicFrustum();
208203
frustum.right = maxRadii * Math.PI;
@@ -217,7 +212,8 @@ defineSuite([
217212
scene.morphTime = SceneMode.getMorphTime(scene.mode);
218213

219214
var rectangle = createRectangle();
220-
var pickedObject = scene.pick(new Cartesian2(0, 0));
215+
scene.initializeFrame();
216+
var pickedObject = scene.pick(new Cartesian2(0.0, 0.0));
221217
expect(pickedObject.primitive).toEqual(rectangle);
222218
});
223219
}, 'WebGL');

0 commit comments

Comments
 (0)