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