@@ -2701,15 +2701,18 @@ define([
2701
2701
2702
2702
/**
2703
2703
* Returns the cartesian position reconstructed from the depth buffer and window position.
2704
+ * The returned position is in world coordinates. Used internally by camera functions to
2705
+ * prevent conversion to projected 2D coordinates and then back.
2706
+ *
2707
+ * @private
2704
2708
*
2705
2709
* @param {Cartesian2 } windowPosition Window coordinates to perform picking on.
2706
2710
* @param {Cartesian3 } [result] The object on which to restore the result.
2707
- * @returns {Cartesian3 } The cartesian position.
2711
+ * @returns {Cartesian3 } The cartesian position in world coordinates .
2708
2712
*
2709
2713
* @exception {DeveloperError} Picking from the depth buffer is not supported. Check pickPositionSupported.
2710
- * @exception {DeveloperError} 2D is not supported. An orthographic projection matrix is not invertible.
2711
2714
*/
2712
- Scene . prototype . pickPosition = function ( windowPosition , result ) {
2715
+ Scene . prototype . pickPositionWorldCoordinates = function ( windowPosition , result ) {
2713
2716
if ( ! this . useDepthPicking ) {
2714
2717
return undefined ;
2715
2718
}
@@ -2738,9 +2741,7 @@ define([
2738
2741
} else if ( defined ( camera . frustum . infiniteProjectionMatrix ) ) {
2739
2742
frustum = camera . frustum . clone ( scratchPerspectiveOffCenterFrustum ) ;
2740
2743
} else {
2741
- //>>includeStart('debug', pragmas.debug);
2742
- throw new DeveloperError ( '2D is not supported. An orthographic projection matrix is not invertible.' ) ;
2743
- //>>includeEnd('debug');
2744
+ frustum = camera . frustum . clone ( scratchOrthographicFrustum ) ;
2744
2745
}
2745
2746
2746
2747
var numFrustums = this . numberOfFrustums ;
@@ -2760,17 +2761,64 @@ define([
2760
2761
2761
2762
if ( depth > 0.0 && depth < 1.0 ) {
2762
2763
var renderedFrustum = this . _frustumCommandsList [ i ] ;
2763
- frustum . near = renderedFrustum . near * ( i !== 0 ? OPAQUE_FRUSTUM_NEAR_OFFSET : 1.0 ) ;
2764
- frustum . far = renderedFrustum . far ;
2765
- uniformState . updateFrustum ( frustum ) ;
2764
+ var height2D ;
2765
+ if ( this . mode === SceneMode . SCENE2D ) {
2766
+ height2D = camera . position . z ;
2767
+ camera . position . z = height2D - renderedFrustum . near + 1.0 ;
2768
+ frustum . far = Math . max ( 1.0 , renderedFrustum . far - renderedFrustum . near ) ;
2769
+ frustum . near = 1.0 ;
2770
+ uniformState . update ( this . frameState ) ;
2771
+ uniformState . updateFrustum ( frustum ) ;
2772
+ } else {
2773
+ frustum . near = renderedFrustum . near * ( i !== 0 ? OPAQUE_FRUSTUM_NEAR_OFFSET : 1.0 ) ;
2774
+ frustum . far = renderedFrustum . far ;
2775
+ uniformState . updateFrustum ( frustum ) ;
2776
+ }
2777
+
2778
+ result = SceneTransforms . drawingBufferToWgs84Coordinates ( this , drawingBufferPosition , depth , result ) ;
2766
2779
2767
- return SceneTransforms . drawingBufferToWgs84Coordinates ( this , drawingBufferPosition , depth , result ) ;
2780
+ if ( this . mode === SceneMode . SCENE2D ) {
2781
+ camera . position . z = height2D ;
2782
+ uniformState . update ( this . frameState ) ;
2783
+ }
2784
+
2785
+ return result ;
2768
2786
}
2769
2787
}
2770
2788
2771
2789
return undefined ;
2772
2790
} ;
2773
2791
2792
+ var scratchPickPositionCartographic = new Cartographic ( ) ;
2793
+
2794
+ /**
2795
+ * Returns the cartesian position reconstructed from the depth buffer and window position.
2796
+ * <p>
2797
+ * The position reconstructed from the depth buffer in 2D may be slightly different from those
2798
+ * reconstructed in 3D and Columbus view. This is caused by the difference in the distribution
2799
+ * of depth values of perspective and orthographic projection.
2800
+ * </p>
2801
+ *
2802
+ * @param {Cartesian2 } windowPosition Window coordinates to perform picking on.
2803
+ * @param {Cartesian3 } [result] The object on which to restore the result.
2804
+ * @returns {Cartesian3 } The cartesian position.
2805
+ *
2806
+ * @exception {DeveloperError} Picking from the depth buffer is not supported. Check pickPositionSupported.
2807
+ */
2808
+ Scene . prototype . pickPosition = function ( windowPosition , result ) {
2809
+ result = this . pickPositionWorldCoordinates ( windowPosition , result ) ;
2810
+ if ( defined ( result ) && this . mode !== SceneMode . SCENE3D ) {
2811
+ Cartesian3 . fromElements ( result . y , result . z , result . x , result ) ;
2812
+
2813
+ var projection = this . mapProjection ;
2814
+ var ellipsoid = projection . ellipsoid ;
2815
+
2816
+ var cart = projection . unproject ( result , scratchPickPositionCartographic ) ;
2817
+ ellipsoid . cartographicToCartesian ( cart , result ) ;
2818
+ }
2819
+ return result ;
2820
+ } ;
2821
+
2774
2822
/**
2775
2823
* Returns a list of objects, each containing a `primitive` property, for all primitives at
2776
2824
* a particular window coordinate position. Other properties may also be set depending on the
0 commit comments