aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/utilities.js
diff options
context:
space:
mode:
authorKris Kowal2012-07-06 12:34:53 -0700
committerKris Kowal2012-07-06 15:01:48 -0700
commit3644cb6def4f681c99959e5729e78ea353441fad (patch)
treef8a886f4829e507cc4956db37cff2580cae6003d /js/helper-classes/RDGE/src/core/script/utilities.js
parent04343eda8c2f870b0da55cfdc8003c99fe1cc4de (diff)
downloadninja-3644cb6def4f681c99959e5729e78ea353441fad.tar.gz
Normalize to unix line terminators
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/utilities.js')
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/utilities.js530
1 files changed, 265 insertions, 265 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/utilities.js b/js/helper-classes/RDGE/src/core/script/utilities.js
index 3cf43e92..157fa5e2 100755
--- a/js/helper-classes/RDGE/src/core/script/utilities.js
+++ b/js/helper-classes/RDGE/src/core/script/utilities.js
@@ -1,265 +1,265 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility, Inc
3All Rights Reserved. 3All Rights Reserved.
4BSD License. 4BSD License.
5 5
6Redistribution and use in source and binary forms, with or without 6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 7modification, are permitted provided that the following conditions are met:
8 8
9 - Redistributions of source code must retain the above copyright notice, 9 - Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 10 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 11 - Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the 12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution. 13 documentation and/or other materials provided with the distribution.
14 - Neither the name of Motorola Mobility nor the names of its contributors 14 - Neither the name of Motorola Mobility nor the names of its contributors
15 may be used to endorse or promote products derived from this software 15 may be used to endorse or promote products derived from this software
16 without specific prior written permission. 16 without specific prior written permission.
17 17
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28POSSIBILITY OF SUCH DAMAGE. 28POSSIBILITY OF SUCH DAMAGE.
29</copyright> */ 29</copyright> */
30 30
31// RDGE namespaces 31// RDGE namespaces
32var RDGE = RDGE || {}; 32var RDGE = RDGE || {};
33 33
34 34
35/* 35/*
36// Methods not currently used in Ninja 36// Methods not currently used in Ninja
37RDGE.getRandColor = function () { 37RDGE.getRandColor = function () {
38 var r = Math.random(); 38 var r = Math.random();
39 var g = Math.random(); 39 var g = Math.random();
40 var b =Math.random(); 40 var b =Math.random();
41 41
42 return [r, g, b, 1.0]; 42 return [r, g, b, 1.0];
43}; 43};
44 44
45RDGE.unProject = function (winx, winy, winz, modelMatrix, projMatrix, viewport) { 45RDGE.unProject = function (winx, winy, winz, modelMatrix, projMatrix, viewport) {
46 var inVal = [0,0,0,0]; 46 var inVal = [0,0,0,0];
47 47
48 var finalMatrix = RDGE.mat4.mul(modelMatrix, projMatrix); 48 var finalMatrix = RDGE.mat4.mul(modelMatrix, projMatrix);
49 49
50 finalMatrix = RDGE.mat4.inverse(finalMatrix); 50 finalMatrix = RDGE.mat4.inverse(finalMatrix);
51 if(!finalMatrix) 51 if(!finalMatrix)
52 return null; 52 return null;
53 53
54 inVal[0]=winx; 54 inVal[0]=winx;
55 inVal[1]=winy; 55 inVal[1]=winy;
56 inVal[2]=winz; 56 inVal[2]=winz;
57 inVal[3]=1.0; 57 inVal[3]=1.0;
58 58
59 // Map x and y from window coordinates 59 // Map x and y from window coordinates
60 inVal[0] = (inVal[0] - viewport[0]) / viewport[2]; 60 inVal[0] = (inVal[0] - viewport[0]) / viewport[2];
61 inVal[1] = (inVal[1] - viewport[1]) / viewport[3]; 61 inVal[1] = (inVal[1] - viewport[1]) / viewport[3];
62 62
63 // Map to range -1 to 1 63 // Map to range -1 to 1
64 inVal[0] = inVal[0] * 2 - 1; 64 inVal[0] = inVal[0] * 2 - 1;
65 inVal[1] = inVal[1] * 2 - 1; 65 inVal[1] = inVal[1] * 2 - 1;
66 inVal[2] = inVal[2] * 2 - 1; 66 inVal[2] = inVal[2] * 2 - 1;
67 67
68 var v4Out = RDGE.mat4.transformPoint(finalMatrix, inVal); 68 var v4Out = RDGE.mat4.transformPoint(finalMatrix, inVal);
69 69
70 if (v4Out[3] <= 0.0001) 70 if (v4Out[3] <= 0.0001)
71 return null; 71 return null;
72 72
73 v4Out[0] /= v4Out[3]; 73 v4Out[0] /= v4Out[3];
74 v4Out[1] /= v4Out[3]; 74 v4Out[1] /= v4Out[3];
75 v4Out[2] /= v4Out[3]; 75 v4Out[2] /= v4Out[3];
76 76
77 return [ v4Out[0], v4Out[1], v4Out[2] ]; 77 return [ v4Out[0], v4Out[1], v4Out[2] ];
78}; 78};
79 79
80RDGE.AABB2LineSegment = function (box, startPoint, endPoint) { 80RDGE.AABB2LineSegment = function (box, startPoint, endPoint) {
81 c = RDGE.vec3.scale(RDGE.vec3.add(box.min, box.max), 0.5); 81 c = RDGE.vec3.scale(RDGE.vec3.add(box.min, box.max), 0.5);
82 e = RDGE.vec3.sub(box.max, box.min); 82 e = RDGE.vec3.sub(box.max, box.min);
83 d = RDGE.vec3.sub(endPoint, startPoint); 83 d = RDGE.vec3.sub(endPoint, startPoint);
84 m = RDGE.vec3.sub(startPoint, endPoint); 84 m = RDGE.vec3.sub(startPoint, endPoint);
85 m = RDGE.vec3.sub(m, box.min), 85 m = RDGE.vec3.sub(m, box.min),
86 m = RDGE.vec3.sub(m, box.max); 86 m = RDGE.vec3.sub(m, box.max);
87 87
88 var adx = Math.abs(d[0]); 88 var adx = Math.abs(d[0]);
89 if( Math.abs(m[0]) > e[0] + adx ) return false; 89 if( Math.abs(m[0]) > e[0] + adx ) return false;
90 90
91 var ady = Math.abs(d[1]); 91 var ady = Math.abs(d[1]);
92 if( Math.abs(m[1]) > e[1] + ady ) return false; 92 if( Math.abs(m[1]) > e[1] + ady ) return false;
93 93
94 var adz = Math.abs(d[2]); 94 var adz = Math.abs(d[2]);
95 if( Math.abs(m[2]) > e[2] + adz ) return false; 95 if( Math.abs(m[2]) > e[2] + adz ) return false;
96 96
97 adx += 1.192092896e-07; 97 adx += 1.192092896e-07;
98 ady += 1.192092896e-07; 98 ady += 1.192092896e-07;
99 adz += 1.192092896e-07; 99 adz += 1.192092896e-07;
100 100
101 if( Math.abs(m[1] * d[2] - m[2] * d[1]) > e[1] * adz + e[2] * ady ) return false; 101 if( Math.abs(m[1] * d[2] - m[2] * d[1]) > e[1] * adz + e[2] * ady ) return false;
102 if( Math.abs(m[2] * d[0] - m[0] * d[2]) > e[0] * adz + e[2] * adx ) return false; 102 if( Math.abs(m[2] * d[0] - m[0] * d[2]) > e[0] * adz + e[2] * adx ) return false;
103 if( Math.abs(m[0] * d[1] - m[1] * d[0]) > e[0] * ady + e[1] * adx ) return false; 103 if( Math.abs(m[0] * d[1] - m[1] * d[0]) > e[0] * ady + e[1] * adx ) return false;
104 104
105 return true; 105 return true;
106}; 106};
107 107
108RDGE.hitTest = function (mesh, near, far) { 108RDGE.hitTest = function (mesh, near, far) {
109 // holds distance to the nearest BV 109 // holds distance to the nearest BV
110 var dist = null; 110 var dist = null;
111 var BV = null; 111 var BV = null;
112 112
113 for (var index = 0; index < mesh.BVL.length; index++) { 113 for (var index = 0; index < mesh.BVL.length; index++) {
114 if (AABB2LineSegment(mesh.BVL[index], near, far)) { 114 if (AABB2LineSegment(mesh.BVL[index], near, far)) {
115 var center = RDGE.vec3.scale(RDGE.vec3.add(mesh.BVL[index].min, mesh.BVL[index].max), 0.5); 115 var center = RDGE.vec3.scale(RDGE.vec3.add(mesh.BVL[index].min, mesh.BVL[index].max), 0.5);
116 var newDist = RDGE.vec3.dot(RDGE.mat4.row(RDGE.globals.cam.world, 2), center); 116 var newDist = RDGE.vec3.dot(RDGE.mat4.row(RDGE.globals.cam.world, 2), center);
117 if (newDist < dist || dist == null) { 117 if (newDist < dist || dist == null) {
118 dist = newDist; 118 dist = newDist;
119 BV = mesh.BVL[index]; 119 BV = mesh.BVL[index];
120 } 120 }
121 } 121 }
122 } 122 }
123 return BV; 123 return BV;
124}; 124};
125 125