From 0c9903fd71074366bc402bb267f2ea60fde1f2ad Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Wed, 8 Aug 2018 16:10:57 -0400 Subject: [PATCH 1/3] Fix get pick ray in 2D. --- Source/Scene/Camera.js | 2 +- Source/Scene/ScreenSpaceCameraController.js | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index fcefe4ad9aff..248a7c72888a 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -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); } diff --git a/Source/Scene/ScreenSpaceCameraController.js b/Source/Scene/ScreenSpaceCameraController.js index 319e30b9c811..3e8600ce0c06 100644 --- a/Source/Scene/ScreenSpaceCameraController.js +++ b/Source/Scene/ScreenSpaceCameraController.js @@ -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; @@ -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); } } @@ -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); } @@ -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); From 7ba08a574f6b493959a4a19e5172c7d5a17af603 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Wed, 8 Aug 2018 16:21:21 -0400 Subject: [PATCH 2/3] Fix tests. --- Source/Scene/Camera.js | 2 +- Specs/Scene/CameraSpec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index 248a7c72888a..5ab8934670ae 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -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) { diff --git a/Specs/Scene/CameraSpec.js b/Specs/Scene/CameraSpec.js index 535eb9188f4a..819ba609bf02 100644 --- a/Specs/Scene/CameraSpec.js +++ b/Specs/Scene/CameraSpec.js @@ -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); }); From d72c767106734d2ed58ea77f2546449045670a87 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Wed, 8 Aug 2018 16:23:30 -0400 Subject: [PATCH 3/3] Update CHANGES.md. --- CHANGES.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index d3f4c24cf1eb..7fb533b752bd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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: