Skip to content

Commit 669179c

Browse files
author
hpinkos
committed
Merge branch 'globe-pick' of github.com:AnalyticalGraphicsInc/cesium into globe-pick
2 parents 4bbf35e + b796bef commit 669179c

5 files changed

+37
-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.pickProjected(ray, scene, scratchRayIntersection);
10171017

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

Source/Scene/Globe.js

+32-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.pickProjected = function(ray, scene, result) {
418415
//>>includeStart('debug', pragmas.debug);
419416
if (!defined(ray)) {
420417
throw new DeveloperError('ray is required');
@@ -472,6 +469,35 @@ define([
472469
return intersection;
473470
};
474471

472+
var pickScratch = new Cartesian3();
473+
var cartoScratch = new Cartographic();
474+
/**
475+
* Find an intersection between a ray and the globe surface that was rendered. The ray must be given in world coordinates.
476+
*
477+
* @param {Ray} ray The ray to test for intersection.
478+
* @param {Scene} scene The scene.
479+
* @param {Cartesian3} [result] The object onto which to store the result.
480+
* @returns {Cartesian3|undefined} The intersection in world coordinates or <code>undefined</code> if none was found.
481+
*
482+
* @example
483+
* // find intersection of ray through a pixel and the globe
484+
* var ray = viewer.camera.getPickRay(windowCoordinates);
485+
* var intersection = globe.pick(ray, scene);
486+
*/
487+
Globe.prototype.pick = function(ray, scene, result) {
488+
result = this.pickProjected(ray, scene, result);
489+
if (defined(result) && scene.mode === SceneMode.COLUMBUS_VIEW) {
490+
pickScratch.x = result.y;
491+
pickScratch.y = result.z;
492+
pickScratch.z = result.x;
493+
var carto = scene.mapProjection.unproject(pickScratch, cartoScratch);
494+
result = scene.globe.ellipsoid.cartographicToCartesian(carto, result);
495+
}
496+
//TODO: is always undefined for 2D
497+
498+
return result;
499+
};
500+
475501
var scratchGetHeightCartesian = new Cartesian3();
476502
var scratchGetHeightIntersection = new Cartesian3();
477503
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.pickProjected(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.pickProjected(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.pickProjected(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.pickProjected = function() {
6868
return new Cartesian3(0.0, 0.0, 1.0);
6969
};
7070
this._surface = {

0 commit comments

Comments
 (0)