1
1
/*global define*/
2
2
define ( [
3
3
'../Core/Cartesian3' ,
4
+ '../Core/Cartesian4' ,
4
5
'../Core/defaultValue' ,
5
6
'../Core/defined' ,
6
7
'../Core/DeveloperError' ,
7
8
'../Core/Intersect' ,
8
9
'../Core/Plane'
9
10
] , function (
10
11
Cartesian3 ,
12
+ Cartesian4 ,
11
13
defaultValue ,
12
14
defined ,
13
15
DeveloperError ,
@@ -21,7 +23,7 @@ define([
21
23
* @alias CullingVolume
22
24
* @constructor
23
25
*
24
- * @param {Cartesian4[] } planes An array of clipping planes.
26
+ * @param {Cartesian4[] } [ planes] An array of clipping planes.
25
27
*/
26
28
function CullingVolume ( planes ) {
27
29
/**
@@ -34,7 +36,78 @@ define([
34
36
this . planes = defaultValue ( planes , [ ] ) ;
35
37
}
36
38
39
+ var faces = [ new Cartesian3 ( ) , new Cartesian3 ( ) , new Cartesian3 ( ) ] ;
40
+ Cartesian3 . clone ( Cartesian3 . UNIT_X , faces [ 0 ] ) ;
41
+ Cartesian3 . clone ( Cartesian3 . UNIT_Y , faces [ 1 ] ) ;
42
+ Cartesian3 . clone ( Cartesian3 . UNIT_Z , faces [ 2 ] ) ;
43
+
44
+ var scratchPlaneCenter = new Cartesian3 ( ) ;
45
+ var scratchPlaneNormal = new Cartesian3 ( ) ;
37
46
var scratchPlane = new Plane ( new Cartesian3 ( ) , 0.0 ) ;
47
+
48
+ /**
49
+ * Constructs a culling volume from a bounding sphere. Creates six planes that create a box containing the sphere.
50
+ * The planes are aligned to the x, y, and z axes in world coordinates.
51
+ *
52
+ * @param {BoundingSphere } boundingSphere The bounding sphere used to create the culling volume.
53
+ * @param {CullingVolume } [result] The object onto which to store the result.
54
+ * @returns {CullingVolume } The culling volume created from the bounding sphere.
55
+ */
56
+ CullingVolume . fromBoundingSphere = function ( boundingSphere , result ) {
57
+ //>>includeStart('debug', pragmas.debug);
58
+ if ( ! defined ( boundingSphere ) ) {
59
+ throw new DeveloperError ( 'boundingSphere is required.' ) ;
60
+ }
61
+ //>>includeEnd('debug');
62
+
63
+ if ( ! defined ( result ) ) {
64
+ result = new CullingVolume ( ) ;
65
+ }
66
+
67
+ var length = faces . length ;
68
+ var planes = result . planes ;
69
+ planes . length = 2 * length ;
70
+
71
+ var center = boundingSphere . center ;
72
+ var radius = boundingSphere . radius ;
73
+
74
+ var planeIndex = 0 ;
75
+
76
+ for ( var i = 0 ; i < length ; ++ i ) {
77
+ var faceNormal = faces [ i ] ;
78
+
79
+ var plane0 = planes [ planeIndex ] ;
80
+ var plane1 = planes [ planeIndex + 1 ] ;
81
+
82
+ if ( ! defined ( plane0 ) ) {
83
+ plane0 = planes [ planeIndex ] = new Cartesian4 ( ) ;
84
+ }
85
+ if ( ! defined ( plane1 ) ) {
86
+ plane1 = planes [ planeIndex + 1 ] = new Cartesian4 ( ) ;
87
+ }
88
+
89
+ Cartesian3 . multiplyByScalar ( faceNormal , - radius , scratchPlaneCenter ) ;
90
+ Cartesian3 . add ( center , scratchPlaneCenter , scratchPlaneCenter ) ;
91
+
92
+ plane0 . x = faceNormal . x ;
93
+ plane0 . y = faceNormal . y ;
94
+ plane0 . z = faceNormal . z ;
95
+ plane0 . w = - Cartesian3 . dot ( faceNormal , scratchPlaneCenter ) ;
96
+
97
+ Cartesian3 . multiplyByScalar ( faceNormal , radius , scratchPlaneCenter ) ;
98
+ Cartesian3 . add ( center , scratchPlaneCenter , scratchPlaneCenter ) ;
99
+
100
+ plane1 . x = - faceNormal . x ;
101
+ plane1 . y = - faceNormal . y ;
102
+ plane1 . z = - faceNormal . z ;
103
+ plane1 . w = - Cartesian3 . dot ( Cartesian3 . negate ( faceNormal , scratchPlaneNormal ) , scratchPlaneCenter ) ;
104
+
105
+ planeIndex += 2 ;
106
+ }
107
+
108
+ return result ;
109
+ } ;
110
+
38
111
/**
39
112
* Determines whether a bounding volume intersects the culling volume.
40
113
*
0 commit comments