aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D/math-utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/3D/math-utils.js')
-rwxr-xr-xjs/helper-classes/3D/math-utils.js287
1 files changed, 148 insertions, 139 deletions
diff --git a/js/helper-classes/3D/math-utils.js b/js/helper-classes/3D/math-utils.js
index 8a9be4b5..16d168b6 100755
--- a/js/helper-classes/3D/math-utils.js
+++ b/js/helper-classes/3D/math-utils.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
@@ -33,15 +34,15 @@ POSSIBILITY OF SUCH DAMAGE.
33// Math Utility functions 34// Math Utility functions
34/////////////////////////////////////////////////////////////////////// 35///////////////////////////////////////////////////////////////////////
35var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, 36var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils,
36 ViewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, 37 ViewUtils = require("js/helper-classes/3D/view-utils").ViewUtils,
37 Rectangle = require("js/helper-classes/3D/rectangle").Rectangle; 38 Rectangle = require("js/helper-classes/3D/rectangle").Rectangle;
38 39
39var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { 40var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
40 /////////////////////////////////////////////////////////////////////// 41 ///////////////////////////////////////////////////////////////////////
41 // Instance variables 42 // Instance variables
42 /////////////////////////////////////////////////////////////////////// 43 ///////////////////////////////////////////////////////////////////////
43// VecUtils: { value: null, writable: true }, 44// VecUtils: { value: null, writable: true },
44 45
45 EPSILON: { value: 1.e-5, writable: true }, 46 EPSILON: { value: 1.e-5, writable: true },
46 47
47 // these are used in containment tests 48 // these are used in containment tests
@@ -61,7 +62,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
61 // Vector Methods 62 // Vector Methods
62 /////////////////////////////////////////////////////////////////////// 63 ///////////////////////////////////////////////////////////////////////
63 64
64 vecIntersectPlaneForParam: { 65 vecIntersectPlaneForParam: {
65 value: function( pt0, vec, plane ) 66 value: function( pt0, vec, plane )
66 { 67 {
67 // declare the variable to return - undefined when there is no solution 68 // declare the variable to return - undefined when there is no solution
@@ -82,7 +83,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
82 } 83 }
83 }, 84 },
84 85
85 vecMag3: { 86 vecMag3: {
86 value: function( vec ) 87 value: function( vec )
87 { 88 {
88 if (vec.length < 3) return; 89 if (vec.length < 3) return;
@@ -92,7 +93,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
92 } 93 }
93 }, 94 },
94 95
95 vecMag: { 96 vecMag: {
96 value: function( dimen, vec ) 97 value: function( dimen, vec )
97 { 98 {
98 var sum = 0.0; 99 var sum = 0.0;
@@ -102,7 +103,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
102 } 103 }
103 }, 104 },
104 105
105 vecSubtract: { 106 vecSubtract: {
106 value: function( a, b ) 107 value: function( a, b )
107 { 108 {
108 var rtnVec; 109 var rtnVec;
@@ -119,7 +120,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
119 } 120 }
120 }, 121 },
121 122
122 vecAdd: { 123 vecAdd: {
123 value: function( a, b ) 124 value: function( a, b )
124 { 125 {
125 var rtnVec; 126 var rtnVec;
@@ -136,7 +137,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
136 } 137 }
137 }, 138 },
138 139
139 vecDist: { 140 vecDist: {
140 value: function( a, b ) 141 value: function( a, b )
141 { 142 {
142 var sum; 143 var sum;
@@ -176,7 +177,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
176 } 177 }
177 }, 178 },
178 179
179 getPointOnPlane: { 180 getPointOnPlane: {
180 value: function( plane ) 181 value: function( plane )
181 { 182 {
182 // abreviate the plane equation 183 // abreviate the plane equation
@@ -203,7 +204,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
203 } 204 }
204 }, 205 },
205 206
206 transformPlane: { 207 transformPlane: {
207 value: function( plane, mat ) 208 value: function( plane, mat )
208 { 209 {
209 // we will project a point down one of the coordinate axes to find a point on the plane 210 // we will project a point down one of the coordinate axes to find a point on the plane
@@ -213,7 +214,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
213 // find a point on the plane 214 // find a point on the plane
214 var ptOnPlane = this.getPointOnPlane(plane); 215 var ptOnPlane = this.getPointOnPlane(plane);
215 216
216 ptOnPlane[3] = 1.0; // 4 dimen so we can transform it 217 ptOnPlane[3] = 1.0; // 4 dimen so we can transform it
217 218
218 // transform the point 219 // transform the point
219 //ptOnPlane = mat.multiply( ptOnPlane ); 220 //ptOnPlane = mat.multiply( ptOnPlane );
@@ -225,12 +226,12 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
225 } 226 }
226 }, 227 },
227 228
228 transformHomogeneousPoint: { 229 transformHomogeneousPoint: {
229 value: function( srcPt, mat ) 230 value: function( srcPt, mat )
230 { 231 {
231 var pt = srcPt.slice(0); 232 var pt = srcPt.slice(0);
232 this.makeDimension4( pt ); 233 this.makeDimension4( pt );
233 var x = VecUtils.vecDot(4, pt, [mat[0], mat[4], mat[ 8], mat[12]] ), 234 var x = VecUtils.vecDot(4, pt, [mat[0], mat[4], mat[ 8], mat[12]] ),
234 y = VecUtils.vecDot(4, pt, [mat[1], mat[5], mat[ 9], mat[13]] ), 235 y = VecUtils.vecDot(4, pt, [mat[1], mat[5], mat[ 9], mat[13]] ),
235 z = VecUtils.vecDot(4, pt, [mat[2], mat[6], mat[10], mat[14]] ), 236 z = VecUtils.vecDot(4, pt, [mat[2], mat[6], mat[10], mat[14]] ),
236 w = VecUtils.vecDot(4, pt, [mat[3], mat[7], mat[11], mat[15]] ); 237 w = VecUtils.vecDot(4, pt, [mat[3], mat[7], mat[11], mat[15]] );
@@ -239,7 +240,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
239 } 240 }
240 }, 241 },
241 242
242 applyHomogeneousCoordinate: { 243 applyHomogeneousCoordinate: {
243 value: function( hPt ) 244 value: function( hPt )
244 { 245 {
245 var w = hPt[3]; 246 var w = hPt[3];
@@ -252,19 +253,19 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
252 } 253 }
253 }, 254 },
254 255
255 transformAndDivideHomogeneousPoint: { 256 transformAndDivideHomogeneousPoint: {
256 value: function( pt, mat ) 257 value: function( pt, mat )
257 { 258 {
258 return this.applyHomogeneousCoordinate( this.transformHomogeneousPoint(pt, mat) ); 259 return this.applyHomogeneousCoordinate( this.transformHomogeneousPoint(pt, mat) );
259 } 260 }
260 }, 261 },
261 262
262 transformPoint: { 263 transformPoint: {
263 value: function( srcPt, mat ) 264 value: function( srcPt, mat )
264 { 265 {
265 var pt = srcPt.slice(0); 266 var pt = srcPt.slice(0);
266 this.makeDimension3( pt ); 267 this.makeDimension3( pt );
267 var x = VecUtils.vecDot(3, pt, [mat[0], mat[4], mat[ 8]] ) + mat[12], 268 var x = VecUtils.vecDot(3, pt, [mat[0], mat[4], mat[ 8]] ) + mat[12],
268 y = VecUtils.vecDot(3, pt, [mat[1], mat[5], mat[ 9]] ) + mat[13], 269 y = VecUtils.vecDot(3, pt, [mat[1], mat[5], mat[ 9]] ) + mat[13],
269 z = VecUtils.vecDot(3, pt, [mat[2], mat[6], mat[10]] ) + mat[14]; 270 z = VecUtils.vecDot(3, pt, [mat[2], mat[6], mat[10]] ) + mat[14];
270 271
@@ -272,11 +273,11 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
272 } 273 }
273 }, 274 },
274 275
275 transformVector: { 276 transformVector: {
276 value: function( vec, mat ) <