From fb0a659c9ca3479fd6799325498b11f074689936 Mon Sep 17 00:00:00 2001 From: John Mayhew Date: Mon, 2 Apr 2012 14:57:31 -0700 Subject: -Namespaced all RDGE javascript. -Removed the following unused files from the build script /core/script/fx/blur.js /core/script/fx/ssao.js /core/script/animation.js - Fully removed the following from the build and from source control as they are unused or no longer needed /core/script/util/dbgpanel.js /core/script/util/fpsTracker.js /core/script/util/statTracker.js /core/script/input.js /core/script/TextureManager.js /core/script/ubershader.js --- js/helper-classes/RDGE/src/core/script/box.js | 181 +++++++++++++------------- 1 file changed, 88 insertions(+), 93 deletions(-) (limited to 'js/helper-classes/RDGE/src/core/script/box.js') 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 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -MAX_VAL = 1e+38; - -function box() -{ - this.min = [MAX_VAL, MAX_VAL, MAX_VAL]; - this.max = [-MAX_VAL, -MAX_VAL, -MAX_VAL]; -} - -box.prototype.addBox = function(a) -{ - this.min = vec3.min( this.min, a.min ); - this.max = vec3.max( this.max, a.max ); -// this.min = vec3.min( this.min, a.min ); -// this.max = vec3.max( this.max, a.max ); -} - -box.prototype.addVec3 = function(a) -{ - this.min = vec3.min( this.min, a ); - this.max = vec3.max( this.max, a ); -} - -box.prototype.set = function(min, max) -{ - this.min[0] = min[0]; - this.min[1] = min[1]; - this.min[2] = min[2]; - this.max[0] = max[0]; - this.max[1] = max[1]; - this.max[2] = max[2]; -} - -box.prototype.reset = function() -{ - this.min[0] = MAX_VAL; - this.min[1] = MAX_VAL; - this.min[2] = MAX_VAL; - this.max[0] = -MAX_VAL; - this.max[1] = -MAX_VAL; - this.max[2] = -MAX_VAL; -} - -box.prototype.getCenter = function() -{ - 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])]; -} - -box.prototype.isVisible = function(frustum) -{ - var center = this.getCenter(); - var radius = vec3.distance( this.max, center ); - // var diag = vec3.sub( this.max, center ); - - var i = 0; - while(i < frustum.length) { - var plane = frustum[i]; - var dist = vec3.dot( plane, center ) + plane[3]; - if( dist < -radius ) { - return false; - } - i++; - } - - return true; -} - -box.prototype.isValid = function() -{ - return !(this.min[0] > this.max[0] || this.min[1] > this.max[1] || this.min[2] > this.max[2]); -} - -box.prototype.transform = function(mat) { - var out = new box(); - var pts = []; - pts.push( [ this.min[0], this.min[1], this.min[2] ] ); - pts.push( [ this.min[0], this.max[1], this.min[2] ] ); - pts.push( [ this.max[0], this.max[1], this.min[2] ] ); - pts.push( [ this.max[0], this.min[1], this.min[2] ] ); - pts.push( [ this.min[0], this.min[1], this.max[2] ] ); - pts.push( [ this.min[0], this.max[1], this.max[2] ] ); - pts.push( [ this.max[0], this.max[1], this.max[2] ] ); - pts.push( [ this.max[0], this.min[1], this.max[2] ] ); - - var i = pts.length - 1; - do { - out.addVec3( mat4.transformPoint( mat, pts[i] ) ); - } while(i--); - - return out; -} +// RDGE namespaces +var RDGE = RDGE || {}; + +RDGE.box = function () { + this.MAX_VAL = 1e+38; + this.min = [this.MAX_VAL, this.MAX_VAL, this.MAX_VAL]; + this.max = [-this.MAX_VAL, -this.MAX_VAL, -this.MAX_VAL]; +}; + +RDGE.box.prototype.addBox = function (a) { + this.min = RDGE.vec3.min(this.min, a.min); + this.max = RDGE.vec3.max(this.max, a.max); + // this.min = RDGE.vec3.min( this.min, a.min ); + // this.max = RDGE.vec3.max( this.max, a.max ); +}; + +RDGE.box.prototype.addVec3 = function (a) { + this.min = RDGE.vec3.min(this.min, a); + this.max = RDGE.vec3.max(this.max, a); +}; + +RDGE.box.prototype.set = function (min, max) { + this.min[0] = min[0]; + this.min[1] = min[1]; + this.min[2] = min[2]; + this.max[0] = max[0]; + this.max[1] = max[1]; + this.max[2] = max[2]; +}; + +RDGE.box.prototype.reset = function () { + this.min[0] = this.MAX_VAL; + this.min[1] = this.MAX_VAL; + this.min[2] = this.MAX_VAL; + this.max[0] = -this.MAX_VAL; + this.max[1] = -this.MAX_VAL; + this.max[2] = -this.MAX_VAL; +}; + +RDGE.box.prototype.getCenter = function () { + 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])]; +}; + +RDGE.box.prototype.isVisible = function (frustum) { + var center = this.getCenter(); + var radius = RDGE.vec3.distance(this.max, center); + // var diag = RDGE.vec3.sub( this.max, center ); + + var i = 0; + while (i < frustum.length) { + var plane = frustum[i]; + var dist = RDGE.vec3.dot(plane, center) + plane[3]; + if (dist < -radius) { + return false; + } + i++; + } + + return true; +}; + +RDGE.box.prototype.isValid = function () { + return !(this.min[0] > this.max[0] || this.min[1] > this.max[1] || this.min[2] > this.max[2]); +}; + +RDGE.box.prototype.transform = function (mat) { + var out = new RDGE.box(); + var pts = []; + pts.push([this.min[0], this.min[1], this.min[2]]); + pts.push([this.min[0], this.max[1], this.min[2]]); + pts.push([this.max[0], this.max[1], this.min[2]]); + pts.push([this.max[0], this.min[1], this.min[2]]); + pts.push([this.min[0], this.min[1], this.max[2]]); + pts.push([this.min[0], this.max[1], this.max[2]]); + pts.push([this.max[0], this.max[1], this.max[2]]); + pts.push([this.max[0], this.min[1], this.max[2]]); + + var i = pts.length - 1; + do { + out.addVec3(RDGE.mat4.transformPoint(mat, pts[i])); + } while (i--); + + return out; +}; + /* -box.prototype.transform = function(mat) { - var newBox = new box(); +RDGE.box.prototype.transform = function(mat) { + var newBox = new RDGE.box(); var e, f; newBox.b[0] = mat[12]; newBox.b[1] = mat[13]; newBox.b[2] = mat[14]; @@ -139,5 +134,5 @@ box.prototype.transform = function(mat) { newBox.t[2] += (e < f) ? f : e; return newBox; -} +}; */ \ No newline at end of file -- cgit v1.2.3