Skip to content

Commit 716a86a

Browse files
author
hpinkos
committed
globe pick wc
1 parent 4bbf35e commit 716a86a

5 files changed

+33
-11
lines changed

Source/Scene/Camera.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ define([
10131013
mousePosition.y = scene.drawingBufferHeight / 2.0;
10141014

10151015
var ray = this.getPickRay(mousePosition, pickGlobeScratchRay);
1016-
rayIntersection = globe.pick(ray, scene, scratchRayIntersection);
1016+
rayIntersection = globe.pickWorldCoordinates(ray, scene, scratchRayIntersection);
10171017

10181018
if (scene.pickPositionSupported) {
10191019
depthIntersection = scene.pickPositionWorldCoordinates(mousePosition, scratchDepthIntersection);

Source/Scene/Globe.js

+28-6
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,11 @@ define([
407407
* @param {Ray} ray The ray to test for intersection.
408408
* @param {Scene} scene The scene.
409409
* @param {Cartesian3} [result] The object onto which to store the result.
410-
* @returns {Cartesian3|undefined} The intersection or <code>undefined</code> if none was found.
410+
* @returns {Cartesian3|undefined} The intersection or <code>undefined</code> if none was found. The returned position is in projected coordinates for 2D and Columbus View.
411411
*
412-
* @example
413-
* // find intersection of ray through a pixel and the globe
414-
* var ray = viewer.camera.getPickRay(windowCoordinates);
415-
* var intersection = globe.pick(ray, scene);
412+
* @private
416413
*/
417-
Globe.prototype.pick = function(ray, scene, result) {
414+
Globe.prototype.pickWorldCoordinates = function(ray, scene, result) {
418415
//>>includeStart('debug', pragmas.debug);
419416
if (!defined(ray)) {
420417
throw new DeveloperError('ray is required');
@@ -472,6 +469,31 @@ define([
472469
return intersection;
473470
};
474471

472+
var cartoScratch = new Cartographic();
473+
/**
474+
* Find an intersection between a ray and the globe surface that was rendered. The ray must be given in world coordinates.
475+
*
476+
* @param {Ray} ray The ray to test for intersection.
477+
* @param {Scene} scene The scene.
478+
* @param {Cartesian3} [result] The object onto which to store the result.
479+
* @returns {Cartesian3|undefined} The intersection in world coordinates or <code>undefined</code> if none was found.
480+
*
481+
* @example
482+
* // find intersection of ray through a pixel and the globe
483+
* var ray = viewer.camera.getPickRay(windowCoordinates);
484+
* var intersection = globe.pick(ray, scene);
485+
*/
486+
Globe.prototype.pick = function(ray, scene, result) {
487+
result = this.pickWorldCoordinates(ray, scene, result);
488+
if (defined(result) && scene.mode !== SceneMode.SCENE3D) {
489+
result = Cartesian3.fromElements(result.y, result.z, result.x, result);
490+
var carto = scene.mapProjection.unproject(result, cartoScratch);
491+
result = scene.globe.ellipsoid.cartographicToCartesian(carto, result);
492+
}
493+
494+
return result;
495+
};
496+
475497
var scratchGetHeightCartesian = new Cartesian3();
476498
var scratchGetHeightIntersection = new Cartesian3();
477499
var scratchGetHeightCartographic = new Cartographic();

Source/Scene/SceneTransitioner.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ define([
530530

531531
var globe = scene.globe;
532532
if (defined(globe)) {
533-
var pickPos = globe.pick(ray, scene, scratchCVTo2DPickPos);
533+
var pickPos = globe.pickWorldCoordinates(ray, scene, scratchCVTo2DPickPos);
534534
if (defined(pickPos)) {
535535
Matrix4.multiplyByPoint(Camera.TRANSFORM_2D_INVERSE, pickPos, endPos);
536536
endPos.z += Cartesian3.distance(startPos, endPos);
@@ -634,7 +634,7 @@ define([
634634

635635
var globe = scene.globe;
636636
if (defined(globe)) {
637-
var pickedPos = globe.pick(ray, scene, scratch3DTo2DPickPosition);
637+
var pickedPos = globe.pickWorldCoordinates(ray, scene, scratch3DTo2DPickPosition);
638638
if (defined(pickedPos)) {
639639
var height = Cartesian3.distance(camera2D.position2D, pickedPos);
640640
pickedPos.x += height;

Source/Scene/ScreenSpaceCameraController.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ define([
832832
}
833833

834834
var ray = camera.getPickRay(mousePosition, pickGlobeScratchRay);
835-
var rayIntersection = globe.pick(ray, scene, scratchRayIntersection);
835+
var rayIntersection = globe.pickWorldCoordinates(ray, scene, scratchRayIntersection);
836836

837837
var pickDistance = defined(depthIntersection) ? Cartesian3.distance(depthIntersection, camera.positionWC) : Number.POSITIVE_INFINITY;
838838
var rayDistance = defined(rayIntersection) ? Cartesian3.distance(rayIntersection, camera.positionWC) : Number.POSITIVE_INFINITY;

Specs/Scene/ScreenSpaceCameraControllerSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ defineSuite([
6464
this.getHeight = function(cartographic) {
6565
return 0.0;
6666
};
67-
this.pick = function() {
67+
this.pickWorldCoordinates = function() {
6868
return new Cartesian3(0.0, 0.0, 1.0);
6969
};
7070
this._surface = {

0 commit comments

Comments
 (0)