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