diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/box.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/box.js | 324 |
1 files changed, 162 insertions, 162 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/box.js b/js/helper-classes/RDGE/src/core/script/box.js index d33907a0..cd9c52b3 100755 --- a/js/helper-classes/RDGE/src/core/script/box.js +++ b/js/helper-classes/RDGE/src/core/script/box.js | |||
@@ -1,162 +1,162 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility, Inc |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | 4 | BSD License. |
5 | 5 | ||
6 | Redistribution and use in source and binary forms, with or without | 6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 7 | modification, are permitted provided that the following conditions are met: |
8 | 8 | ||
9 | - Redistributions of source code must retain the above copyright notice, | 9 | - Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. | 10 | this list of conditions and the following disclaimer. |
11 | - Redistributions in binary form must reproduce the above copyright | 11 | - Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the | 12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. | 13 | documentation and/or other materials provided with the distribution. |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 14 | - Neither the name of Motorola Mobility nor the names of its contributors |
15 | may be used to endorse or promote products derived from this software | 15 | may be used to endorse or promote products derived from this software |
16 | without specific prior written permission. | 16 | without specific prior written permission. |
17 | 17 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
28 | POSSIBILITY OF SUCH DAMAGE. | 28 | POSSIBILITY OF SUCH DAMAGE. |
29 | </copyright> */ | 29 | </copyright> */ |
30 | 30 | ||
31 | // RDGE namespaces | 31 | // RDGE namespaces |
32 | var RDGE = RDGE || {}; | 32 | var RDGE = RDGE || {}; |
33 | 33 | ||
34 | RDGE.box = function () { | 34 | RDGE.box = function () { |
35 | this.MAX_VAL = 1e+38; | 35 | this.MAX_VAL = 1e+38; |
36 | this.min = [this.MAX_VAL, this.MAX_VAL, this.MAX_VAL]; | 36 | this.min = [this.MAX_VAL, this.MAX_VAL, this.MAX_VAL]; |
37 | this.max = [-this.MAX_VAL, -this.MAX_VAL, -this.MAX_VAL]; | 37 | this.max = [-this.MAX_VAL, -this.MAX_VAL, -this.MAX_VAL]; |
38 | }; | 38 | }; |
39 | 39 | ||
40 | RDGE.box.prototype.addBox = function (a) { | 40 | RDGE.box.prototype.addBox = function (a) { |
41 | this.min = RDGE.vec3.min(this.min, a.min); | 41 | this.min = RDGE.vec3.min(this.min, a.min); |
42 | this.max = RDGE.vec3.max(this.max, a.max); | 42 | this.max = RDGE.vec3.max(this.max, a.max); |
43 | // this.min = RDGE.vec3.min( this.min, a.min ); | 43 | // this.min = RDGE.vec3.min( this.min, a.min ); |
44 | // this.max = RDGE.vec3.max( this.max, a.max ); | 44 | // this.max = RDGE.vec3.max( this.max, a.max ); |
45 | }; | 45 | }; |
46 | 46 | ||
47 | RDGE.box.prototype.addVec3 = function (a) { | 47 | RDGE.box.prototype.addVec3 = function (a) { |
48 | this.min = RDGE.vec3.min(this.min, a); | 48 | this.min = RDGE.vec3.min(this.min, a); |
49 | this.max = RDGE.vec3.max(this.max, a); | 49 | this.max = RDGE.vec3.max(this.max, a); |
50 | }; | 50 | }; |
51 | 51 | ||
52 | RDGE.box.prototype.set = function (min, max) { | 52 | RDGE.box.prototype.set = function (min, max) { |
53 | this.min[0] = min[0]; | 53 | this.min[0] = min[0]; |
54 | this.min[1] = min[1]; | 54 | this.min[1] = min[1]; |
55 | this.min[2] = min[2]; | 55 | this.min[2] = min[2]; |
56 | this.max[0] = max[0]; | 56 | this.max[0] = max[0]; |
57 | this.max[1] = max[1]; | 57 | this.max[1] = max[1]; |
58 | this.max[2] = max[2]; | 58 | this.max[2] = max[2]; |
59 | }; | 59 | }; |
60 | 60 | ||
61 | RDGE.box.prototype.reset = function () { | 61 | RDGE.box.prototype.reset = function () { |
62 | this.min[0] = this.MAX_VAL; | 62 | this.min[0] = this.MAX_VAL; |
63 | this.min[1] = this.MAX_VAL; | 63 | this.min[1] = this.MAX_VAL; |
64 | this.min[2] = this.MAX_VAL; | 64 | this.min[2] = this.MAX_VAL; |
65 | this.max[0] = -this.MAX_VAL; | 65 | this.max[0] = -this.MAX_VAL; |
66 | this.max[1] = -this.MAX_VAL; | 66 | this.max[1] = -this.MAX_VAL; |
67 | this.max[2] = -this.MAX_VAL; | 67 | this.max[2] = -this.MAX_VAL; |
68 | }; | 68 | }; |
69 | 69 | ||
70 | RDGE.box.prototype.getCenter = function () { | 70 | RDGE.box.prototype.getCenter = function () { |
71 | return [0.5 * (this.min[0] + this.max[0]), 0.5 * (this.min[1] + this.max[1]), 0.5 * (this.min[2] + this.max[2])]; | 71 | return [0.5 * (this.min[0] + this.max[0]), 0.5 * (this.min[1] + this.max[1]), 0.5 * (this.min[2] + this.max[2])]; |
72 | }; | 72 | }; |
73 | 73 | ||
74 | RDGE.box.prototype.isVisible = function (frustum) { | 74 | RDGE.box.prototype.isVisible = function (frustum) { |
75 | var center = this.getCenter(); | 75 | var center = this.getCenter(); |
76 | var radius = RDGE.vec3.distance(this.max, center); | 76 | var radius = RDGE.vec3.distance(this.max, center); |
77 | // var diag = RDGE.vec3.sub( this.max, center ); | 77 | // var diag = RDGE.vec3.sub( this.max, center ); |
78 | 78 | ||
79 | var i = 0; | 79 | var i = 0; |
80 | while (i < frustum.length) { | 80 | while (i < frustum.length) { |
81 | var plane = frustum[i]; | 81 | var plane = frustum[i]; |
82 | var dist = RDGE.vec3.dot(plane, center) + plane[3]; | 82 | var dist = RDGE.vec3.dot(plane, center) + plane[3]; |
83 | if (dist < -radius) { | 83 | if (dist < -radius) { |
84 | return false; | 84 | return false; |
85 | } | 85 | } |
86 | i++; | 86 | i++; |
87 | } | 87 | } |
88 | 88 | ||
89 | return true; | 89 | return true; |
90 | }; | 90 | }; |
91 | 91 | ||
92 | RDGE.box.prototype.isValid = function () { | 92 | RDGE.box.prototype.isValid = function () { |
93 | return !(this.min[0] > this.max[0] || this.min[1] > this.max[1] || this.min[2] > this.max[2]); | 93 | return !(this.min[0] > this.max[0] || this.min[1] > this.max[1] || this.min[2] > this.max[2]); |
94 | }; | 94 | }; |
95 | 95 | ||
96 | RDGE.box.prototype.transform = function (mat) { | 96 | RDGE.box.prototype.transform = function (mat) { |
97 | var out = new RDGE.box(); | 97 | var out = new RDGE.box(); |
98 | var pts = []; | 98 | var pts = []; |
99 | pts.push([this.min[0], this.min[1], this.min[2]]); | 99 | pts.push([this.min[0], this.min[1], this.min[2]]); |
100 | pts.push([this.min[0], this.max[1], this.min[2]]); | 100 | pts.push([this.min[0], this.max[1], this.min[2]]); |
101 | pts.push([this.max[0], this.max[1], this.min[2]]); | 101 | pts.push([this.max[0], this.max[1], this.min[2]]); |
102 | pts.push([this.max[0], this.min[1], this.min[2]]); | 102 | pts.push([this.max[0], this.min[1], this.min[2]]); |
103 | pts.push([this.min[0], this.min[1], this.max[2]]); | 103 | pts.push([this.min[0], this.min[1], this.max[2]]); |
104 | pts.push([this.min[0], this.max[1], this.max[2]]); | 104 | pts.push([this.min[0], this.max[1], this.max[2]]); |
105 | pts.push([this.max[0], this.max[1], this.max[2]]); | 105 | pts.push([this.max[0], this.max[1], this.max[2]]); |
106 | pts.push([this.max[0], this.min[1], this.max[2]]); | 106 | pts.push([this.max[0], this.min[1], this.max[2]]); |
107 | 107 | ||
108 | var i = pts.length - 1; | 108 | var i = pts.length - 1; |
109 | do { | 109 | do { |
110 | out.addVec3(RDGE.mat4.transformPoint(mat, pts[i])); | 110 | out.addVec3(RDGE.mat4.transformPoint(mat, pts[i])); |
111 | } while (i--); | 111 | } while (i--); |
112 | 112 | ||
113 | return out; | 113 | return out; |
114 | }; | 114 | }; |
115 | 115 | ||
116 | /* | 116 | /* |
117 | RDGE.box.prototype.transform = function(mat) { | 117 | RDGE.box.prototype.transform = function(mat) { |
118 | var newBox = new RDGE.box(); | 118 | var newBox = new RDGE.box(); |
119 | var e, f; | 119 | var e, f; |
120 | 120 | ||
121 | newBox.b[0] = mat[12]; newBox.b[1] = mat[13]; newBox.b[2] = mat[14]; | 121 | newBox.b[0] = mat[12]; newBox.b[1] = mat[13]; newBox.b[2] = mat[14]; |
122 | newBox.t[0] = mat[12]; newBox.t[1] = mat[13]; newBox.t[2] = mat[14]; | 122 | newBox.t[0] = mat[12]; newBox.t[1] = mat[13]; newBox.t[2] = mat[14]; |
123 | 123 | ||
124 | e = mat[0] * this.min[0]; f = mat[0] * this.max[0]; | 124 | e = mat[0] * this.min[0]; f = mat[0] * this.max[0]; |
125 | newBox.b[0] += (e < f) ? e : f; | 125 | newBox.b[0] += (e < f) ? e : f; |
126 | newBox.t[0] += (e < f) ? f : e; | 126 | newBox.t[0] += (e < f) ? f : e; |
127 | 127 | ||
128 | e = mat[4] * this.min[1]; f = mat[4] * this.max[1]; | 128 | e = mat[4] * this.min[1]; f = mat[4] * this.max[1]; |
129 | newBox.b[0] += (e < f) ? e : f; | 129 | newBox.b[0] += (e < f) ? e : f; |
130 | newBox.t[0] += (e < f) ? f : e; | 130 | newBox.t[0] += (e < f) ? f : e; |
131 | 131 | ||
132 | e = mat[8] * this.min[2]; f = mat[8] * this.max[2]; |