@@ -148,63 +148,64 @@ define([
148
148
var vectorScratch = new Cartesian3 ( ) ;
149
149
150
150
TileBoundingBox . prototype . distanceToCamera = function ( frameState ) {
151
- var southwestCornerCartesian = this . southwestCornerCartesian ;
152
- var northeastCornerCartesian = this . northeastCornerCartesian ;
153
- var westNormal = this . westNormal ;
154
- var southNormal = this . southNormal ;
155
- var eastNormal = this . eastNormal ;
156
- var northNormal = this . northNormal ;
157
- var maximumHeight = this . maximumHeight ;
158
-
159
- if ( frameState . mode !== SceneMode . SCENE3D ) {
160
- southwestCornerCartesian = frameState . mapProjection . project ( Rectangle . southwest ( this . rectangle ) , southwestCornerScratch ) ;
161
- southwestCornerCartesian . z = southwestCornerCartesian . y ;
162
- southwestCornerCartesian . y = southwestCornerCartesian . x ;
163
- southwestCornerCartesian . x = 0.0 ;
164
- northeastCornerCartesian = frameState . mapProjection . project ( Rectangle . northeast ( this . rectangle ) , northeastCornerScratch ) ;
165
- northeastCornerCartesian . z = northeastCornerCartesian . y ;
166
- northeastCornerCartesian . y = northeastCornerCartesian . x ;
167
- northeastCornerCartesian . x = 0.0 ;
168
- westNormal = negativeUnitY ;
169
- eastNormal = Cartesian3 . UNIT_Y ;
170
- southNormal = negativeUnitZ ;
171
- northNormal = Cartesian3 . UNIT_Z ;
172
- maximumHeight = 0.0 ;
173
- }
174
-
175
- var cameraCartesianPosition = frameState . camera . positionWC ;
176
- var cameraCartographicPosition = frameState . camera . positionCartographic ;
151
+ var camera = frameState . camera ;
152
+ var cameraCartesianPosition = camera . positionWC ;
153
+ var cameraCartographicPosition = camera . positionCartographic ;
177
154
178
- var vectorFromSouthwestCorner = Cartesian3 . subtract ( cameraCartesianPosition , southwestCornerCartesian , vectorScratch ) ;
179
- var distanceToWestPlane = Cartesian3 . dot ( vectorFromSouthwestCorner , westNormal ) ;
180
- var distanceToSouthPlane = Cartesian3 . dot ( vectorFromSouthwestCorner , southNormal ) ;
181
-
182
- var vectorFromNortheastCorner = Cartesian3 . subtract ( cameraCartesianPosition , northeastCornerCartesian , vectorScratch ) ;
183
- var distanceToEastPlane = Cartesian3 . dot ( vectorFromNortheastCorner , eastNormal ) ;
184
- var distanceToNorthPlane = Cartesian3 . dot ( vectorFromNortheastCorner , northNormal ) ;
155
+ var result = 0.0 ;
156
+ if ( ! Rectangle . contains ( this . rectangle , cameraCartographicPosition ) ) {
157
+ var southwestCornerCartesian = this . southwestCornerCartesian ;
158
+ var northeastCornerCartesian = this . northeastCornerCartesian ;
159
+ var westNormal = this . westNormal ;
160
+ var southNormal = this . southNormal ;
161
+ var eastNormal = this . eastNormal ;
162
+ var northNormal = this . northNormal ;
163
+
164
+ if ( frameState . mode !== SceneMode . SCENE3D ) {
165
+ southwestCornerCartesian = frameState . mapProjection . project ( Rectangle . southwest ( this . rectangle ) , southwestCornerScratch ) ;
166
+ southwestCornerCartesian . z = southwestCornerCartesian . y ;
167
+ southwestCornerCartesian . y = southwestCornerCartesian . x ;
168
+ southwestCornerCartesian . x = 0.0 ;
169
+ northeastCornerCartesian = frameState . mapProjection . project ( Rectangle . northeast ( this . rectangle ) , northeastCornerScratch ) ;
170
+ northeastCornerCartesian . z = northeastCornerCartesian . y ;
171
+ northeastCornerCartesian . y = northeastCornerCartesian . x ;
172
+ northeastCornerCartesian . x = 0.0 ;
173
+ westNormal = negativeUnitY ;
174
+ eastNormal = Cartesian3 . UNIT_Y ;
175
+ southNormal = negativeUnitZ ;
176
+ northNormal = Cartesian3 . UNIT_Z ;
177
+ }
178
+
179
+ var vectorFromSouthwestCorner = Cartesian3 . subtract ( cameraCartesianPosition , southwestCornerCartesian , vectorScratch ) ;
180
+ var distanceToWestPlane = Cartesian3 . dot ( vectorFromSouthwestCorner , westNormal ) ;
181
+ var distanceToSouthPlane = Cartesian3 . dot ( vectorFromSouthwestCorner , southNormal ) ;
182
+
183
+ var vectorFromNortheastCorner = Cartesian3 . subtract ( cameraCartesianPosition , northeastCornerCartesian , vectorScratch ) ;
184
+ var distanceToEastPlane = Cartesian3 . dot ( vectorFromNortheastCorner , eastNormal ) ;
185
+ var distanceToNorthPlane = Cartesian3 . dot ( vectorFromNortheastCorner , northNormal ) ;
186
+
187
+ if ( distanceToWestPlane > 0.0 ) {
188
+ result += distanceToWestPlane * distanceToWestPlane ;
189
+ } else if ( distanceToEastPlane > 0.0 ) {
190
+ result += distanceToEastPlane * distanceToEastPlane ;
191
+ }
192
+
193
+ if ( distanceToSouthPlane > 0.0 ) {
194
+ result += distanceToSouthPlane * distanceToSouthPlane ;
195
+ } else if ( distanceToNorthPlane > 0.0 ) {
196
+ result += distanceToNorthPlane * distanceToNorthPlane ;
197
+ }
198
+ }
185
199
186
200
var cameraHeight ;
187
201
if ( frameState . mode === SceneMode . SCENE3D ) {
188
202
cameraHeight = cameraCartographicPosition . height ;
189
203
} else {
190
204
cameraHeight = cameraCartesianPosition . x ;
191
205
}
192
- var distanceFromTop = cameraHeight - maximumHeight ;
193
-
194
- var result = 0.0 ;
195
-
196
- if ( distanceToWestPlane > 0.0 ) {
197
- result += distanceToWestPlane * distanceToWestPlane ;
198
- } else if ( distanceToEastPlane > 0.0 ) {
199
- result += distanceToEastPlane * distanceToEastPlane ;
200
- }
201
-
202
- if ( distanceToSouthPlane > 0.0 ) {
203
- result += distanceToSouthPlane * distanceToSouthPlane ;
204
- } else if ( distanceToNorthPlane > 0.0 ) {
205
- result += distanceToNorthPlane * distanceToNorthPlane ;
206
- }
207
206
207
+ var maximumHeight = frameState . mode === SceneMode . SCENE3D ? this . maximumHeight : 0.0 ;
208
+ var distanceFromTop = cameraHeight - maximumHeight ;
208
209
if ( distanceFromTop > 0.0 ) {
209
210
result += distanceFromTop * distanceFromTop ;
210
211
}
0 commit comments