aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/utilities.js
diff options
context:
space:
mode:
authorJonathan Duran2012-07-17 09:30:22 -0700
committerJonathan Duran2012-07-17 09:30:22 -0700
commit53051672a62208fbc96957719d8285fac6431ed6 (patch)
tree79d542ee811044e8af2ef84aa0d6662c6eb895c4 /js/helper-classes/RDGE/src/core/script/utilities.js
parent7e2c2dbd040ed79a3f0678f91bd4b6db9cf69231 (diff)
parent5146f224258929415adf4a8022e492454b4e2476 (diff)
downloadninja-53051672a62208fbc96957719d8285fac6431ed6.tar.gz
Merge branch 'refs/heads/NINJA-master' into TimelineUber
Conflicts: js/panels/Timeline/DragDrop.js js/panels/Timeline/Keyframe.reel/Keyframe.js js/panels/Timeline/Layer.reel/Layer.js js/panels/Timeline/PropertyTrack.reel/PropertyTrack.js js/panels/Timeline/Span.reel/Span.js js/panels/Timeline/Style.reel/Style.js js/panels/Timeline/TimelinePanel.reel/TimelinePanel.js js/panels/Timeline/TimelineTrack.reel/TimelineTrack.js js/panels/Timeline/Track.reel/Track.html js/panels/Timeline/Track.reel/Track.js js/panels/Timeline/Track.reel/css/Track.css js/panels/Timeline/TrackSpacer.reel/TrackSpacer.html js/panels/Timeline/TrackSpacer.reel/TrackSpacer.js js/panels/Timeline/TrackSpacer.reel/css/TrackSpacer.css js/panels/Timeline/Tween.reel/Tween.js Signed-off-by: Jonathan Duran <jduran@motorola.com>
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/utilities.js')
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/utilities.js531
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>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License. 4
5 5Redistribution and use in source and binary forms, with or without
6Redistribution and use in source and binary forms, with or without 6modification, are permitted provided that the following conditions are met:
7modification, 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.
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28POSSIBILITY OF SUCH DAMAGE. 28ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29</copyright> */ 29POSSIBILITY OF SUCH DAMAGE.
30 30</copyright> */
31// RDGE namespaces 31
32var RDGE = RDGE || {}; 32// RDGE namespaces
33 33var RDGE = RDGE || {};
34 34
35/* 35
36// Methods not currently used in Ninja 36/*
37RDGE.getRandColor = function () { 37// Methods not currently used in Ninja
38 var r = Math.random(); 38RDGE.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};
45RDGE.unProject = function (winx, winy, winz, modelMatrix, projMatrix, viewport) { 45
46 var inVal = [0,0,0,0]; 46RDGE.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};
80RDGE.AABB2LineSegment = function (box, startPoint, endPoint) { 80
81 c = RDGE.vec3.scale(RDGE.vec3.add(box.min, box.max), 0.5); 81RDGE.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};
108RDGE.hitTest = function (mesh, near, far) { 108
109 // holds distance to the nearest BV 109RDGE.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