Skip to content

Commit

Permalink
Merge branch 'globe-pick' of github.com:AnalyticalGraphicsInc/cesium …
Browse files Browse the repository at this point in the history
…into globe-pick
  • Loading branch information
hpinkos committed Jul 31, 2018
2 parents 4bbf35e + b796bef commit 669179c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Source/Scene/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ define([
mousePosition.y = scene.drawingBufferHeight / 2.0;

var ray = this.getPickRay(mousePosition, pickGlobeScratchRay);
rayIntersection = globe.pick(ray, scene, scratchRayIntersection);
rayIntersection = globe.pickProjected(ray, scene, scratchRayIntersection);

if (scene.pickPositionSupported) {
depthIntersection = scene.pickPositionWorldCoordinates(mousePosition, scratchDepthIntersection);
Expand Down
38 changes: 32 additions & 6 deletions Source/Scene/Globe.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,11 @@ define([
* @param {Ray} ray The ray to test for intersection.
* @param {Scene} scene The scene.
* @param {Cartesian3} [result] The object onto which to store the result.
* @returns {Cartesian3|undefined} The intersection or <code>undefined</code> if none was found.
* @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.
*
* @example
* // find intersection of ray through a pixel and the globe
* var ray = viewer.camera.getPickRay(windowCoordinates);
* var intersection = globe.pick(ray, scene);
* @private
*/
Globe.prototype.pick = function(ray, scene, result) {
Globe.prototype.pickProjected = function(ray, scene, result) {
//>>includeStart('debug', pragmas.debug);
if (!defined(ray)) {
throw new DeveloperError('ray is required');
Expand Down Expand Up @@ -472,6 +469,35 @@ define([
return intersection;
};

var pickScratch = new Cartesian3();
var cartoScratch = new Cartographic();
/**
* Find an intersection between a ray and the globe surface that was rendered. The ray must be given in world coordinates.
*
* @param {Ray} ray The ray to test for intersection.
* @param {Scene} scene The scene.
* @param {Cartesian3} [result] The object onto which to store the result.
* @returns {Cartesian3|undefined} The intersection in world coordinates or <code>undefined</code> if none was found.
*
* @example
* // find intersection of ray through a pixel and the globe
* var ray = viewer.camera.getPickRay(windowCoordinates);
* var intersection = globe.pick(ray, scene);
*/
Globe.prototype.pick = function(ray, scene, result) {
result = this.pickProjected(ray, scene, result);
if (defined(result) && scene.mode === SceneMode.COLUMBUS_VIEW) {
pickScratch.x = result.y;
pickScratch.y = result.z;
pickScratch.z = result.x;
var carto = scene.mapProjection.unproject(pickScratch, cartoScratch);
result = scene.globe.ellipsoid.cartographicToCartesian(carto, result);
}
//TODO: is always undefined for 2D

return result;
};

var scratchGetHeightCartesian = new Cartesian3();
var scratchGetHeightIntersection = new Cartesian3();
var scratchGetHeightCartographic = new Cartographic();
Expand Down
4 changes: 2 additions & 2 deletions Source/Scene/SceneTransitioner.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ define([

var globe = scene.globe;
if (defined(globe)) {
var pickPos = globe.pick(ray, scene, scratchCVTo2DPickPos);
var pickPos = globe.pickProjected(ray, scene, scratchCVTo2DPickPos);
if (defined(pickPos)) {
Matrix4.multiplyByPoint(Camera.TRANSFORM_2D_INVERSE, pickPos, endPos);
endPos.z += Cartesian3.distance(startPos, endPos);
Expand Down Expand Up @@ -634,7 +634,7 @@ define([

var globe = scene.globe;
if (defined(globe)) {
var pickedPos = globe.pick(ray, scene, scratch3DTo2DPickPosition);
var pickedPos = globe.pickProjected(ray, scene, scratch3DTo2DPickPosition);
if (defined(pickedPos)) {
var height = Cartesian3.distance(camera2D.position2D, pickedPos);
pickedPos.x += height;
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/ScreenSpaceCameraController.js
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ define([
}

var ray = camera.getPickRay(mousePosition, pickGlobeScratchRay);
var rayIntersection = globe.pick(ray, scene, scratchRayIntersection);
var rayIntersection = globe.pickProjected(ray, scene, scratchRayIntersection);

var pickDistance = defined(depthIntersection) ? Cartesian3.distance(depthIntersection, camera.positionWC) : Number.POSITIVE_INFINITY;
var rayDistance = defined(rayIntersection) ? Cartesian3.distance(rayIntersection, camera.positionWC) : Number.POSITIVE_INFINITY;
Expand Down
2 changes: 1 addition & 1 deletion Specs/Scene/ScreenSpaceCameraControllerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ defineSuite([
this.getHeight = function(cartographic) {
return 0.0;
};
this.pick = function() {
this.pickProjected = function() {
return new Cartesian3(0.0, 0.0, 1.0);
};
this._surface = {
Expand Down

0 comments on commit 669179c

Please sign in to comment.