aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/utilities.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/utilities.js')
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/utilities.js49
1 files changed, 25 insertions, 24 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..52662025 100755
--- a/js/helper-classes/RDGE/src/core/script/utilities.js
+++ b/js/helper-classes/RDGE/src/core/script/utilities.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -32,13 +33,13 @@ POSSIBILITY OF SUCH DAMAGE.
32var RDGE = RDGE || {}; 33var RDGE = RDGE || {};
33 34
34 35
35/* 36/*
36// Methods not currently used in Ninja 37// Methods not currently used in Ninja
37RDGE.getRandColor = function () { 38RDGE.getRandColor = function () {
38 var r = Math.random(); 39 var r = Math.random();
39 var g = Math.random(); 40 var g = Math.random();
40 var b =Math.random(); 41 var b =Math.random();
41 42
42 return [r, g, b, 1.0]; 43 return [r, g, b, 1.0];
43}; 44};
44 45
@@ -46,7 +47,7 @@ RDGE.unProject = function (winx, winy, winz, modelMatrix, projMatrix, viewport)
46 var inVal = [0,0,0,0]; 47 var inVal = [0,0,0,0];
47 48
48 var finalMatrix = RDGE.mat4.mul(modelMatrix, projMatrix); 49 var finalMatrix = RDGE.mat4.mul(modelMatrix, projMatrix);
49 50
50 finalMatrix = RDGE.mat4.inverse(finalMatrix); 51 finalMatrix = RDGE.mat4.inverse(finalMatrix);
51 if(!finalMatrix) 52 if(!finalMatrix)
52 return null; 53 return null;
@@ -56,24 +57,24 @@ RDGE.unProject = function (winx, winy, winz, modelMatrix, projMatrix, viewport)
56 inVal[2]=winz; 57 inVal[2]=winz;
57 inVal[3]=1.0; 58 inVal[3]=1.0;
58 59
59 // Map x and y from window coordinates 60 // Map x and y from window coordinates
60 inVal[0] = (inVal[0] - viewport[0]) / viewport[2]; 61 inVal[0] = (inVal[0] - viewport[0]) / viewport[2];
61 inVal[1] = (inVal[1] - viewport[1]) / viewport[3]; 62 inVal[1] = (inVal[1] - viewport[1]) / viewport[3];
62 63
63 // Map to range -1 to 1 64 // Map to range -1 to 1
64 inVal[0] = inVal[0] * 2 - 1; 65 inVal[0] = inVal[0] * 2 - 1;
65 inVal[1] = inVal[1] * 2 - 1; 66 inVal[1] = inVal[1] * 2 - 1;
66 inVal[2] = inVal[2] * 2 - 1; 67 inVal[2] = inVal[2] * 2 - 1;
67 68
68 var v4Out = RDGE.mat4.transformPoint(finalMatrix, inVal); 69 var v4Out = RDGE.mat4.transformPoint(finalMatrix, inVal);
69 70
70 if (v4Out[3] <= 0.0001) 71 if (v4Out[3] <= 0.0001)
71 return null; 72 return null;
72 73
73 v4Out[0] /= v4Out[3]; 74 v4Out[0] /= v4Out[3];
74 v4Out[1] /= v4Out[3]; 75 v4Out[1] /= v4Out[3];
75 v4Out[2] /= v4Out[3]; 76 v4Out[2] /= v4Out[3];
76 77
77 return [ v4Out[0], v4Out[1], v4Out[2] ]; 78 return [ v4Out[0], v4Out[1], v4Out[2] ];
78}; 79};
79 80
@@ -87,7 +88,7 @@ RDGE.AABB2LineSegment = function (box, startPoint, endPoint) {
87 88
88 var adx = Math.abs(d[0]); 89 var adx = Math.abs(d[0]);
89 if( Math.abs(m[0]) > e[0] + adx ) return false; 90 if( Math.abs(m[0]) > e[0] + adx ) return false;
90 91
91 var ady = Math.abs(d[1]); 92 var ady = Math.abs(d[1]);
92 if( Math.abs(m[1]) > e[1] + ady ) return false; 93 if( Math.abs(m[1]) > e[1] + ady ) return false;
93 94
@@ -109,7 +110,7 @@ RDGE.hitTest = function (mesh, near, far) {
109 // holds distance to the nearest BV 110 // holds distance to the nearest BV
110 var dist = null; 111 var dist = null;
111 var BV = null; 112 var BV = null;
112 113
113 for (var index = 0; index < mesh.BVL.length; index++) { 114 for (var index = 0; index < mesh.BVL.length; index++) {
114 if (AABB2LineSegment(mesh.BVL[index], near, far)) { 115 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); 116 var center = RDGE.vec3.scale(RDGE.vec3.add(mesh.BVL[index].min, mesh.BVL[index].max), 0.5);
@@ -147,7 +148,7 @@ RDGE.loadShader = function (ctx, shaderType, shaderStr) {
147 var shader = ctx.createShader(shaderType); 148 var shader = ctx.createShader(shaderType);
148 if (shader == null) { 149 if (shader == null) {
149 150
150 ctx.console.log("*** Error: unable to create shader '"+shaderType+"'"); 151 ctx.console.log("*** Error: unable to create shader '"+shaderType+"'");
151 152
152 return null; 153 return null;
153 } 154 }
@@ -236,7 +237,7 @@ RDGE.createShader = function (ctx, strVertShaderName, strFragShaderName, attribs
236 237
237 return null; 238 return null;
238 } 239 }
239 240
240 program.shaderID = "Shader" + RDGE.g_shaderCounter++; 241 program.shaderID = "Shader" + RDGE.g_shaderCounter++;
241 program.vname = strVertShaderName; 242 program.vname = strVertShaderName;
242 program.RDGEUniform = new RDGE.RDGEUniformInit(); 243 program.RDGEUniform = new RDGE.RDGEUniformInit();