Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2D Picking #2458

Merged
merged 4 commits into from
Feb 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 1 addition & 6 deletions Source/Scene/Globe.js
Original file line number Diff line number Diff line change
Expand Up @@ -801,11 +801,6 @@ define([
enabled : true
}
});
this._depthCommand.renderState = context.createRenderState({
cull : {
enabled : true
}
});
}
}

Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
26 changes: 11 additions & 15 deletions Specs/Scene/PickSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
});
Expand All @@ -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;
Expand All @@ -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');