aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/box.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/box.js')
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/box.js181
1 files changed, 88 insertions, 93 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/box.js b/js/helper-classes/RDGE/src/core/script/box.js
index 8272d952..fc13982e 100755
--- a/js/helper-classes/RDGE/src/core/script/box.js
+++ b/js/helper-classes/RDGE/src/core/script/box.js
@@ -4,99 +4,94 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */ 5</copyright> */
6 6
7MAX_VAL = 1e+38; 7// RDGE namespaces
8 8var RDGE = RDGE || {};
9function box() 9
10{ 10RDGE.box = function () {
11 this.min = [MAX_VAL, MAX_VAL, MAX_VAL]; 11 this.MAX_VAL = 1e+38;
12 this.max = [-MAX_VAL, -MAX_VAL, -MAX_VAL]; 12 this.min = [this.MAX_VAL, this.MAX_VAL, this.MAX_VAL];
13} 13 this.max = [-this.MAX_VAL, -this.MAX_VAL, -this.MAX_VAL];
14 14};
15box.prototype.addBox = function(a) 15
16{ 16RDGE.box.prototype.addBox = function (a) {
17 this.min = vec3.min( this.min, a.min ); 17 this.min = RDGE.vec3.min(this.min, a.min);
18 this.max = vec3.max( this.max, a.max ); 18 this.max = RDGE.vec3.max(this.max, a.max);
19// this.min = vec3.min( this.min, a.min ); 19 // this.min = RDGE.vec3.min( this.min, a.min );
20// this.max = vec3.max( this.max, a.max ); 20 // this.max = RDGE.vec3.max( this.max, a.max );
21} 21};
22 22
23box.prototype.addVec3 = function(a) 23RDGE.box.prototype.addVec3 = function (a) {
24{ 24 this.min = RDGE.vec3.min(this.min, a);
25 this.min = vec3.min( this.min, a ); 25 this.max = RDGE.vec3.max(this.max, a);
26 this.max = vec3.max( this.max, a ); 26};
27} 27
28 28RDGE.box.prototype.set = function (min, max) {
29box.prototype.set = function(min, max) 29 this.min[0] = min[0];
30{ 30 this.min[1] = min[1];
31 this.min[0] = min[0]; 31 this.min[2] = min[2];
32 this.min[1] = min[1]; 32 this.max[0] = max[0];
33 this.min[2] = min[2]; 33 this.max[1] = max[1];
34 this.max[0] = max[0]; 34 this.max[2] = max[2];
35 this.max[1] = max[1]; 35};
36 this.max[2] = max[2]; 36
37} 37RDGE.box.prototype.reset = function () {
38 38 this.min[0] = this.MAX_VAL;
39box.prototype.reset = function() 39 this.min[1] = this.MAX_VAL;
40{ 40 this.min[2] = this.MAX_VAL;
41 this.min[0] = MAX_VAL; 41 this.max[0] = -this.MAX_VAL;
42 this.min[1] = MAX_VAL; 42 this.max[1] = -this.MAX_VAL;
43 this.min[2] = MAX_VAL; 43 this.max[2] = -this.MAX_VAL;
44 this.max[0] = -MAX_VAL; 44};
45 this.max[1] = -MAX_VAL; 45
46 this.max[2] = -MAX_VAL; 46RDGE.box.prototype.getCenter = function () {
47} 47 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])];
48 48};
49box.prototype.getCenter = function() 49
50{ 50RDGE.box.prototype.isVisible = function (frustum) {
51 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])]; 51 var center = this.getCenter();
52} 52 var radius = RDGE.vec3.distance(this.max, center);
53 53 // var diag = RDGE.vec3.sub( this.max, center );
54box.prototype.isVisible = function(frustum) 54
55{ 55 var i = 0;
56 var center = this.getCenter(); 56 while (i < frustum.length) {
57 var radius = vec3.distance( this.max, center ); 57 var plane = frustum[i];
58 // var diag = vec3.sub( this.max, center ); 58 var dist = RDGE.vec3.dot(plane, center) + plane[3];
59 59 if (dist < -radius) {
60 var i = 0; 60 return false;
61 while(i < frustum.length) { 61 }
62 var plane = frustum[i]; 62 i++;
63 var dist = vec3.dot( plane, center ) + plane[3]; 63 }
64 if( dist < -radius ) { 64
65 return false; 65 return true;
66 } 66};
67 i++; 67
68 } 68RDGE.box.prototype.isValid = function () {
69 69 return !(this.min[0] > this.max[0] || this.min[1] > this.max[1] || this.min[2] > this.max[2]);
70 return true; 70};
71} 71
72 72RDGE.box.prototype.transform = function (mat) {
73box.prototype.isValid = function() 73 var out = new RDGE.box();
74{ 74 var pts = [];
75 return !(this.min[0] > this.max[0] || this.min[1] > this.max[1] || this.min[2] > this.max[2]); 75 pts.push([this.min[0], this.min[1], this.min[2]]);
76} 76 pts.push([this.min[0], this.max[1], this.min[2]]);
77 77 pts.push([this.max[0], this.max[1], this.min[2]]);
78box.prototype.transform = function(mat) { 78 pts.push([this.max[0], this.min[1], this.min[2]]);
79 var out = new box(); 79 pts.push([this.min[0], this.min[1], this.max[2]]);
80 var pts = []; 80 pts.push([this.min[0], this.max[1], this.max[2]]);
81 pts.push( [ this.min[0], this.min[1], this.min[2] ] ); 81 pts.push([this.max[0], this.max[1], this.max[2]]);
82 pts.push( [ this.min[0], this.max[1], this.min[2] ] ); 82 pts.push([this.max[0], this.min[1], this.max[2]]);
83 pts.push( [ this.max[0], this.max[1], this.min[2] ] ); 83
84 pts.push( [ this.max[0], this.min[1], this.min[2] ] ); 84 var i = pts.length - 1;
85 pts.push( [ this.min[0], this.min[1], this.max[2] ] ); 85 do {
86 pts.push( [ this.min[0], this.max[1], this.max[2] ] ); 86 out.addVec3(RDGE.mat4.transformPoint(mat, pts[i]));
87 pts.push( [ this.max[0], this.max[1], this.max[2] ] ); 87 } while (i--);
88 pts.push( [ this.max[0], this.min[1], this.max[2] ] ); 88
89 89 return out;
90 var i = pts.length - 1; 90};
91 do { 91
92 out.addVec3( mat4.transformPoint( mat, pts[i] ) );
93 } while(i--);
94
95 return out;
96}
97/* 92/*
98box.prototype.transform = function(mat) { 93RDGE.box.prototype.transform = function(mat) {
99 var newBox = new box(); 94 var newBox = new RDGE.box();
100 var e, f; 95 var e, f;
101 96
102 newBox.b[0] = mat[12]; newBox.b[1] = mat[13]; newBox.b[2] = mat[14]; 97 newBox.b[0] = mat[12]; newBox.b[1] = mat[13]; newBox.b[2] = mat[14];
@@ -139,5 +134,5 @@ box.prototype.transform = function(mat) {
139 newBox.t[2] += (e < f) ? f : e; 134 newBox.t[2] += (e < f) ? f : e;
140 135
141 return newBox; 136 return newBox;
142} 137};
143*/ \ No newline at end of file 138*/ \ No newline at end of file