@@ -4,6 +4,7 @@ import Check from './Check.js';
4
4
import defaultValue from './defaultValue.js' ;
5
5
import defined from './defined.js' ;
6
6
import defineProperties from './defineProperties.js' ;
7
+ import Ellipsoid from './Ellipsoid.js' ;
7
8
import Rectangle from './Rectangle.js' ;
8
9
9
10
/**
@@ -116,16 +117,40 @@ import Rectangle from './Rectangle.js';
116
117
* occluder.isScaledSpacePointVisible(scaledSpacePoint); //returns true
117
118
*/
118
119
EllipsoidalOccluder . prototype . isScaledSpacePointVisible = function ( occludeeScaledSpacePosition ) {
119
- // See https://cesium.com/blog/2013/04/25/Horizon-culling/
120
- var cv = this . _cameraPositionInScaledSpace ;
121
- var vhMagnitudeSquared = this . _distanceToLimbInScaledSpaceSquared ;
122
- var vt = Cartesian3 . subtract ( occludeeScaledSpacePosition , cv , scratchCartesian ) ;
123
- var vtDotVc = - Cartesian3 . dot ( vt , cv ) ;
124
- // If vhMagnitudeSquared < 0 then we are below the surface of the ellipsoid and
125
- // in this case, set the culling plane to be on V.
126
- var isOccluded = vhMagnitudeSquared < 0 ? vtDotVc > 0 : ( vtDotVc > vhMagnitudeSquared &&
127
- vtDotVc * vtDotVc / Cartesian3 . magnitudeSquared ( vt ) > vhMagnitudeSquared ) ;
128
- return ! isOccluded ;
120
+ return isScaledSpacePointVisible ( occludeeScaledSpacePosition , this . _cameraPositionInScaledSpace , this . _distanceToLimbInScaledSpaceSquared ) ;
121
+ } ;
122
+
123
+ var scratchEllipsoidShrunkRadii = new Cartesian3 ( ) ;
124
+ var scratchEllipsoidShrunk = Ellipsoid . clone ( Ellipsoid . UNIT_SPHERE ) ;
125
+ var scratchCameraPositionInScaledSpaceShrunk = new Cartesian3 ( ) ;
126
+
127
+ /**
128
+ * Similar to {@link EllipsoidalOccluder#isScaledSpacePointVisible} except tests against an
129
+ * ellipsoid that has been shrunk by the minimum height when the minimum height is below
130
+ * the ellipsoid. This is intended to be used with points generated by
131
+ * {@link EllipsoidalOccluder#computeHorizonCullingPointPossiblyUnderEllipsoid},
132
+ * {@link EllipsoidalOccluder#computeHorizonCullingPointFromVerticesPossiblyUnderEllipsoid}, or
133
+ * {@link EllipsoidalOccluder#computeHorizonCullingPointFromRectanglePossiblyUnderEllipsoid}.
134
+ *
135
+ * @param {Cartesian3 } occludeeScaledSpacePosition The point to test for visibility, represented in the scaled space of the possibly-shrunk ellipsoid.
136
+ * @returns {Boolean } <code>true</code> if the occludee is visible; otherwise <code>false</code>.
137
+ */
138
+ EllipsoidalOccluder . prototype . isScaledSpacePointVisiblePossiblyUnderEllipsoid = function ( occludeeScaledSpacePosition , minimumHeight ) {
139
+ var ellipsoid = this . _ellipsoid ;
140
+ if ( defined ( minimumHeight ) && minimumHeight < 0.0 && ellipsoid . minimumRadius > - minimumHeight ) {
141
+ var ellipsoidShrunkRadii = Cartesian3 . fromElements (
142
+ ellipsoid . radii . x + minimumHeight ,
143
+ ellipsoid . radii . y + minimumHeight ,
144
+ ellipsoid . radii . z + minimumHeight ,
145
+ scratchEllipsoidShrunkRadii
146
+ ) ;
147
+ var ellipsoidShrunk = Ellipsoid . fromCartesian3 ( ellipsoidShrunkRadii , scratchEllipsoidShrunk ) ;
148
+ var cameraPositionInScaledSpaceShrunk = ellipsoidShrunk . transformPositionToScaledSpace ( this . _cameraPosition , scratchCameraPositionInScaledSpaceShrunk ) ;
149
+ var distanceToLimbinScaledSpaceSquaredShrunk = Cartesian3 . magnitudeSquared ( cameraPositionInScaledSpaceShrunk ) - 1.0 ;
150
+ return isScaledSpacePointVisible ( occludeeScaledSpacePosition , cameraPositionInScaledSpaceShrunk , distanceToLimbinScaledSpaceSquaredShrunk ) ;
151
+ }
152
+
153
+ return isScaledSpacePointVisible ( occludeeScaledSpacePosition , this . _cameraPositionInScaledSpace , this . _distanceToLimbInScaledSpaceSquared ) ;
129
154
} ;
130
155
131
156
/**
@@ -167,6 +192,30 @@ import Rectangle from './Rectangle.js';
167
192
return magnitudeToPoint ( scaledSpaceDirectionToPoint , resultMagnitude , result ) ;
168
193
} ;
169
194
195
+ /**
196
+ * Similar to {@link EllipsoidalOccluder#computeHorizonCullingPoint} except computes the culling
197
+ * point relative to an ellipsoid that has been shrunk by the minimum height when the minimum height is below
198
+ * the ellipsoid. The returned point is expressed in the possibly-shrunk ellipsoid-scaled space and is suitable
199
+ * for use with {@link EllipsoidalOccluder#isScaledSpacePointVisiblePossiblyUnderEllipsoid}.
200
+ *
201
+ * @param {Cartesian3 } directionToPoint The direction that the computed point will lie along.
202
+ * A reasonable direction to use is the direction from the center of the ellipsoid to
203
+ * the center of the bounding sphere computed from the positions. The direction need not
204
+ * be normalized.
205
+ * @param {Cartesian3[] } positions The positions from which to compute the horizon culling point. The positions
206
+ * must be expressed in a reference frame centered at the ellipsoid and aligned with the
207
+ * ellipsoid's axes.
208
+ * @param {Number } [minimumHeight] The minimum height of all positions. If this value is undefined, all positions are assumed to be above the ellipsoid.
209
+ * @param {Cartesian3 } [result] The instance on which to store the result instead of allocating a new instance.
210
+ * @returns {Cartesian3 } The computed horizon culling point, expressed in the possibly-shrunk ellipsoid-scaled space.
211
+ */
212
+ EllipsoidalOccluder . prototype . computeHorizonCullingPointPossiblyUnderEllipsoid = function ( directionToPoint , positions , minimumHeight , result ) {
213
+ var that = this ;
214
+ return computeHorizonCullingPointPossiblyUnderEllipsoid ( that , minimumHeight , function ( ) {
215
+ return that . computeHorizonCullingPoint ( directionToPoint , positions , result ) ;
216
+ } ) ;
217
+ } ;
218
+
170
219
var positionScratch = new Cartesian3 ( ) ;
171
220
172
221
/**
@@ -215,6 +264,32 @@ import Rectangle from './Rectangle.js';
215
264
return magnitudeToPoint ( scaledSpaceDirectionToPoint , resultMagnitude , result ) ;
216
265
} ;
217
266
267
+ /**
268
+ * Similar to {@link EllipsoidalOccluder#computeHorizonCullingPointFromVertices} except computes the culling
269
+ * point relative to an ellipsoid that has been shrunk by the minimum height when the minimum height is below
270
+ * the ellipsoid. The returned point is expressed in the possibly-shrunk ellipsoid-scaled space and is suitable
271
+ * for use with {@link EllipsoidalOccluder#isScaledSpacePointVisiblePossiblyUnderEllipsoid}.
272
+ *
273
+ * @param {Cartesian3 } directionToPoint The direction that the computed point will lie along.
274
+ * A reasonable direction to use is the direction from the center of the ellipsoid to
275
+ * the center of the bounding sphere computed from the positions. The direction need not
276
+ * be normalized.
277
+ * @param {Number[] } vertices The vertices from which to compute the horizon culling point. The positions
278
+ * must be expressed in a reference frame centered at the ellipsoid and aligned with the
279
+ * ellipsoid's axes.
280
+ * @param {Number } [stride=3]
281
+ * @param {Cartesian3 } [center=Cartesian3.ZERO]
282
+ * @param {Number } [minimumHeight] The minimum height of all vertices. If this value is undefined, all vertices are assumed to be above the ellipsoid.
283
+ * @param {Cartesian3 } [result] The instance on which to store the result instead of allocating a new instance.
284
+ * @returns {Cartesian3 } The computed horizon culling point, expressed in the possibly-shrunk ellipsoid-scaled space.
285
+ */
286
+ EllipsoidalOccluder . prototype . computeHorizonCullingPointFromVerticesPossiblyUnderEllipsoid = function ( directionToPoint , vertices , stride , center , minimumHeight , result ) {
287
+ var that = this ;
288
+ return computeHorizonCullingPointPossiblyUnderEllipsoid ( that , minimumHeight , function ( ) {
289
+ return that . computeHorizonCullingPointFromVertices ( directionToPoint , vertices , stride , center , result ) ;
290
+ } ) ;
291
+ } ;
292
+
218
293
var subsampleScratch = [ ] ;
219
294
220
295
/**
@@ -246,6 +321,65 @@ import Rectangle from './Rectangle.js';
246
321
return this . computeHorizonCullingPoint ( bs . center , positions , result ) ;
247
322
} ;
248
323
324
+ /**
325
+ * Similar to {@link EllipsoidalOccluder#computeHorizonCullingPointFromRectangle} except computes the culling
326
+ * point relative to an ellipsoid that has been shrunk by the height when the height is below
327
+ * the ellipsoid. The returned point is expressed in the possibly-shrunk ellipsoid-scaled space and is suitable
328
+ * for use with {@link EllipsoidalOccluder#isScaledSpacePointVisiblePossiblyUnderEllipsoid}.
329
+ *
330
+ * @param {Rectangle } rectangle The rectangle for which to compute the horizon culling point.
331
+ * @param {Ellipsoid } ellipsoid The ellipsoid on which the rectangle is defined. This may be different from
332
+ * the ellipsoid used by this instance for occlusion testing.
333
+ * @param {Number } [height] The height of the rectangle. If this value is undefined, the rectangle is assumed to be on the occluder's ellipsoid.
334
+ * @param {Cartesian3 } [result] The instance on which to store the result instead of allocating a new instance.
335
+ * @returns {Cartesian3 } The computed horizon culling point, expressed in the possibly-shrunk ellipsoid-scaled space.
336
+ */
337
+ EllipsoidalOccluder . prototype . computeHorizonCullingPointFromRectanglePossiblyUnderEllipsoid = function ( rectangle , ellipsoid , height , result ) {
338
+ var that = this ;
339
+ return computeHorizonCullingPointPossiblyUnderEllipsoid ( that , height , function ( ) {
340
+ return that . computeHorizonCullingPointFromRectangle ( rectangle , ellipsoid , result ) ;
341
+ } ) ;
342
+ } ;
343
+
344
+ var scratchEllipsoidShrunkRadii2 = new Cartesian3 ( ) ;
345
+ var scratchEllipsoidShrunk2 = Ellipsoid . clone ( Ellipsoid . UNIT_SPHERE ) ;
346
+
347
+ function computeHorizonCullingPointPossiblyUnderEllipsoid ( ellipsoidalOccluder , minimumHeight , func ) {
348
+ var ellipsoid = ellipsoidalOccluder . _ellipsoid ;
349
+
350
+ if ( defined ( minimumHeight ) && minimumHeight < 0.0 && ellipsoid . minimumRadius > - minimumHeight ) {
351
+ var ellipsoidShrunkRadii = Cartesian3 . fromElements (
352
+ ellipsoid . radii . x + minimumHeight ,
353
+ ellipsoid . radii . y + minimumHeight ,
354
+ ellipsoid . radii . z + minimumHeight ,
355
+ scratchEllipsoidShrunkRadii2
356
+ ) ;
357
+ var ellipsoidShrunk = Ellipsoid . fromCartesian3 ( ellipsoidShrunkRadii , scratchEllipsoidShrunk2 ) ;
358
+
359
+ // The horizon culling point is calculated with respect to the shrunk ellipsoid, so
360
+ // temporarily change change the occluder's ellipsoid to the shrunk ellipsoid.
361
+ ellipsoidalOccluder . _ellipsoid = ellipsoidShrunk ;
362
+ var result = func ( ) ;
363
+ ellipsoidalOccluder . _ellipsoid = ellipsoid ;
364
+ return result ;
365
+ }
366
+
367
+ return func ( ) ;
368
+ }
369
+
370
+ function isScaledSpacePointVisible ( occludeeScaledSpacePosition , cameraPositionInScaledSpace , distanceToLimbInScaledSpaceSquared ) {
371
+ // See https://cesium.com/blog/2013/04/25/Horizon-culling/
372
+ var cv = cameraPositionInScaledSpace ;
373
+ var vhMagnitudeSquared = distanceToLimbInScaledSpaceSquared ;
374
+ var vt = Cartesian3 . subtract ( occludeeScaledSpacePosition , cv , scratchCartesian ) ;
375
+ var vtDotVc = - Cartesian3 . dot ( vt , cv ) ;
376
+ // If vhMagnitudeSquared < 0 then we are below the surface of the ellipsoid and
377
+ // in this case, set the culling plane to be on V.
378
+ var isOccluded = vhMagnitudeSquared < 0 ? vtDotVc > 0 : ( vtDotVc > vhMagnitudeSquared &&
379
+ vtDotVc * vtDotVc / Cartesian3 . magnitudeSquared ( vt ) > vhMagnitudeSquared ) ;
380
+ return ! isOccluded ;
381
+ }
382
+
249
383
var scaledSpaceScratch = new Cartesian3 ( ) ;
250
384
var directionScratch = new Cartesian3 ( ) ;
251
385
0 commit comments