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/math/mat4.js | 1055 ++++++++++---------- .../RDGE/src/core/script/math/quat.js | 237 ++--- .../RDGE/src/core/script/math/vec2.js | 229 ++--- .../RDGE/src/core/script/math/vec3.js | 423 ++++---- .../RDGE/src/core/script/math/vec4.js | 315 +++--- 5 files changed, 1126 insertions(+), 1133 deletions(-) (limited to 'js/helper-classes/RDGE/src/core/script/math') diff --git a/js/helper-classes/RDGE/src/core/script/math/mat4.js b/js/helper-classes/RDGE/src/core/script/math/mat4.js index fab57732..226b771a 100755 --- a/js/helper-classes/RDGE/src/core/script/math/mat4.js +++ b/js/helper-classes/RDGE/src/core/script/math/mat4.js @@ -4,17 +4,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ - -float3 = function() { - data = [3]; -} - -float4 = function() { - data = [4]; -} - /** -* mat4 = {} * This library contains functions for operating on 4x4 matrices. Any JS array * containing at least 16 numeric components can represent a 4x4 matrix. * @@ -31,313 +21,314 @@ float4 = function() { * y0, y1, y2, y3, * z0, z1, z2, z3, * w0, w1, w2, w3 ]; -* The translation components of a tranformation matrix would be stored in +* The translation components of a transformation matrix would be stored in * w0, w1, w2, or at indices 12, 13, and 14 of the array, as is consistent -* with opengl. +* with OpenGL. */ -mat4 = {} +// RDGE namespaces +var RDGE = RDGE || {}; +RDGE.mat4 = {}; /** -* mat4.string +* RDGE.mat4.string */ -mat4.string = function(m) { - var out = "{ "; - out += m[0] + ", " + m[1] + ", " + m[2] + ", " + m[3] + ", "; - out += m[4] + ", " + m[5] + ", " + m[6] + ", " + m[7] + ", "; - out += m[8] + ", " + m[9] + ", " + m[10] + ", " + m[11] + ", "; - out += m[12] + ", " + m[13] + ", " + m[14] + ", " + m[15] + " }"; - return out; -} +RDGE.mat4.string = function (m) { + var out = "{ "; + out += m[0] + ", " + m[1] + ", " + m[2] + ", " + m[3] + ", "; + out += m[4] + ", " + m[5] + ", " + m[6] + ", " + m[7] + ", "; + out += m[8] + ", " + m[9] + ", " + m[10] + ", " + m[11] + ", "; + out += m[12] + ", " + m[13] + ", " + m[14] + ", " + m[15] + " }"; + return out; +}; -mat4.toCSSString = function(m, conversionConstant) -{ +RDGE.mat4.toCSSString = function (m, conversionConstant) { var cc = 10.0; if (conversionConstant) cc = conversionConstant; - + var out = "matrix3d("; out += m[0].toFixed(10) + ", " + m[1].toFixed(10) + ", " + m[2].toFixed(10) + ", " + m[3].toFixed(10) + ", "; out += m[4].toFixed(10) + ", " + m[5].toFixed(10) + ", " + m[6].toFixed(10) + ", " + m[7].toFixed(10) + ", "; out += m[8].toFixed(10) + ", " + m[9].toFixed(10) + ", " + m[10].toFixed(10) + ", " + m[11].toFixed(10) + ", "; - out += m[12].toFixed(10)*cc + ", " + (600 - m[13].toFixed(10)*cc) + ", " + m[14].toFixed(10)*cc + ", " + m[15].toFixed(10) + ")"; + out += m[12].toFixed(10) * cc + ", " + (600 - m[13].toFixed(10) * cc) + ", " + m[14].toFixed(10) * cc + ", " + m[15].toFixed(10) + ")"; return out; -} +}; /** -* mat4.verify +* RDGE.mat4.verify * This function is provided for debugging purposes only. It is not recommended * to be used in performance critical areas of the code. */ -mat4.verify = function(m) { - if (m == undefined || m.length == undefined || m.length < 16) { - return false; - } - var i = 16; - while (i--) { - if (typeof (m[i]) != "number") { - return false; - } - } - return true; -} - -/** -* mat4.copy -*/ -mat4.copy = function(m) { - return [ m[0], m[1], m[2], m[3], - m[4], m[5], m[6], m[7], - m[8], m[9], m[10], m[11], - m[12], m[13], m[14], m[15] ]; -} - -/** -* mat4.inplace_copy -*/ -mat4.inplace_copy = function(dst, src) { - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - dst[3] = src[3]; - dst[4] = src[4]; - dst[5] = src[5]; - dst[6] = src[6]; - dst[7] = src[7]; - dst[8] = src[8]; - dst[9] = src[9]; - dst[10] = src[10]; - dst[11] = src[11]; - dst[12] = src[12]; - dst[13] = src[13]; - dst[14] = src[14]; - dst[15] = src[15]; -} - -/** -* mat4.identity -*/ -mat4.identity = function() { - return [ 1.0, 0.0, 0.0, 0.0, +RDGE.mat4.verify = function (m) { + if (m == undefined || m.length == undefined || m.length < 16) { + return false; + } + var i = 16; + while (i--) { + if (typeof (m[i]) != "number") { + return false; + } + } + return true; +}; + +/** +* RDGE.mat4.copy +*/ +RDGE.mat4.copy = function (m) { + return [m[0], m[1], m[2], m[3], + m[4], m[5], m[6], m[7], + m[8], m[9], m[10], m[11], + m[12], m[13], m[14], m[15]]; +}; + +/** +* RDGE.mat4.inplace_copy +*/ +RDGE.mat4.inplace_copy = function (dst, src) { + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = src[3]; + dst[4] = src[4]; + dst[5] = src[5]; + dst[6] = src[6]; + dst[7] = src[7]; + dst[8] = src[8]; + dst[9] = src[9]; + dst[10] = src[10]; + dst[11] = src[11]; + dst[12] = src[12]; + dst[13] = src[13]; + dst[14] = src[14]; + dst[15] = src[15]; +}; + +/** +* RDGE.mat4.identity +*/ +RDGE.mat4.identity = function () { + return [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0 ]; -} + 0.0, 0.0, 0.0, 1.0]; +}; /** -* mat4.zero +* RDGE.mat4.zero */ -mat4.zero = function() { - return [ 0.0, 0.0, 0.0, 0.0, +RDGE.mat4.zero = function () { + return [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0 ]; -} + 0.0, 0.0, 0.0, 0.0]; +}; /** -* mat4.basis +* RDGE.mat4.basis * description - construct a matrix with the given basis vectors. */ -mat4.basis = function( rowx, rowy, rowz, roww ) { - if( roww == null || roww == undefined ) { - return [ rowx[0], rowx[1], rowx[2], 0.0, +RDGE.mat4.basis = function (rowx, rowy, rowz, roww) { + if (roww == null || roww == undefined) { + return [rowx[0], rowx[1], rowx[2], 0.0, rowy[0], rowy[1], rowy[2], 0.0, rowz[0], rowz[1], rowz[2], 0.0, - 0, 0, 0, 1.0 ]; - } else { - return [ rowx[0], rowx[1], rowx[2], rowx.length == 4 ? rowx[3] : 0.0, + 0, 0, 0, 1.0]; + } else { + return [rowx[0], rowx[1], rowx[2], rowx.length == 4 ? rowx[3] : 0.0, rowy[0], rowy[1], rowy[2], rowy.length == 4 ? rowy[3] : 0.0, rowz[0], rowz[1], rowz[2], rowz.length == 4 ? rowz[3] : 0.0, - roww[0], roww[1], roww[2], roww.length == 4 ? roww[3] : 1.0 ]; - } -} - -/** -* mat4.angleAxis -*/ -mat4.angleAxis = function(angle, axis) { - // angles are in degrees. Switch to radians - angle *= (Math.PI / 180.0); - - angle /= 2; - var sinA = Math.sin(angle); - var cosA = Math.cos(angle); - var sinA2 = sinA * sinA; - - // normalize - vec3.normalize(axis); - if (vec3.lengthSq(axis) <= 0.0) { - axis = [0, 0, 0, 1]; - } - - var matR = mat4.identity(); - - // optimize case where axis is along major axis - if (axis[0] == 1 && axis[1] == 0 && axis[2] == 0) { - matR[5] = 1 - 2 * sinA2; - matR[6] = 2 * sinA * cosA; - matR[9] = -2 * sinA * cosA; - matR[10] = 1 - 2 * sinA2; - } else if (axis[0] == 0 && axis[1] == 1 && axis[2] == 0) { - matR[0] = 1 - 2 * sinA2; - matR[2] = -2 * sinA * cosA; - matR[8] = 2 * sinA * cosA; - matR[10] = 1 - 2 * sinA2; - } else if (axis[0] == 0 && axis[1] == 0 && axis[2] == 1) { - matR[0] = 1 - 2 * sinA2; - matR[1] = 2 * sinA * cosA; - matR[4] = -2 * sinA * cosA; - matR[5] = 1 - 2 * sinA2; - } else { - var x = axis[0]; - var y = axis[1]; - var z = axis[2]; - var x2 = x * x; - var y2 = y * y; - var z2 = z * z; - - matR[0] = 1 - 2 * (y2 + z2) * sinA2; - matR[1] = 2 * (x * y * sinA2 + z * sinA * cosA); - matR[2] = 2 * (x * z * sinA2 - y * sinA * cosA); - matR[4] = 2 * (y * x * sinA2 - z * sinA * cosA); - matR[5] = 1 - 2 * (z2 + x2) * sinA2; - matR[6] = 2 * (y * z * sinA2 + x * sinA * cosA); - matR[8] = 2 * (z * x * sinA2 + y * sinA * cosA); - matR[9] = 2 * (z * y * sinA2 - x * sinA * cosA); - matR[10] = 1 - 2 * (x2 + y2) * sinA2; - } - - return matR; -} - -/** -* mat4.lookAt -*/ -mat4.lookAt = function(eye, at, up) { -/* - var w_axis = new vec3(posVec.x, posVec.y, posVec.z); + roww[0], roww[1], roww[2], roww.length == 4 ? roww[3] : 1.0]; + } +}; + +/** +* RDGE.mat4.angleAxis +*/ +RDGE.mat4.angleAxis = function (angle, axis) { + // angles are in degrees. Switch to radians + angle *= (Math.PI / 180.0); + + angle /= 2; + var sinA = Math.sin(angle); + var cosA = Math.cos(angle); + var sinA2 = sinA * sinA; + + // normalize + RDGE.vec3.normalize(axis); + if (RDGE.vec3.lengthSq(axis) <= 0.0) { + axis = [0, 0, 0, 1]; + } + + var matR = RDGE.mat4.identity(); + + // optimize case where axis is along major axis + if (axis[0] == 1 && axis[1] == 0 && axis[2] == 0) { + matR[5] = 1 - 2 * sinA2; + matR[6] = 2 * sinA * cosA; + matR[9] = -2 * sinA * cosA; + matR[10] = 1 - 2 * sinA2; + } else if (axis[0] == 0 && axis[1] == 1 && axis[2] == 0) { + matR[0] = 1 - 2 * sinA2; + matR[2] = -2 * sinA * cosA; + matR[8] = 2 * sinA * cosA; + matR[10] = 1 - 2 * sinA2; + } else if (axis[0] == 0 && axis[1] == 0 && axis[2] == 1) { + matR[0] = 1 - 2 * sinA2; + matR[1] = 2 * sinA * cosA; + matR[4] = -2 * sinA * cosA; + matR[5] = 1 - 2 * sinA2; + } else { + var x = axis[0]; + var y = axis[1]; + var z = axis[2]; + var x2 = x * x; + var y2 = y * y; + var z2 = z * z; + + matR[0] = 1 - 2 * (y2 + z2) * sinA2; + matR[1] = 2 * (x * y * sinA2 + z * sinA * cosA); + matR[2] = 2 * (x * z * sinA2 - y * sinA * cosA); + matR[4] = 2 * (y * x * sinA2 - z * sinA * cosA); + matR[5] = 1 - 2 * (z2 + x2) * sinA2; + matR[6] = 2 * (y * z * sinA2 + x * sinA * cosA); + matR[8] = 2 * (z * x * sinA2 + y * sinA * cosA); + matR[9] = 2 * (z * y * sinA2 - x * sinA * cosA); + matR[10] = 1 - 2 * (x2 + y2) * sinA2; + } + + return matR; +}; + +/** +* RDGE.mat4.lookAt +*/ +RDGE.mat4.lookAt = function (eye, at, up) { + /* + var w_axis = new RDGE.vec3(posVec.x, posVec.y, posVec.z); - var z_axis = subVec3(targetVec, w_axis); - z_axis.normalize(); + var z_axis = subVec3(targetVec, w_axis); + z_axis.normalize(); - var x_axis = crossVec3(upVec, z_axis); - x_axis.normalize(); - - var y_axis = crossVec3(z_axis, x_axis); - y_axis.normalize(); -*/ - - var z = vec3.normalize(vec3.sub(eye, at)); - if (vec3.length(z) < 0.0001) { - z = [ 0, 0, 1 ]; - } - - var x = vec3.normalize(vec3.cross(up, z)); - var y = vec3.normalize(vec3.cross(z, x)); - var m = mat4.identity(); - - mat4.setRow(m, 0, x); - mat4.setRow(m, 1, y); - mat4.setRow(m, 2, z); - mat4.setRow(m, 3, eye); - - return m; -} - -/** -* mat4.frustum -*/ -mat4.frustum = function(left, right, bottom, top, near, far) { - var rl = right - left; - var tb = top - bottom; - var fn = far - near; - var n2 = 2.0 * near; - - var m = mat4.zero(); - m[0] = n2 / rl; - m[5] = n2 / tb; - m[8] = (right + left) / rl; - m[9] = (top + bottom) / tb; - m[10] = -(far + near) / fn; - m[11] = -1.0; - m[14] = -(n2 * far) / fn; - - return m; -} - -/** -* mat4.perspective -*/ -mat4.perspective = function(fov, aspect, near, far) { - var top = Math.tan(fov * Math.PI / 360.0) * near; - var bottom = -top; - var left = aspect * bottom; - var right = aspect * top; - - return mat4.frustum(left, right, bottom, top, near, far); -} - -/** -* mat4.orthographic -*/ -mat4.orthographic = function(left, right, top, bottom, near, far) { - var tx = (left + right) / (left - right); - var ty = (top + bottom) / (top - bottom); - var tz = (far + near) / (far - near); - - var m = mat4.zero(); - m[0] = 2.0 / (left - right); - m[5] = 2.0 / (top - bottom); - m[10] = -2.0 / (far - near); - m[12] = tx; - m[13] = ty; - m[14] = tz; - m[15] = 1.0; - - return m; -} - -/** -* mat4.mul -*/ -mat4.mul = function(a, b) { - // note: precaching the matrix elements saves 96 additional array lookups. - // this turns out to be significantly faster. - var a00 = a[0]; - var a01 = a[1]; - var a02 = a[2]; - var a03 = a[3]; - var a04 = a[4]; - var a05 = a[5]; - var a06 = a[6]; - var a07 = a[7]; - var a08 = a[8]; - var a09 = a[9]; - var a10 = a[10]; - var a11 = a[11]; - var a12 = a[12]; - var a13 = a[13]; - var a14 = a[14]; - var a15 = a[15]; - - var b00 = b[0]; - var b01 = b[1]; - var b02 = b[2]; - var b03 = b[3]; - var b04 = b[4]; - var b05 = b[5]; - var b06 = b[6]; - var b07 = b[7]; - var b08 = b[8]; - var b09 = b[9]; - var b10 = b[10]; - var b11 = b[11]; - var b12 = b[12]; - var b13 = b[13]; - var b14 = b[14]; - var b15 = b[15]; - - return [a00 * b00 + a01 * b04 + a02 * b08 + a03 * b12, + var x_axis = crossVec3(upVec, z_axis); + x_axis.normalize(); + + var y_axis = crossVec3(z_axis, x_axis); + y_axis.normalize(); + */ + + var z = RDGE.vec3.normalize(RDGE.vec3.sub(eye, at)); + if (RDGE.vec3.length(z) < 0.0001) { + z = [0, 0, 1]; + } + + var x = RDGE.vec3.normalize(RDGE.vec3.cross(up, z)); + var y = RDGE.vec3.normalize(RDGE.vec3.cross(z, x)); + var m = RDGE.mat4.identity(); + + RDGE.mat4.setRow(m, 0, x); + RDGE.mat4.setRow(m, 1, y); + RDGE.mat4.setRow(m, 2, z); + RDGE.mat4.setRow(m, 3, eye); + + return m; +}; + +/** +* RDGE.mat4.frustum +*/ +RDGE.mat4.frustum = function (left, right, bottom, top, near, far) { + var rl = right - left; + var tb = top - bottom; + var fn = far - near; + var n2 = 2.0 * near; + + var m = RDGE.mat4.zero(); + m[0] = n2 / rl; + m[5] = n2 / tb; + m[8] = (right + left) / rl; + m[9] = (top + bottom) / tb; + m[10] = -(far + near) / fn; + m[11] = -1.0; + m[14] = -(n2 * far) / fn; + + return m; +}; + +/** +* RDGE.mat4.perspective +*/ +RDGE.mat4.perspective = function (fov, aspect, near, far) { + var top = Math.tan(fov * Math.PI / 360.0) * near; + var bottom = -top; + var left = aspect * bottom; + var right = aspect * top; + + return RDGE.mat4.frustum(left, right, bottom, top, near, far); +}; + +/** +* RDGE.mat4.orthographic +*/ +RDGE.mat4.orthographic = function (left, right, top, bottom, near, far) { + var tx = (left + right) / (left - right); + var ty = (top + bottom) / (top - bottom); + var tz = (far + near) / (far - near); + + var m = RDGE.mat4.zero(); + m[0] = 2.0 / (left - right); + m[5] = 2.0 / (top - bottom); + m[10] = -2.0 / (far - near); + m[12] = tx; + m[13] = ty; + m[14] = tz; + m[15] = 1.0; + + return m; +}; + +/** +* RDGE.mat4.mul +*/ +RDGE.mat4.mul = function (a, b) { + // note: precaching the matrix elements saves 96 additional array lookups. + // this turns out to be significantly faster. + var a00 = a[0]; + var a01 = a[1]; + var a02 = a[2]; + var a03 = a[3]; + var a04 = a[4]; + var a05 = a[5]; + var a06 = a[6]; + var a07 = a[7]; + var a08 = a[8]; + var a09 = a[9]; + var a10 = a[10]; + var a11 = a[11]; + var a12 = a[12]; + var a13 = a[13]; + var a14 = a[14]; + var a15 = a[15]; + + var b00 = b[0]; + var b01 = b[1]; + var b02 = b[2]; + var b03 = b[3]; + var b04 = b[4]; + var b05 = b[5]; + var b06 = b[6]; + var b07 = b[7]; + var b08 = b[8]; + var b09 = b[9]; + var b10 = b[10]; + var b11 = b[11]; + var b12 = b[12]; + var b13 = b[13]; + var b14 = b[14]; + var b15 = b[15]; + + return [a00 * b00 + a01 * b04 + a02 * b08 + a03 * b12, a00 * b01 + a01 * b05 + a02 * b09 + a03 * b13, a00 * b02 + a01 * b06 + a02 * b10 + a03 * b14, a00 * b03 + a01 * b07 + a02 * b11 + a03 * b15, @@ -356,44 +347,44 @@ mat4.mul = function(a, b) { a12 * b01 + a13 * b05 + a14 * b09 + a15 * b13, a12 * b02 + a13 * b06 + a14 * b10 + a15 * b14, a12 * b03 + a13 * b07 + a14 * b11 + a15 * b15]; -} +}; /** -* mat4.mul4x3 +* RDGE.mat4.mul4x3 * This version cuts 28 multiplies and 21 adds. */ -mat4.mul4x3 = function(a, b) { - // note: precaching the matrix elements cuts redundant array lookups. - var a00 = a[0]; - var a01 = a[1]; - var a02 = a[2]; - - var a04 = a[4]; - var a05 = a[5]; - var a06 = a[6]; - - var a08 = a[8]; - var a09 = a[9]; - var a10 = a[10]; - - var a12 = a[12]; - var a13 = a[13]; - var a14 = a[14]; - - var b00 = b[0]; - var b01 = b[1]; - var b02 = b[2]; - var b04 = b[4]; - var b05 = b[5]; - var b06 = b[6]; - var b08 = b[8]; - var b09 = b[9]; - var b10 = b[10]; - var b12 = b[12]; - var b13 = b[13]; - var b14 = b[14]; - - return [a00 * b00 + a01 * b04 + a02 * b08, +RDGE.mat4.mul4x3 = function (a, b) { + // note: precaching the matrix elements cuts redundant array lookups. + var a00 = a[0]; + var a01 = a[1]; + var a02 = a[2]; + + var a04 = a[4]; + var a05 = a[5]; + var a06 = a[6]; + + var a08 = a[8]; + var a09 = a[9]; + var a10 = a[10]; + + var a12 = a[12]; + var a13 = a[13]; + var a14 = a[14]; + + var b00 = b[0]; + var b01 = b[1]; + var b02 = b[2]; + var b04 = b[4]; + var b05 = b[5]; + var b06 = b[6]; + var b08 = b[8]; + var b09 = b[9]; + var b10 = b[10]; + var b12 = b[12]; + var b13 = b[13]; + var b14 = b[14]; + + return [a00 * b00 + a01 * b04 + a02 * b08, a00 * b01 + a01 * b05 + a02 * b09, a00 * b02 + a01 * b06 + a02 * b10, 0, @@ -410,30 +401,30 @@ mat4.mul4x3 = function(a, b) { a12 * b00 + a13 * b04 + a14 * b08 + b12, a12 * b01 + a13 * b05 + a14 * b09 + b13, - a12 * b02 + a13 * b06 + a14 * b10 + b14, - 1.0 ]; -} + a12 * b02 + a13 * b06 + a14 * b10 + b14, + 1.0]; +}; /** -* mat4._det2x2 +* RDGE.mat4._det2x2 */ -mat4._det2x2 = function(a, b, c, d) { +RDGE.mat4._det2x2 = function(a, b, c, d) { return a * d - b * c; }; /** -* mat4._det3x3 +* RDGE.mat4._det3x3 */ -mat4._det3x3 = function(a1, a2, a3, b1, b2, b3, c1, c2, c3) { - return a1 * mat4._det2x2(b2, b3, c2, c3) - - b1 * mat4._det2x2(a2, a3, c2, c3) - + c1 * mat4._det2x2(a2, a3, b2, b3); +RDGE.mat4._det3x3 = function(a1, a2, a3, b1, b2, b3, c1, c2, c3) { + return a1 * RDGE.mat4._det2x2(b2, b3, c2, c3) + - b1 * RDGE.mat4._det2x2(a2, a3, c2, c3) + + c1 * RDGE.mat4._det2x2(a2, a3, b2, b3); }; /** -* mat4._det4x4 +* RDGE.mat4._det4x4 */ -mat4._det4x4 = function(m) { +RDGE.mat4._det4x4 = function(m) { var a1 = m[0]; var b1 = m[1]; var c1 = m[2]; @@ -454,301 +445,301 @@ mat4._det4x4 = function(m) { var c4 = m[14]; var d4 = m[15]; - return a1 * mat4._det3x3(b2, b3, b4, c2, c3, c4, d2, d3, d4) - - b1 * mat4._det3x3(a2, a3, a4, c2, c3, c4, d2, d3, d4) - + c1 * mat4._det3x3(a2, a3, a4, b2, b3, b4, d2, d3, d4) - - d1 * mat4._det3x3(a2, a3, a4, b2, b3, b4, c2, c3, c4); + return a1 * RDGE.mat4._det3x3(b2, b3, b4, c2, c3, c4, d2, d3, d4) + - b1 * RDGE.mat4._det3x3(a2, a3, a4, c2, c3, c4, d2, d3, d4) + + c1 * RDGE.mat4._det3x3(a2, a3, a4, b2, b3, b4, d2, d3, d4) + - d1 * RDGE.mat4._det3x3(a2, a3, a4, b2, b3, b4, c2, c3, c4); }; /** -* mat4._adjoint -*/ -mat4._adjoint = function(m) { - var a1 = m[0]; - var b1 = m[1]; - var c1 = m[2]; - var d1 = m[3]; +* RDGE.mat4._adjoint +*/ +RDGE.mat4._adjoint = function (m) { + var a1 = m[0]; + var b1 = m[1]; + var c1 = m[2]; + var d1 = m[3]; + + var a2 = m[4]; + var b2 = m[5]; + var c2 = m[6]; + var d2 = m[7]; + + var a3 = m[8]; + var b3 = m[9]; + var c3 = m[10]; + var d3 = m[11]; + + var a4 = m[12]; + var b4 = m[13]; + var c4 = m[14]; + var d4 = m[15]; + + return [RDGE.mat4._det3x3(b2, b3, b4, c2, c3, c4, d2, d3, d4), + -RDGE.mat4._det3x3(b1, b3, b4, c1, c3, c4, d1, d3, d4), + RDGE.mat4._det3x3(b1, b2, b4, c1, c2, c4, d1, d2, d4), + -RDGE.mat4._det3x3(b1, b2, b3, c1, c2, c3, d1, d2, d3), + -RDGE.mat4._det3x3(a2, a3, a4, c2, c3, c4, d2, d3, d4), + RDGE.mat4._det3x3(a1, a3, a4, c1, c3, c4, d1, d3, d4), + -RDGE.mat4._det3x3(a1, a2, a4, c1, c2, c4, d1, d2, d4), + RDGE.mat4._det3x3(a1, a2, a3, c1, c2, c3, d1, d2, d3), + RDGE.mat4._det3x3(a2, a3, a4, b2, b3, b4, d2, d3, d4), + -RDGE.mat4._det3x3(a1, a3, a4, b1, b3, b4, d1, d3, d4), + RDGE.mat4._det3x3(a1, a2, a4, b1, b2, b4, d1, d2, d4), + -RDGE.mat4._det3x3(a1, a2, a3, b1, b2, b3, d1, d2, d3), + -RDGE.mat4._det3x3(a2, a3, a4, b2, b3, b4, c2, c3, c4), + RDGE.mat4._det3x3(a1, a3, a4, b1, b3, b4, c1, c3, c4), + -RDGE.mat4._det3x3(a1, a2, a4, b1, b2, b4, c1, c2, c4), + RDGE.mat4._det3x3(a1, a2, a3, b1, b2, b3, c1, c2, c3)]; +}; - var a2 = m[4]; - var b2 = m[5]; - var c2 = m[6]; - var d2 = m[7]; +/** +* RDGE.mat4.inverse +*/ +RDGE.mat4.inverse = function (m) { + // Calculate the 4x4 determinant + // If the determinant is zero, + // then the inverse matrix is not unique. + var det = RDGE.mat4._det4x4(m); - var a3 = m[8]; - var b3 = m[9]; - var c3 = m[10]; - var d3 = m[11]; + if (Math.abs(det) < 1e-8) { + // this is an error condition. + return null; + } - var a4 = m[12]; - var b4 = m[13]; - var c4 = m[14]; - var d4 = m[15]; + var adj = RDGE.mat4._adjoint(m); + var ood = 1.0 / det; - return [ mat4._det3x3(b2, b3, b4, c2, c3, c4, d2, d3, d4), - -mat4._det3x3(b1, b3, b4, c1, c3, c4, d1, d3, d4), - mat4._det3x3(b1, b2, b4, c1, c2, c4, d1, d2, d4), - -mat4._det3x3(b1, b2, b3, c1, c2, c3, d1, d2, d3), - -mat4._det3x3(a2, a3, a4, c2, c3, c4, d2, d3, d4), - mat4._det3x3(a1, a3, a4, c1, c3, c4, d1, d3, d4), - -mat4._det3x3(a1, a2, a4, c1, c2, c4, d1, d2, d4), - mat4._det3x3(a1, a2, a3, c1, c2, c3, d1, d2, d3), - mat4._det3x3(a2, a3, a4, b2, b3, b4, d2, d3, d4), - -mat4._det3x3(a1, a3, a4, b1, b3, b4, d1, d3, d4), - mat4._det3x3(a1, a2, a4, b1, b2, b4, d1, d2, d4), - -mat4._det3x3(a1, a2, a3, b1, b2, b3, d1, d2, d3), - -mat4._det3x3(a2, a3, a4, b2, b3, b4, c2, c3, c4), - mat4._det3x3(a1, a3, a4, b1, b3, b4, c1, c3, c4), - -mat4._det3x3(a1, a2, a4, b1, b2, b4, c1, c2, c4), - mat4._det3x3(a1, a2, a3, b1, b2, b3, c1, c2, c3) ]; -} - -/** -* mat4.inverse -*/ -mat4.inverse = function(m) { - // Calculate the 4x4 determinant - // If the determinant is zero, - // then the inverse matrix is not unique. - var det = mat4._det4x4(m); - - if (Math.abs(det) < 1e-8) { - // this is an error condition. - return null; - } - - var adj = mat4._adjoint(m); - var ood = 1.0 / det; - - return [ adj[0] * ood, adj[1] * ood, adj[2] * ood, adj[3] * ood, + return [adj[0] * ood, adj[1] * ood, adj[2] * ood, adj[3] * ood, adj[4] * ood, adj[5] * ood, adj[6] * ood, adj[7] * ood, adj[8] * ood, adj[9] * ood, adj[10] * ood, adj[11] * ood, - adj[12] * ood, adj[13] * ood, adj[14] * ood, adj[15] * ood ]; -} + adj[12] * ood, adj[13] * ood, adj[14] * ood, adj[15] * ood]; +}; /** -* mat4.rigidinverse +* RDGE.mat4.rigidinverse */ -mat4.rigidInverse = function(m) { - out = mat4.transpose3x3(m); - out[12] = -vec3.dot( [ out[0], out[4], out[8] ], [ m[12], m[13], m[14] ] ); - out[13] = -vec3.dot( [ out[1], out[5], out[9] ], [ m[12], m[13], m[14] ] ); - out[14] = -vec3.dot( [ out[2], out[6], out[10] ], [ m[12], m[13], m[14] ] ); - return out; -} +RDGE.mat4.rigidInverse = function (m) { + out = RDGE.mat4.transpose3x3(m); + out[12] = -RDGE.vec3.dot([out[0], out[4], out[8]], [m[12], m[13], m[14]]); + out[13] = -RDGE.vec3.dot([out[1], out[5], out[9]], [m[12], m[13], m[14]]); + out[14] = -RDGE.vec3.dot([out[2], out[6], out[10]], [m[12], m[13], m[14]]); + return out; +}; /** -* mat4.transpose +* RDGE.mat4.transpose */ -mat4.transpose = function(m) { - return [ m[0], m[4], m[8], m[12], - m[1], m[5], m[9], m[13], - m[2], m[6], m[10], m[14], - m[3], m[7], m[11], m[15] ]; -} +RDGE.mat4.transpose = function (m) { + return [m[0], m[4], m[8], m[12], + m[1], m[5], m[9], m[13], + m[2], m[6], m[10], m[14], + m[3], m[7], m[11], m[15]]; +}; /** -* mat4.transpose3x3 +* RDGE.mat4.transpose3x3 */ -mat4.transpose3x3 = function(m) { - return [ m[0], m[4], m[8], m[3], - m[1], m[5], m[9], m[7], - m[2], m[6], m[10], m[11], - m[12], m[13], m[14], m[15] ]; -} +RDGE.mat4.transpose3x3 = function (m) { + return [m[0], m[4], m[8], m[3], + m[1], m[5], m[9], m[7], + m[2], m[6], m[10], m[11], + m[12], m[13], m[14], m[15]]; +}; /** -* mat4.transformPoint +* RDGE.mat4.transformPoint */ -mat4.transformPoint = function(m, v) { - var x = v[0], y = v[1], z = v[2], w = v.length >= 4 ? v[3] : 1.0; - return [m[0] * x + m[4] * y + m[8] * z + m[12] * w, +RDGE.mat4.transformPoint = function (m, v) { + var x = v[0], y = v[1], z = v[2], w = v.length >= 4 ? v[3] : 1.0; + return [m[0] * x + m[4] * y + m[8] * z + m[12] * w, m[1] * x + m[5] * y + m[9] * z + m[13] * w, m[2] * x + m[6] * y + m[10] * z + m[14] * w, m[3] * x + m[7] * y + m[11] * z + m[15] * w]; - // 12 adds, 16 multiplies, 16 lookups. -} + // 12 adds, 16 multiplies, 16 lookups. +}; /** -* mat4.transformVector +* RDGE.mat4.transformVector */ -mat4.transformVector = function(m, v) { - m = mat4.inverse(m); - var x = v[0], y = v[1], z = v[2], w = v.length >= 4 ? v[3] : 0.0; - // 12 adds, 16 multiplies, 16 lookups. - // transpose multiply - return [ m[0] * x + m[1] * y + m[2] * z + m[3] * w, +RDGE.mat4.transformVector = function (m, v) { + m = RDGE.mat4.inverse(m); + var x = v[0], y = v[1], z = v[2], w = v.length >= 4 ? v[3] : 0.0; + // 12 adds, 16 multiplies, 16 lookups. + // transpose multiply + return [m[0] * x + m[1] * y + m[2] * z + m[3] * w, m[4] * x + m[5] * y + m[6] * z + m[7] * w, m[8] * x + m[9] * y + m[10] * z + m[11] * w, - m[12] * x + m[13] * y + m[14] * z + m[15] * w ]; -} + m[12] * x + m[13] * y + m[14] * z + m[15] * w]; +}; /** -* mat4.transformVector4x3 +* RDGE.mat4.transformVector4x3 */ -mat4.transformPoint4x3 = function(m, v) { - // assumes m[3], m[7], m[11], m[15] equal 0, 0, 0, 1 - var x = v[0], y = v[1], z = v[2]; - // 9 adds, 9 multiplies, 16 lookups. - return [ m[0] * x + m[4] * y + m[8] * z + m[12], +RDGE.mat4.transformPoint4x3 = function (m, v) { + // assumes m[3], m[7], m[11], m[15] equal 0, 0, 0, 1 + var x = v[0], y = v[1], z = v[2]; + // 9 adds, 9 multiplies, 16 lookups. + return [m[0] * x + m[4] * y + m[8] * z + m[12], m[1] * x + m[5] * y + m[9] * z + m[13], m[2] * x + m[6] * y + m[10] * z + m[14], - 1.0 ]; -} + 1.0]; +}; /** -* mat4.transformVector4x3 +* RDGE.mat4.transformVector4x3 * this implementation saves 3 adds and 7 multiplies */ -mat4.transformVector4x3 = function(m, v) { - m = mat4.inverse(m); - var x = v[0], y = v[1], z = v[2]; - return [ m[0] * x + m[1] * y + m[2] * z, +RDGE.mat4.transformVector4x3 = function (m, v) { + m = RDGE.mat4.inverse(m); + var x = v[0], y = v[1], z = v[2]; + return [m[0] * x + m[1] * y + m[2] * z, m[4] * x + m[5] * y + m[6] * z, m[8] * x + m[9] * y + m[10] * z, - 0.0 ]; -} + 0.0]; +}; /** -* mat4.getRow +* RDGE.mat4.getRow */ -mat4.getRow = function(m, i) { - i *= 4; - return [ m[i], m[i+1], m[i+2], m[i+3] ]; -} +RDGE.mat4.getRow = function (m, i) { + i *= 4; + return [m[i], m[i + 1], m[i + 2], m[i + 3]]; +}; /** -* mat4.getCol +* RDGE.mat4.getCol */ -mat4.getCol = function(m, i) { - return [ m[i], m[i+4], m[i+8], m[i+12] ]; -} +RDGE.mat4.getCol = function (m, i) { + return [m[i], m[i + 4], m[i + 8], m[i + 12]]; +}; /** -* mat4.setRow +* RDGE.mat4.setRow */ -mat4.setRow = function(m, i, v) { - i *= 4; - m[i + 0] = v[0]; - m[i + 1] = v[1]; - m[i + 2] = v[2]; +RDGE.mat4.setRow = function (m, i, v) { + i *= 4; + m[i + 0] = v[0]; + m[i + 1] = v[1]; + m[i + 2] = v[2]; - if (v.length >= 4) { - m[i + 3] = v[3]; - } + if (v.length >= 4) { + m[i + 3] = v[3]; + } - return m; -} + return m; +}; /** -* mat4.setCol +* RDGE.mat4.setCol */ -mat4.setCol = function(m, i, v) { - m[i + 0] = v[0]; - m[i + 4] = v[1]; - m[i + 8] = v[2]; - if (v.length >= 4) { - m[i + 12] = v[3]; - } +RDGE.mat4.setCol = function (m, i, v) { + m[i + 0] = v[0]; + m[i + 4] = v[1]; + m[i + 8] = v[2]; + if (v.length >= 4) { + m[i + 12] = v[3]; + } - return m; -} + return m; +}; /** -* mat4.rotate +* RDGE.mat4.rotate */ -mat4.rotate = function(m, angle, axis) { - return mat4.mul(m, mat4.angleAxis(angle, axis)); -} +RDGE.mat4.rotate = function (m, angle, axis) { + return RDGE.mat4.mul(m, RDGE.mat4.angleAxis(angle, axis)); +}; /** -* mat4.rotateX +* RDGE.mat4.rotateX */ -mat4.rotateX = function(m, angle) { - return mat4.mul( m, mat4.angleAxis(angle, vec3.basisX(m) ) ); -} +RDGE.mat4.rotateX = function (m, angle) { + return RDGE.mat4.mul(m, RDGE.mat4.angleAxis(angle, RDGE.vec3.basisX(m))); +}; /** -* mat4.rotateY +* RDGE.mat4.rotateY */ -mat4.rotateY = function(m, angle) { - return mat4.mul( m, mat4.angleAxis(angle, vec3.basisY(m)) ); -} +RDGE.mat4.rotateY = function (m, angle) { + return RDGE.mat4.mul(m, RDGE.mat4.angleAxis(angle, RDGE.vec3.basisY(m))); +}; /** -* mat4.rotateZ +* RDGE.mat4.rotateZ */ -mat4.rotateZ = function(m, angle) { - return mat4.mul( m, mat4.angleAxis(angle, vec3.basisZ(m)) ); -} +RDGE.mat4.rotateZ = function (m, angle) { + return RDGE.mat4.mul(m, RDGE.mat4.angleAxis(angle, RDGE.vec3.basisZ(m))); +}; /** -* mat4.scale +* RDGE.mat4.scale */ -mat4.scale = function(m, s) { - var sMat = mat4.identity(); - - if (s.length == undefined) { - s = [s, s, s]; - } - - sMat[0] = s[0]; - sMat[5] = s[1]; - sMat[10] = s[2]; - - return mat4.mul(m, sMat); -} +RDGE.mat4.scale = function (m, s) { + var sMat = RDGE.mat4.identity(); + + if (s.length == undefined) { + s = [s, s, s]; + } + + sMat[0] = s[0]; + sMat[5] = s[1]; + sMat[10] = s[2]; + + return RDGE.mat4.mul(m, sMat); +}; /** -* mat4.scaleX +* RDGE.mat4.scaleX */ -mat4.scaleX = function(m, s) { - return mat4.scale(m, [s,1.0,1.0]); -} +RDGE.mat4.scaleX = function (m, s) { + return RDGE.mat4.scale(m, [s, 1.0, 1.0]); +}; /** -* mat4.scaleY +* RDGE.mat4.scaleY */ -mat4.scaleY = function(m, s) { - return mat4.scale(m, [1.0,s,1.0]); -} +RDGE.mat4.scaleY = function (m, s) { + return RDGE.mat4.scale(m, [1.0, s, 1.0]); +}; /** -* mat4.scaleZ +* RDGE.mat4.scaleZ */ -mat4.scaleZ = function(m, s) { - return mat4.scale(m, [1.0,1.0,s]); -} +RDGE.mat4.scaleZ = function (m, s) { + return RDGE.mat4.scale(m, [1.0, 1.0, s]); +}; /** -* mat4.translate +* RDGE.mat4.translate */ -mat4.translate = function(m, t) { - matT = mat4.identity(); - - matT[12] = t[0]; - matT[13] = t[1]; - matT[14] = t[2]; +RDGE.mat4.translate = function (m, t) { + matT = RDGE.mat4.identity(); + + matT[12] = t[0]; + matT[13] = t[1]; + matT[14] = t[2]; - return mat4.mul(m, matT); -} + return RDGE.mat4.mul(m, matT); +}; /** -* mat4.translateX +* RDGE.mat4.translateX */ -mat4.translateX = function(m, t) { - return mat4.translate(m, [t,0,0]); -} +RDGE.mat4.translateX = function (m, t) { + return RDGE.mat4.translate(m, [t, 0, 0]); +}; /** -* mat4.translateY +* RDGE.mat4.translateY */ -mat4.translateY = function(m, t) { - return mat4.translate(m, [0,t,0]); -} +RDGE.mat4.translateY = function (m, t) { + return RDGE.mat4.translate(m, [0, t, 0]); +}; /** -* mat4.translateZ +* RDGE.mat4.translateZ */ -mat4.translateZ = function(m, t) { - return mat4.translate(m, [0,0,t]); -} +RDGE.mat4.translateZ = function (m, t) { + return RDGE.mat4.translate(m, [0, 0, t]); +}; diff --git a/js/helper-classes/RDGE/src/core/script/math/quat.js b/js/helper-classes/RDGE/src/core/script/math/quat.js index 5c2c8bb6..f3c44d11 100755 --- a/js/helper-classes/RDGE/src/core/script/math/quat.js +++ b/js/helper-classes/RDGE/src/core/script/math/quat.js @@ -6,210 +6,211 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot /** -* quat = {} +* RDGE.quat = {} * This library contains utility functions for operating on quaternions. * -- * TODO: * -need to add more helper functions for generating quaternions from * other representations (i.e. - eulers, angle-axis). */ -quat = {} +var RDGE = RDGE || {}; +RDGE.quat = {}; /** -* vec4.string +* RDGE.quat.string */ -quat.string = function(q) { - return "{ " + q[0] + ", " + q[1] + ", " + q[2] + ", " + q[3] + " }"; -} +RDGE.quat.string = function (q) { + return "{ " + q[0] + ", " + q[1] + ", " + q[2] + ", " + q[3] + " }"; +}; /** -* quat.verify +* RDGE.quat.verify */ -quat.verify = function(q) { - if (q == undefined || q.length == undefined || q.length < 4) { - return false; - } +RDGE.quat.verify = function (q) { + if (q == undefined || q.length == undefined || q.length < 4) { + return false; + } - if (typeof (q[0]) != "number" || typeof (q[1]) != "number" || typeof (q[2]) != "number" || typeof (q[3]) != "number") { - return false; - } + if (typeof (q[0]) != "number" || typeof (q[1]) != "number" || typeof (q[2]) != "number" || typeof (q[3]) != "number") { + return false; + } - return true; -} + return true; +}; /** -* quat.identity +* RDGE.quat.identity */ -quat.identity = function() { - return [0.0, 0.0, 0.0, 1.0]; -} +RDGE.quat.identity = function () { + return [0.0, 0.0, 0.0, 1.0]; +}; /** -* quat.add +* RDGE.quat.add */ -quat.add = function(a, b) { - return [ a[0] + b[0], +RDGE.quat.add = function (a, b) { + return [a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3] + b[3]]; -} +}; /** -* quat.sub +* RDGE.quat.sub */ -quat.sub = function(a, b) { - return [ a[0] - b[0], +RDGE.quat.sub = function (a, b) { + return [a[0] - b[0], a[1] - b[1], a[2] - b[2], a[3] - b[3]]; -} +}; /** -* quat.mul +* RDGE.quat.mul */ -quat.mul = function( a, b ) { - return [ a[3]*b[3] - a[0]*b[0] - a[1]*b[1] - a[2]*b[2], - a[3]*b[0] + a[0]*b[3] + a[1]*b[2] - a[2]*b[1], - a[3]*b[1] - a[0]*b[2] + a[1]*b[3] + a[2]*b[0], - a[3]*b[2] + a[0]*b[1] - a[1]*b[0] + a[2]*b[3] ]; -} +RDGE.quat.mul = function (a, b) { + return [a[3] * b[3] - a[0] * b[0] - a[1] * b[1] - a[2] * b[2], + a[3] * b[0] + a[0] * b[3] + a[1] * b[2] - a[2] * b[1], + a[3] * b[1] - a[0] * b[2] + a[1] * b[3] + a[2] * b[0], + a[3] * b[2] + a[0] * b[1] - a[1] * b[0] + a[2] * b[3]]; +}; /** -* quat.addMul +* RDGE.quat.addMul */ -quat.addMul = function(a, b, s) { - if (s.length != undefined && s.length >= 4) { - return [a[0] + b[0] * s[0], a[1] + b[1] * s[1], a[2] + b[2] * s[2], a[3] + b[3] * s[3]]; - } else { - return [a[0] + b[0] * s, a[1] + b[1] * s, a[2] + b[2] * s, a[3] + b[3] * s]; - } -} +RDGE.quat.addMul = function (a, b, s) { + if (s.length != undefined && s.length >= 4) { + return [a[0] + b[0] * s[0], a[1] + b[1] * s[1], a[2] + b[2] * s[2], a[3] + b[3] * s[3]]; + } else { + return [a[0] + b[0] * s, a[1] + b[1] * s, a[2] + b[2] * s, a[3] + b[3] * s]; + } +}; /** -* quat.scale +* RDGE.quat.scale */ -quat.scale = function(q, s) { - if (s.length != undefined && s.length >= 4) { - return [q[0] * s[0], q[1] * q[1], q[2] * s[2], q[3] * s[3]]; - } else { - return [q[0] * s, q[1] * s, q[2] * s, q[3] * s]; - } -} +RDGE.quat.scale = function (q, s) { + if (s.length != undefined && s.length >= 4) { + return [q[0] * s[0], q[1] * q[1], q[2] * s[2], q[3] * s[3]]; + } else { + return [q[0] * s, q[1] * s, q[2] * s, q[3] * s]; + } +}; /** -* quat.lengthSq +* RDGE.quat.lengthSq */ -quat.lengthSq = function(q) { - return q[0] * q[0] + +RDGE.quat.lengthSq = function (q) { + return q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]; -} +}; /** -* quat.length +* RDGE.quat.length */ -quat.length = function(q) { - return Math.sqrt( q[0] * q[0] + +RDGE.quat.length = function (q) { + return Math.sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]); -} +}; /** -* quat.normalize +* RDGE.quat.normalize */ -quat.normalize = function(q) { - var l = Math.sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]); - if (Math.abs(1.0 - l) > 0.0001) { - var ool = 1.0 / l; - return [q[0] * ool, q[1] * ool, q[2] * ool, q[3] * ool]; - } - return q; -} +RDGE.quat.normalize = function (q) { + var l = Math.sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]); + if (Math.abs(1.0 - l) > 0.0001) { + var ool = 1.0 / l; + return [q[0] * ool, q[1] * ool, q[2] * ool, q[3] * ool]; + } + return q; +}; /** -* quat.inverse +* RDGE.quat.inverse */ -quat.inverse = function(q) { - var n = vec4.lengthSq( q ); - if( n > 0.00001 ) { - n = 1.0 / n; - return [ q[0] * -n, q[1] * -n, q[2] * -n, q[3] ]; - } else { - // error condition - } - return q; -} +RDGE.quat.inverse = function (q) { + var n = RDGE.vec4.lengthSq(q); + if (n > 0.00001) { + n = 1.0 / n; + return [q[0] * -n, q[1] * -n, q[2] * -n, q[3]]; + } else { + // error condition + } + return q; +}; /** -* quat.dot +* RDGE.quat.dot */ -quat.dot = function(a, b) { - return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; -} +RDGE.quat.dot = function (a, b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; +}; /** -* quat.applyRotation +* RDGE.quat.applyRotation */ -quat.applyRotation = function(q, v) { - return mat4.transformPoint(quat.toMatrix(q), v); -} +RDGE.quat.applyRotation = function (q, v) { + return RDGE.mat4.transformPoint(RDGE.quat.toMatrix(q), v); +}; /** -* quat.lerp +* RDGE.quat.lerp */ -quat.lerp = function(q0, q1, t) { - return quat.normalize( [ q0[0] + (q1[0] - q0[0]) * t, q0[1] + (q1[1] - q0[1]) * t, q0[2] + (q1[2] - q0[2]) * t, q0[3] + (q1[3] - q0[3]) * t ] ); -} +RDGE.quat.lerp = function (q0, q1, t) { + return RDGE.quat.normalize([q0[0] + (q1[0] - q0[0]) * t, q0[1] + (q1[1] - q0[1]) * t, q0[2] + (q1[2] - q0[2]) * t, q0[3] + (q1[3] - q0[3]) * t]); +}; /** -* quat.slerp +* RDGE.quat.slerp */ -quat.slerp = function(q0, q1, t) { - var c = quat.dot(q0, q1); // cosine of the angle +RDGE.quat.slerp = function (q0, q1, t) { + var c = RDGE.quat.dot(q0, q1); // cosine of the angle // just lerp if the quats are "close" enough if (c >= 0.9) { - return quat.lerp(q0, q1, t); + return RDGE.quat.lerp(q0, q1, t); } - var s = Math.sqrt(Math.abs(1.0 - c * c)); // sine of the angle + var s = Math.sqrt(Math.abs(1.0 - c * c)); // sine of the angle if (s < 0.001) return q0; // too close var sign = c < 0.0 ? -1.0 : 1.0; var angle = Math.asin(s); - var invs = 1.0 / s; // sine^-1 - var coef0 = Math.sin((1.0 - t) * angle) * invs; // interp. coefficients + var invs = 1.0 / s; // sine^-1 + var coef0 = Math.sin((1.0 - t) * angle) * invs; // interp. coefficients var coef1 = Math.sin(t * angle) * invs * sign; - quat.scale(q0, coef0); - quat.scale(q1, coef1); + RDGE.quat.scale(q0, coef0); + RDGE.quat.scale(q1, coef1); - return quat.normalize( quat.add(q0, q1) ); -} + return RDGE.quat.normalize(RDGE.quat.add(q0, q1)); +}; /** -* quat.toMatrix +* RDGE.quat.toMatrix */ -quat.toMatrix = function(q) { - var tx = 2.0 * q[0]; - var ty = 2.0 * q[1]; - var tz = 2.0 * q[2]; - var twx = tx * q[3]; - var twy = ty * q[3]; - var twz = tz * q[3]; - var txx = tx * q[0]; - var txy = ty * q[0]; - var txz = tz * q[0]; - var tyy = ty * q[1]; - var tyz = tz * q[1]; - var tzz = tz * q[2]; +RDGE.quat.toMatrix = function (q) { + var tx = 2.0 * q[0]; + var ty = 2.0 * q[1]; + var tz = 2.0 * q[2]; + var twx = tx * q[3]; + var twy = ty * q[3]; + var twz = tz * q[3]; + var txx = tx * q[0]; + var txy = ty * q[0]; + var txz = tz * q[0]; + var tyy = ty * q[1]; + var tyz = tz * q[1]; + var tzz = tz * q[2]; - return [ 1.0 - (tyy + tzz), + return [1.0 - (tyy + tzz), txy + twz, txz - twy, 0, @@ -221,5 +222,5 @@ quat.toMatrix = function(q) { tyz - twx, 1.0 - (txx + tyy), 0, 0, 0, 0, 1]; -} +}; diff --git a/js/helper-classes/RDGE/src/core/script/math/vec2.js b/js/helper-classes/RDGE/src/core/script/math/vec2.js index 5f1b07e3..9cdfb89f 100755 --- a/js/helper-classes/RDGE/src/core/script/math/vec2.js +++ b/js/helper-classes/RDGE/src/core/script/math/vec2.js @@ -6,186 +6,187 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot /** -* vec2 = {} +* RDGE.vec2 = {} * This library contains functions for operating on 2D vectors. * A 2D vector can be any array containing at least 2 numeric components. -* All of the following are valid methods for declaring a vec2: +* All of the following are valid methods for declaring a RDGE.vec2: * var a = [0, 1]; -* var b = vec2.zero(); -* var c = vec2.up(); +* var b = RDGE.vec2.zero(); +* var c = RDGE.vec2.up(); */ -vec2 = {}; +var RDGE = RDGE || {}; +RDGE.vec2 = {}; /** -* vec2.string +* RDGE.vec2.string */ -vec2.string = function(v) { - return "{ " + v[0] + ", " + v[1] + " }"; -} +RDGE.vec2.string = function (v) { + return "{ " + v[0] + ", " + v[1] + " }"; +}; /** -* vec2.verify +* RDGE.vec2.verify * This function is provided for debugging purposes only. It is not recommended * to be used in performance critical areas of the code. */ -vec2.verify = function(v) { - if (v == undefined || v.length == undefined || v.length < 2) { - return false; - } +RDGE.vec2.verify = function (v) { + if (v == undefined || v.length == undefined || v.length < 2) { + return false; + } - if (typeof (v[0]) != "number" || typeof (v[1]) != "number") { - return false; - } - - return true; -} + if (typeof (v[0]) != "number" || typeof (v[1]) != "number") { + return false; + } + + return true; +}; /** -* vec2.copy +* RDGE.vec2.copy */ -vec2.copy = function(v) { - if( v.length == undefined ) { - return [ v, v ]; - } - - return [v[0], v[1]]; -} +RDGE.vec2.copy = function (v) { + if (v.length == undefined) { + return [v, v]; + } + + return [v[0], v[1]]; +}; /** -* vec2.inplace_copy +* RDGE.vec2.inplace_copy */ -vec2.inplace_copy = function(dst, src) { - dst[0] = src[0]; - dst[1] = src[1]; -} +RDGE.vec2.inplace_copy = function (dst, src) { + dst[0] = src[0]; + dst[1] = src[1]; +}; /** -* vec2.zero +* RDGE.vec2.zero */ -vec2.zero = function() { - return [0.0, 0.0]; -} +RDGE.vec2.zero = function () { + return [0.0, 0.0]; +}; /** -* vec2.up +* RDGE.vec2.up */ -vec2.up = function() { - return [0.0, 1.0]; -} +RDGE.vec2.up = function () { + return [0.0, 1.0]; +}; /** -* vec2.right +* RDGE.vec2.right */ -vec2.right = function() { - return [1.0, 0.0]; -} +RDGE.vec2.right = function () { + return [1.0, 0.0]; +}; /** -* vec2.add +* RDGE.vec2.add */ -vec2.add = function(a, b) { - return [a[0] + b[0], a[1] + b[1]]; -} +RDGE.vec2.add = function (a, b) { + return [a[0] + b[0], a[1] + b[1]]; +}; /** -* vec2.sub +* RDGE.vec2.sub */ -vec2.sub = function(a, b) { - return [a[0] - b[0], a[1] - b[1]]; -} +RDGE.vec2.sub = function (a, b) { + return [a[0] - b[0], a[1] - b[1]]; +}; /** -* vec2.mul +* RDGE.vec2.mul */ -vec2.mul = function(a, b) { - return [ a[0] * b[0], a[1] * b[1] ]; -} +RDGE.vec2.mul = function (a, b) { + return [a[0] * b[0], a[1] * b[1]]; +}; /** -* vec2.addMul +* RDGE.vec2.addMul */ -vec2.addMul = function(a, b, s) { - if (s.length != undefined && s.length >= 2) { - return [a[0] + b[0] * s[0], a[1] + b[1] * s[1]]; - } else { - return [a[0] + b[0] * s, a[1] + b[1] * s]; - } -} +RDGE.vec2.addMul = function (a, b, s) { + if (s.length != undefined && s.length >= 2) { + return [a[0] + b[0] * s[0], a[1] + b[1] * s[1]]; + } else { + return [a[0] + b[0] * s, a[1] + b[1] * s]; + } +}; /** -* vec2.scale +* RDGE.vec2.scale */ -vec2.scale = function(v, s) { - if (s.length != undefined && s.length >= 2) { - return [v[0] * s[0], v[1] * s[1]]; - } else { - return [v[0] * s, v[1] * s]; - } -} +RDGE.vec2.scale = function (v, s) { + if (s.length != undefined && s.length >= 2) { + return [v[0] * s[0], v[1] * s[1]]; + } else { + return [v[0] * s, v[1] * s]; + } +}; /** -* vec2.negate +* RDGE.vec2.negate */ -vec2.negate = function(v) { - return [ -v[0], -v[1] ]; -} +RDGE.vec2.negate = function (v) { + return [-v[0], -v[1]]; +}; /** -* vec2.normalize +* RDGE.vec2.normalize */ -vec2.normalize = function(v) { - var l = Math.sqrt(v[0] * v[0], v[1] * v[1] ); - if ( Math.abs(1.0 - l) > 0.0001 ) { - var ool = 1.0 / l; - return [ v[0] * ool, v[1] * ool ]; - } - return v; -} +RDGE.vec2.normalize = function (v) { + var l = Math.sqrt(v[0] * v[0], v[1] * v[1]); + if (Math.abs(1.0 - l) > 0.0001) { + var ool = 1.0 / l; + return [v[0] * ool, v[1] * ool]; + } + return v; +}; /** -* vec2.dot +* RDGE.vec2.dot */ -vec2.dot = function(a, b) { - return a[0] * b[0] + a[1] * b[1]; -} +RDGE.vec2.dot = function (a, b) { + return a[0] * b[0] + a[1] * b[1]; +}; /** -* vec2.perp +* RDGE.vec2.perp */ -vec2.perp = function(a) { - return [a[1], -a[0]]; -} +RDGE.vec2.perp = function (a) { + return [a[1], -a[0]]; +}; /** -* vec2.lengthSq +* RDGE.vec2.lengthSq */ -vec2.lengthSq = function( v ) { - return v[0] * v[0] + v[1] * v[1]; -} +RDGE.vec2.lengthSq = function (v) { + return v[0] * v[0] + v[1] * v[1]; +}; /** -* vec2.length +* RDGE.vec2.length */ -vec2.length = function( v ) { - return Math.sqrt( v[0] * v[0] + v[1] * v[1] ); -} +RDGE.vec2.length = function (v) { + return Math.sqrt(v[0] * v[0] + v[1] * v[1]); +}; /** -* vec2.min +* RDGE.vec2.min */ -vec2.min = function(a, b) { - return [Math.min(a[0], b[0]), Math.min(a[1], b[1])]; -} +RDGE.vec2.min = function (a, b) { + return [Math.min(a[0], b[0]), Math.min(a[1], b[1])]; +}; /** -* vec2.max +* RDGE.vec2.max */ -vec2.max = function(a, b) { - return [Math.max(a[0], b[0]), Math.max(a[1], b[1])]; -} +RDGE.vec2.max = function (a, b) { + return [Math.max(a[0], b[0]), Math.max(a[1], b[1])]; +}; /** -* vec2.clamp +* RDGE.vec2.clamp */ -vec2.clamp = function(v, vmin, vmax) { - return vec2.min(vmax, vec2.max(v, vmin)); -} \ No newline at end of file +RDGE.vec2.clamp = function (v, vmin, vmax) { + return RDGE.vec2.min(vmax, RDGE.vec2.max(v, vmin)); +}; \ No newline at end of file diff --git a/js/helper-classes/RDGE/src/core/script/math/vec3.js b/js/helper-classes/RDGE/src/core/script/math/vec3.js index 143fc352..aa76b958 100755 --- a/js/helper-classes/RDGE/src/core/script/math/vec3.js +++ b/js/helper-classes/RDGE/src/core/script/math/vec3.js @@ -6,346 +6,345 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot /** - * vec3 = {} + * RDGE.vec3 = {} * This library contains functions for operating on 3D vectors. Any JS array * containing at least 3 numeric components can represent a 3D vector. * - * For example, all of these are valid vec3 declarations: + * For example, all of these are valid RDGE.vec3 declarations: * var a = [0, 0, 1]; - * var b = vec3.zero(); - * var c = vec3.up(); + * var b = RDGE.vec3.zero(); + * var c = RDGE.vec3.up(); * */ -vec3 = {}; +var RDGE = RDGE || {}; +RDGE.vec3 = {}; /** -* vec3.string +* RDGE.vec3.string */ -vec3.string = function(v) { - return "{ " + v[0] + ", " + v[1] + ", " + v[2] + " }"; -} +RDGE.vec3.string = function (v) { + return "{ " + v[0] + ", " + v[1] + ", " + v[2] + " }"; +}; /** - * vec3.verify + * RDGE.vec3.verify * This function is provided for debugging purposes only. It is not recommended * to be used in performance critical areas of the code. */ -vec3.verify = function(v) { - if (v == undefined || v.length == undefined || v.length < 3) { - return false; - } - if (typeof (v[0]) != "number" || typeof (v[1]) != "number" || typeof (v[2]) != "number" ) { - return false; - } - return true; -} +RDGE.vec3.verify = function (v) { + if (v == undefined || v.length == undefined || v.length < 3) { + return false; + } + if (typeof (v[0]) != "number" || typeof (v[1]) != "number" || typeof (v[2]) != "number") { + return false; + } + return true; +}; /** -* vec3.inplace_copy +* RDGE.vec3.inplace_copy */ -vec3.inplace_copy = function(dst, src) { - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; -} +RDGE.vec3.inplace_copy = function (dst, src) { + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; +}; /** -* vec3.copy +* RDGE.vec3.copy */ -vec3.copy = function(v) { - if( v.length == undefined ) { - return [ v, v, v ]; - } - - return [v[0], v[1], v[2]]; -} +RDGE.vec3.copy = function (v) { + if (v.length == undefined) { + return [v, v, v]; + } + + return [v[0], v[1], v[2]]; +}; /** -* vec3.translation +* RDGE.vec3.translation * description : returns a vector containing the translation vector of m. */ -vec3.translation = function(m) { - return [ m[12], m[13], m[14] ]; -} +RDGE.vec3.translation = function (m) { + return [m[12], m[13], m[14]]; +}; /** -* vec3.basisX = function( m ) +* RDGE.vec3.basisX = function( m ) * description : returns a vector containing the translation vector of m. */ -vec3.basisX = function(m) { - return [ m[0], m[1], m[2] ]; -} +RDGE.vec3.basisX = function (m) { + return [m[0], m[1], m[2]]; +}; /** -* vec3.basisY = function( m ) +* RDGE.vec3.basisY = function( m ) * description : returns a vector containing the translation vector of m. */ -vec3.basisY = function(m) { - return [ m[4], m[5], m[6] ]; -} +RDGE.vec3.basisY = function (m) { + return [m[4], m[5], m[6]]; +}; /** -* vec3.basisZ = function( m ) +* RDGE.vec3.basisZ = function( m ) * description : returns a vector containing the translation vector of m. */ -vec3.basisZ = function(m) { - return [ m[8], m[9], m[10] ]; -} +RDGE.vec3.basisZ = function (m) { + return [m[8], m[9], m[10]]; +}; /** -* vec3.zero +* RDGE.vec3.zero */ -vec3.zero = function() { - return [0.0, 0.0, 0.0]; -} +RDGE.vec3.zero = function () { + return [0.0, 0.0, 0.0]; +}; /** -* vec3.up +* RDGE.vec3.up */ -vec3.up = function() { - return [ 0.0, 1.0, 0.0 ]; -} +RDGE.vec3.up = function () { + return [0.0, 1.0, 0.0]; +}; /** -* vec3.forward +* RDGE.vec3.forward */ -vec3.forward = function() { - return [ 0.0, 0.0, 1.0 ]; -} +RDGE.vec3.forward = function () { + return [0.0, 0.0, 1.0]; +}; /** -* vec3.right +* RDGE.vec3.right */ -vec3.right = function() { - return [ 1.0, 0.0, 0.0 ]; -} +RDGE.vec3.right = function () { + return [1.0, 0.0, 0.0]; +}; /** -* vec3.random +* RDGE.vec3.random */ -vec3.random = function(min, max) { - return [ min[0] + (max[0] - min[0]) * Math.random(), +RDGE.vec3.random = function (min, max) { + return [min[0] + (max[0] - min[0]) * Math.random(), min[1] + (max[1] - min[1]) * Math.random(), - min[2] + (max[2] - min[2]) * Math.random() ]; -} + min[2] + (max[2] - min[2]) * Math.random()]; +}; /** -* vec3.xy +* RDGE.vec3.xy */ -vec3.xy = function(v) { - return [v[0], v[1]]; -} +RDGE.vec3.xy = function (v) { + return [v[0], v[1]]; +}; /** -* vec3.xz +* RDGE.vec3.xz */ -vec3.xz = function(v) { - return [v[0], v[2]]; -} +RDGE.vec3.xz = function (v) { + return [v[0], v[2]]; +}; /** -* vec3.add +* RDGE.vec3.add */ -vec3.add = function(a, b) { - return [ a[0] + b[0], a[1] + b[1], a[2] + b[2] ]; -} +RDGE.vec3.add = function (a, b) { + return [a[0] + b[0], a[1] + b[1], a[2] + b[2]]; +}; -vec3.plusEqual = function(a, b) { +RDGE.vec3.plusEqual = function (a, b) { - a[0] += b[0]; - a[1] += b[1]; - a[2] += b[2]; -} + a[0] += b[0]; + a[1] += b[1]; + a[2] += b[2]; +}; /** -* vec3.sub +* RDGE.vec3.sub */ -vec3.sub = function(a, b) { - return [ a[0] - b[0], a[1] - b[1], a[2] - b[2] ]; -} +RDGE.vec3.sub = function (a, b) { + return [a[0] - b[0], a[1] - b[1], a[2] - b[2]]; +}; /** -* vec3.mul +* RDGE.vec3.mul */ -vec3.mul = function(a, b) { - return [ a[0] * b[0], a[1] * b[1], a[2] * b[2] ]; -} +RDGE.vec3.mul = function (a, b) { + return [a[0] * b[0], a[1] * b[1], a[2] * b[2]]; +}; /** -* vec3.addMul +* RDGE.vec3.addMul */ -vec3.addMul = function(a, b, s) { - if (s.length != undefined && s.length >= 3) { - return [ a[0] + b[0] * s[0], a[1] + b[1] * s[1], a[2] + b[2] * s[2] ]; - } else { - return [ a[0] + b[0] * s, a[1] + b[1] * s, a[2] + b[2] * s ]; - } -} +RDGE.vec3.addMul = function (a, b, s) { + if (s.length != undefined && s.length >= 3) { + return [a[0] + b[0] * s[0], a[1] + b[1] * s[1], a[2] + b[2] * s[2]]; + } else { + return [a[0] + b[0] * s, a[1] + b[1] * s, a[2] + b[2] * s]; + } +}; -vec3.plusEqualMul = function(a, b, s) { +RDGE.vec3.plusEqualMul = function (a, b, s) { - if(s.length !== undefined && s.length >= 3) - { - a[0] += b[0] * s[0]; - a[1] += b[1] * s[1]; - a[2] += b[2] * s[2]; - } - else - { - a[0] += b[0] * s; - a[1] += b[1] * s; - a[2] += b[2] * s; - } -} + if (s.length !== undefined && s.length >= 3) { + a[0] += b[0] * s[0]; + a[1] += b[1] * s[1]; + a[2] += b[2] * s[2]; + } + else { + a[0] += b[0] * s; + a[1] += b[1] * s; + a[2] += b[2] * s; + } +}; /** -* vec3.scale +* RDGE.vec3.scale */ -vec3.scale = function(v, s) { - if (s.length !== undefined && s.length >= 3) { - return [v[0] * s[0], v[1] * s[1], v[2] * s[2]]; - } else { - return [v[0] * s, v[1] * s, v[2] * s]; - } -} +RDGE.vec3.scale = function (v, s) { + if (s.length !== undefined && s.length >= 3) { + return [v[0] * s[0], v[1] * s[1], v[2] * s[2]]; + } else { + return [v[0] * s, v[1] * s, v[2] * s]; + } +}; -vec3.inplace_scale = function(v, s) { - if (s.length !== undefined && s.length >= 3) { - v[0] *= s[0], v[1] *= s[1], v[2] *= s[2]; - } else { - v[0] *= s, v[1] *= s, v[2] *= s; - } -} +RDGE.vec3.inplace_scale = function (v, s) { + if (s.length !== undefined && s.length >= 3) { + v[0] *= s[0], v[1] *= s[1], v[2] *= s[2]; + } else { + v[0] *= s, v[1] *= s, v[2] *= s; + } +}; /** -* vec3.negate +* RDGE.vec3.negate */ -vec3.negate = function(v) { - return [ -v[0], -v[1], -v[2] ]; -} +RDGE.vec3.negate = function (v) { + return [-v[0], -v[1], -v[2]]; +}; -vec3.inplace_negate = function(v) { - v[0] = -v[0], v[1] = -v[1], v[2] = -v[2]; -} +RDGE.vec3.inplace_negate = function (v) { + v[0] = -v[0], v[1] = -v[1], v[2] = -v[2]; +}; /** -* vec3.normalize +* RDGE.vec3.normalize */ -vec3.normalize = function(v) { - var l = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); - if ( Math.abs( 1.0 - l ) > 0.0001 ) { - var ool = 1.0 / l; - return [ v[0] * ool, v[1] * ool, v[2] * ool ]; - } - return v; -} +RDGE.vec3.normalize = function (v) { + var l = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); + if (Math.abs(1.0 - l) > 0.0001) { + var ool = 1.0 / l; + return [v[0] * ool, v[1] * ool, v[2] * ool]; + } + return v; +}; /** -* vec3.cross +* RDGE.vec3.cross */ -vec3.cross = function(a, b) { - return [ a[1] * b[2] - b[1] * a[2], - a[2] * b[0] - b[2] * a[0], - a[0] * b[1] - b[0] * a[1] ]; -} +RDGE.vec3.cross = function (a, b) { + return [a[1] * b[2] - b[1] * a[2], + a[2] * b[0] - b[2] * a[0], + a[0] * b[1] - b[0] * a[1]]; +}; /** -* vec3.dot +* RDGE.vec3.dot */ -vec3.dot = function(a, b) { - return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; -} +RDGE.vec3.dot = function (a, b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; +}; /** -* vec3.lengthSq +* RDGE.vec3.lengthSq */ -vec3.lengthSq = function( v ) { - return v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; -} +RDGE.vec3.lengthSq = function (v) { + return v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; +}; /** -* vec3.length +* RDGE.vec3.length */ -vec3.length = function( v ) { - return Math.sqrt( v[0] * v[0] + v[1] * v[1] + v[2] * v[2] ); -} +RDGE.vec3.length = function (v) { + return Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); +}; /** -* vec3.distanceSq +* RDGE.vec3.distanceSq */ -vec3.distanceSq = function(a, b) { - var diff = [a[0] - b[0], a[1] - b[1], a[2] - b[2]]; - return diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2]; -} +RDGE.vec3.distanceSq = function (a, b) { + var diff = [a[0] - b[0], a[1] - b[1], a[2] - b[2]]; + return diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2]; +}; /** -* vec3.distance +* RDGE.vec3.distance */ -vec3.distance = function( a, b ) { - var diff = [ a[0] - b[0], a[1] - b[1], a[2] - b[2] ]; - return Math.sqrt( diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2] ); -} +RDGE.vec3.distance = function (a, b) { + var diff = [a[0] - b[0], a[1] - b[1], a[2] - b[2]]; + return Math.sqrt(diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2]); +}; /** -* vec3.angle +* RDGE.vec3.angle */ -vec3.angle = function(a, b) { - // return angle in radians. - return Math.acos( vec3.dot( a, b ) ) / ( vec3.length(a) * vec3.length(b) ); -} +RDGE.vec3.angle = function (a, b) { + // return angle in radians. + return Math.acos(RDGE.vec3.dot(a, b)) / (RDGE.vec3.length(a) * RDGE.vec3.length(b)); +}; /** -* vec3.direction +* RDGE.vec3.direction */ -vec3.direction = function(from, to) { - return vec3.normalize( vec3.sub( to, from ) ); -} +RDGE.vec3.direction = function (from, to) { + return RDGE.vec3.normalize(RDGE.vec3.sub(to, from)); +}; /** -* vec3.abs +* RDGE.vec3.abs */ -vec3.abs = function(v) { - return [ Math.abs(v[0]), Math.abs(v[1]), Math.abs(v[2]) ]; -} +RDGE.vec3.abs = function (v) { + return [Math.abs(v[0]), Math.abs(v[1]), Math.abs(v[2])]; +}; /** -* vec3.min +* RDGE.vec3.min */ -vec3.min = function(a, b) { - return [ Math.min( a[0], b[0] ), Math.min( a[1], b[1] ), Math.min( a[2], b[2] ) ]; -} +RDGE.vec3.min = function (a, b) { + return [Math.min(a[0], b[0]), Math.min(a[1], b[1]), Math.min(a[2], b[2])]; +}; /** -* vec3.max +* RDGE.vec3.max */ -vec3.max = function(a, b) { - return [Math.max(a[0], b[0]), Math.max(a[1], b[1]), Math.max(a[2], b[2])]; -} +RDGE.vec3.max = function (a, b) { + return [Math.max(a[0], b[0]), Math.max(a[1], b[1]), Math.max(a[2], b[2])]; +}; /** -* vec3.clamp +* RDGE.vec3.clamp */ -vec3.clamp = function(v, vmin, vmax) { - return vec3.min(vmax, vec3.max(v, vmin)); -} +RDGE.vec3.clamp = function (v, vmin, vmax) { + return RDGE.vec3.min(vmax, RDGE.vec3.max(v, vmin)); +}; /** -* vec3.equal +* RDGE.vec3.equal */ -vec3.equal = function(a, b, t) { - if (!t) { - t = 0.001; - } - return ( vec3.distanceSq(a, b) < (t * t) ); -} +RDGE.vec3.equal = function (a, b, t) { + if (!t) { + t = 0.001; + } + return (RDGE.vec3.distanceSq(a, b) < (t * t)); +}; /** -* vec3.lerp +* RDGE.vec3.lerp */ -vec3.lerp = function(a, b, t) { - return [ +RDGE.vec3.lerp = function (a, b, t) { + return [ a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t ]; -} +}; diff --git a/js/helper-classes/RDGE/src/core/script/math/vec4.js b/js/helper-classes/RDGE/src/core/script/math/vec4.js index 3a0de375..a655d006 100755 --- a/js/helper-classes/RDGE/src/core/script/math/vec4.js +++ b/js/helper-classes/RDGE/src/core/script/math/vec4.js @@ -5,254 +5,255 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot */ /** -* vec4 = {} +* RDGE.vec4 = {} * This library contains functions for operating on 4D vectors. Any JS array * containing at least 4 numeric components can represent a 4D vector. * -* For example, all of these are valid vec4 declarations: +* For example, all of these are valid RDGE.vec4 declarations: * var a = [0, 0, 0, 1]; -* var b = vec3.identity(); -* var c = vec3.zero(); +* var b = RDGE.RDGE.vec4.identity(); +* var c = RDGE.RDGE.vec4.zero(); * */ -vec4 = {}; +var RDGE = RDGE || {}; +RDGE.vec4 = {}; /** -* vec4.string +* RDGE.vec4.string */ -vec4.string = function(v) { - return "{ " + v[0] + ", " + v[1] + ", " + v[2] + ", " + v[3] + " }"; -} +RDGE.vec4.string = function (v) { + return "{ " + v[0] + ", " + v[1] + ", " + v[2] + ", " + v[3] + " }"; +}; /** -* vec4.verify +* RDGE.vec4.verify */ -vec4.verify = function(v) { - if (v == undefined || v.length == undefined || v.length < 4) { - return false; - } +RDGE.vec4.verify = function (v) { + if (v == undefined || v.length == undefined || v.length < 4) { + return false; + } - if (typeof (v[0]) != "number" || typeof (v[1]) != "number" || typeof (v[2]) != "number" || typeof (v[3]) != "number") { - return false; - } - - return true; -} + if (typeof (v[0]) != "number" || typeof (v[1]) != "number" || typeof (v[2]) != "number" || typeof (v[3]) != "number") { + return false; + } + + return true; +}; /** -* vec4.inplace_copy +* RDGE.vec4.inplace_copy */ -vec4.inplace_copy = function(dst, src) { - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - dst[3] = src[3]; -} +RDGE.vec4.inplace_copy = function (dst, src) { + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = src[3]; +}; /** -* vec4.copy +* RDGE.vec4.copy */ -vec4.copy = function(v) { - if( v.length == undefined ) { - return [ v, v, v, v ]; - } - - if( v.length == 3 ) { - return [ v[0], v[1], v[2], 1.0 ]; - } - - return [ v[0], v[1], v[2], v[3] ]; -} +RDGE.vec4.copy = function (v) { + if (v.length == undefined) { + return [v, v, v, v]; + } + + if (v.length == 3) { + return [v[0], v[1], v[2], 1.0]; + } + + return [v[0], v[1], v[2], v[3]]; +}; /** -* vec4.zero +* RDGE.vec4.zero */ -vec4.zero = function() { - return [ 0.0, 0.0, 0.0, 0.0 ]; -} +RDGE.vec4.zero = function () { + return [0.0, 0.0, 0.0, 0.0]; +}; /** -* vec4.identity +* RDGE.vec4.identity */ -vec4.identity = function() { - return [ 0.0, 0.0, 0.0, 1.0 ]; -} +RDGE.vec4.identity = function () { + return [0.0, 0.0, 0.0, 1.0]; +};