Skip to content

Commit

Permalink
Merge pull request #6900 from AnalyticalGraphicsInc/pick-ray-2d
Browse files Browse the repository at this point in the history
Fix getPickRay in 2D
  • Loading branch information
Hannah authored Aug 8, 2018
2 parents 0396958 + d72c767 commit 386a498
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Change Log
==========

### 1.49 - 2018-09-03

#### Fixes :wrench:
* Fixed `getPickRay` in 2D. [#2480](https://github.com/AnalyticalGraphicsInc/cesium/issues/2480)

### 1.48 - 2018-08-01

##### Additions :tada:
Expand Down
4 changes: 2 additions & 2 deletions Source/Scene/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -2414,7 +2414,7 @@ define([
function pickMap2D(camera, windowPosition, projection, result) {
var ray = camera.getPickRay(windowPosition, pickEllipsoid2DRay);
var position = ray.origin;
position.z = 0.0;
position = Cartesian3.fromElements(position.y, position.z, 0.0, position);
var cart = projection.unproject(position);

if (cart.latitude < -CesiumMath.PI_OVER_TWO || cart.latitude > CesiumMath.PI_OVER_TWO) {
Expand Down Expand Up @@ -2536,7 +2536,7 @@ define([

Cartesian3.clone(camera.directionWC, result.direction);

if (camera._mode === SceneMode.COLUMBUS_VIEW) {
if (camera._mode === SceneMode.COLUMBUS_VIEW || camera._mode === SceneMode.SCENE2D) {
Cartesian3.fromElements(result.origin.z, result.origin.x, result.origin.y, result.origin);
}

Expand Down
13 changes: 11 additions & 2 deletions Source/Scene/ScreenSpaceCameraController.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,12 @@ define([
object._zoomMouseStart = Cartesian2.clone(startPosition, object._zoomMouseStart);

if (defined(object._globe)) {
pickedPosition = mode !== SceneMode.SCENE2D ? pickGlobe(object, startPosition, scratchPickCartesian) : camera.getPickRay(startPosition, scratchZoomPickRay).origin;
if (mode === SceneMode.SCENE2D) {
pickedPosition = camera.getPickRay(startPosition, scratchZoomPickRay).origin;
pickedPosition = Cartesian3.fromElements(pickedPosition.y, pickedPosition.z, pickedPosition.x);
} else {
pickedPosition = pickGlobe(object, startPosition, scratchPickCartesian);
}
}
if (defined(pickedPosition)) {
object._useZoomWorldPosition = true;
Expand Down Expand Up @@ -552,6 +557,7 @@ define([

if ((camera.position.x < 0.0 && savedX > 0.0) || (camera.position.x > 0.0 && savedX < 0.0)) {
pickedPosition = camera.getPickRay(startPosition, scratchZoomPickRay).origin;
pickedPosition = Cartesian3.fromElements(pickedPosition.y, pickedPosition.z, pickedPosition.x);
object._zoomWorldPosition = Cartesian3.clone(pickedPosition, object._zoomWorldPosition);
}
}
Expand Down Expand Up @@ -692,7 +698,7 @@ define([
}

var rayDirection = ray.direction;
if (mode === SceneMode.COLUMBUS_VIEW) {
if (mode === SceneMode.COLUMBUS_VIEW || mode === SceneMode.SCENE2D) {
Cartesian3.fromElements(rayDirection.y, rayDirection.z, rayDirection.x, rayDirection);
}

Expand All @@ -716,6 +722,9 @@ define([
var start = camera.getPickRay(movement.startPosition, translate2DStart).origin;
var end = camera.getPickRay(movement.endPosition, translate2DEnd).origin;

start = Cartesian3.fromElements(start.y, start.z, start.x, start);
end = Cartesian3.fromElements(end.y, end.z, end.x, end);

var direction = Cartesian3.subtract(start, end, scratchTranslateP0);
var distance = Cartesian3.magnitude(direction);

Expand Down
2 changes: 1 addition & 1 deletion Specs/Scene/CameraSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2261,7 +2261,7 @@ defineSuite([
var ray = camera.getPickRay(windowCoord);

var cameraPosition = camera.position;
var expectedPosition = new Cartesian3(cameraPosition.x + 2.0, cameraPosition.y + 2, cameraPosition.z);
var expectedPosition = new Cartesian3(cameraPosition.z, cameraPosition.x + 2.0, cameraPosition.y + 2.0);
expect(ray.origin).toEqualEpsilon(expectedPosition, CesiumMath.EPSILON14);
expect(ray.direction).toEqual(camera.directionWC);
});
Expand Down

0 comments on commit 386a498

Please sign in to comment.