diff options
author | hwc487 | 2012-04-19 13:01:43 -0700 |
---|---|---|
committer | hwc487 | 2012-04-19 13:01:43 -0700 |
commit | e6a20fe64574763483dc602bd759278ccf5e5e68 (patch) | |
tree | 69defe7200206f0257fe90697136fadef59d521e /js/helper-classes/RDGE/src/core/script/box.js | |
parent | ae7eb87564632ce7c676bd728b8ff2710ff0bb83 (diff) | |
parent | 9284c19f076dec3b47ece7dc7bcd22d74e4246c3 (diff) | |
download | ninja-e6a20fe64574763483dc602bd759278ccf5e5e68.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into Textures
Conflicts:
js/lib/drawing/world.js
js/lib/geom/geom-obj.js
js/lib/rdge/materials/cloud-material.js
js/lib/rdge/materials/deform-material.js
js/lib/rdge/materials/flat-material.js
js/lib/rdge/materials/material.js
js/lib/rdge/materials/pulse-material.js
js/lib/rdge/materials/relief-tunnel-material.js
js/lib/rdge/materials/square-tunnel-material.js
js/lib/rdge/materials/star-material.js
js/lib/rdge/materials/taper-material.js
js/lib/rdge/materials/tunnel-material.js
js/lib/rdge/materials/twist-material.js
js/lib/rdge/materials/twist-vert-material.js
js/lib/rdge/materials/uber-material.js
js/lib/rdge/materials/water-material.js
js/lib/rdge/materials/z-invert-material.js
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/box.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/box.js | 181 |
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 | ||
7 | MAX_VAL = 1e+38; | 7 | // RDGE namespaces |
8 | 8 | var RDGE = RDGE || {}; | |
9 | function box() | 9 | |
10 | { | 10 | RDGE.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 | }; | |
15 | box.prototype.addBox = function(a) | 15 | |
16 | { | 16 | RDGE.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 | ||
23 | box.prototype.addVec3 = function(a) | 23 | RDGE.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 | 28 | RDGE.box.prototype.set = function (min, max) { | |
29 | box.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 | } | 37 | RDGE.box.prototype.reset = function () { |
38 | 38 | this.min[0] = this.MAX_VAL; | |
39 | box.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; | 46 | RDGE.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 | }; | |
49 | box.prototype.getCenter = function() | 49 | |
50 | { | 50 | RDGE.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 ); | |
54 | box.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 | } | 68 | RDGE.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 | 72 | RDGE.box.prototype.transform = function (mat) { | |
73 | box.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]]); | |
78 | box.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 | /* |
98 | box.prototype.transform = function(mat) { | 93 | RDGE.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 |