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 --- .../RDGE/src/core/script/utilities.js | 282 ++++++++++----------- 1 file changed, 139 insertions(+), 143 deletions(-) (limited to 'js/helper-classes/RDGE/src/core/script/utilities.js') diff --git a/js/helper-classes/RDGE/src/core/script/utilities.js b/js/helper-classes/RDGE/src/core/script/utilities.js index e19c727f..dcc61d45 100755 --- a/js/helper-classes/RDGE/src/core/script/utilities.js +++ b/js/helper-classes/RDGE/src/core/script/utilities.js @@ -4,125 +4,126 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -function getRandColor() -{ - var r = Math.random(); - var g = Math.random(); - var b =Math.random(); - - return [r, g, b, 1.0]; -} - - -function unProject( winx, winy, winz, modelMatrix, projMatrix, viewport) -{ - var inVal = [0,0,0,0]; - - var finalMatrix = mat4.mul( modelMatrix, projMatrix ); - - finalMatrix = mat4.inverse(finalMatrix); - if(!finalMatrix) - return null; - - inVal[0]=winx; - inVal[1]=winy; - inVal[2]=winz; - inVal[3]=1.0; - - /* Map x and y from window coordinates */ +// RDGE namespaces +var RDGE = RDGE || {}; + + +/* +// Methods not currently used in Ninja +RDGE.getRandColor = function () { + var r = Math.random(); + var g = Math.random(); + var b = Math.random(); + + return [r, g, b, 1.0]; +}; + +RDGE.unProject = function (winx, winy, winz, modelMatrix, projMatrix, viewport) { + var inVal = [0, 0, 0, 0]; + + var finalMatrix = RDGE.mat4.mul(modelMatrix, projMatrix); + + finalMatrix = RDGE.mat4.inverse(finalMatrix); + if (!finalMatrix) + return null; + + inVal[0] = winx; + inVal[1] = winy; + inVal[2] = winz; + inVal[3] = 1.0; + + // Map x and y from window coordinates inVal[0] = (inVal[0] - viewport[0]) / viewport[2]; inVal[1] = (inVal[1] - viewport[1]) / viewport[3]; - /* Map to range -1 to 1 */ + // Map to range -1 to 1 inVal[0] = inVal[0] * 2 - 1; inVal[1] = inVal[1] * 2 - 1; inVal[2] = inVal[2] * 2 - 1; - var v4Out = mat4.transformPoint( finalMatrix, inVal ); - - if (v4Out[3] <= 0.0001) - return null; - + var v4Out = RDGE.mat4.transformPoint(finalMatrix, inVal); + + if (v4Out[3] <= 0.0001) + return null; + v4Out[0] /= v4Out[3]; v4Out[1] /= v4Out[3]; v4Out[2] /= v4Out[3]; - - return [ v4Out[0], v4Out[1], v4Out[2] ]; -} - -function AABB2LineSegment(box, startPoint, endPoint ) -{ - c = vec3.scale( vec3.add(box.min, box.max), 0.5 ); - e = vec3.sub(box.max, box.min); - d = vec3.sub(endPoint, startPoint); - m = vec3.sub(startPoint, endPoint); - m = vec3.sub(m, box.min), - m = vec3.sub(m, box.max); - - var adx = Math.abs(d[0]); - if( Math.abs(m[0]) > e[0] + adx ) return false; - - var ady = Math.abs(d[1]); - if( Math.abs(m[1]) > e[1] + ady ) return false; - - var adz = Math.abs(d[2]); - if( Math.abs(m[2]) > e[2] + adz ) return false; - - adx += 1.192092896e-07; - ady += 1.192092896e-07; - adz += 1.192092896e-07; - - if( Math.abs(m[1] * d[2] - m[2] * d[1]) > e[1] * adz + e[2] * ady ) return false; - if( Math.abs(m[2] * d[0] - m[0] * d[2]) > e[0] * adz + e[2] * adx ) return false; - if( Math.abs(m[0] * d[1] - m[1] * d[0]) > e[0] * ady + e[1] * adx ) return false; - - return true; -} - -function hitTest(mesh, near, far) -{ - // holds distance to the nearst BV - var dist = null; - var BV = null; - - for(var index = 0; index < mesh.BVL.length; index++) - { - if(AABB2LineSegment(mesh.BVL[index], near, far)) - { - var center = vec3.scale( vec3.add(mesh.BVL[index].min, mesh.BVL[index].max), 0.5 ); - var newDist = vec3.dot( mat4.row( g_cam.world, 2 ), center); - if(newDist < dist || dist == null) - { - dist = newDist; - BV = mesh.BVL[index]; - } + + return [v4Out[0], v4Out[1], v4Out[2]]; +}; + +RDGE.AABB2LineSegment = function (box, startPoint, endPoint) { + c = RDGE.vec3.scale(RDGE.vec3.add(box.min, box.max), 0.5); + e = RDGE.vec3.sub(box.max, box.min); + d = RDGE.vec3.sub(endPoint, startPoint); + m = RDGE.vec3.sub(startPoint, endPoint); + m = RDGE.vec3.sub(m, box.min), + m = RDGE.vec3.sub(m, box.max); + + var adx = Math.abs(d[0]); + if (Math.abs(m[0]) > e[0] + adx) return false; + + var ady = Math.abs(d[1]); + if (Math.abs(m[1]) > e[1] + ady) return false; + + var adz = Math.abs(d[2]); + if (Math.abs(m[2]) > e[2] + adz) return false; + + adx += 1.192092896e-07; + ady += 1.192092896e-07; + adz += 1.192092896e-07; + + if (Math.abs(m[1] * d[2] - m[2] * d[1]) > e[1] * adz + e[2] * ady) return false; + if (Math.abs(m[2] * d[0] - m[0] * d[2]) > e[0] * adz + e[2] * adx) return false; + if (Math.abs(m[0] * d[1] - m[1] * d[0]) > e[0] * ady + e[1] * adx) return false; + + return true; +}; + +RDGE.hitTest = function (mesh, near, far) { + // holds distance to the nearest BV + var dist = null; + var BV = null; + + for (var index = 0; index < mesh.BVL.length; index++) { + if (AABB2LineSegment(mesh.BVL[index], near, far)) { + var center = RDGE.vec3.scale(RDGE.vec3.add(mesh.BVL[index].min, mesh.BVL[index].max), 0.5); + var newDist = RDGE.vec3.dot(RDGE.mat4.row(RDGE.globals.cam.world, 2), center); + if (newDist < dist || dist == null) { + dist = newDist; + BV = mesh.BVL[index]; + } + } } - } - return BV; -} + return BV; +}; + + + +*/ + + + + + -// // loadShader -// -// 'shaderId' is the id of a