aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D/math-utils.js
diff options
context:
space:
mode:
authorJonathan Duran2012-03-06 11:38:39 -0800
committerJonathan Duran2012-03-06 11:38:39 -0800
commit342fb451bd251358068a0dcb10e9dc218b79a176 (patch)
treeaa0195d581c3934fb6dc09981506b3c070002806 /js/helper-classes/3D/math-utils.js
parent2815adfd7c19b3dff89dc3e1bda9af8d30dca8d6 (diff)
downloadninja-342fb451bd251358068a0dcb10e9dc218b79a176.tar.gz
Squashed commit of the following:
commit 1cd89d4d06e3a8f2c221628b19cf26a2c69f5d3f Author: Jose Antonio Marquez <kgq387@motorola.com> Date: Tue Mar 6 11:24:25 2012 -0800 Fixing WebGL not available bug commit 84332ab81c1b445195f1d9be8bbeae0725c8e758 Author: Valerio Virgillito <valerio@motorola.com> Date: Tue Mar 6 10:58:25 2012 -0800 Squashed commit of preload-fix into Master - Requiring all the previously pre-loaded files - RDGE, Codemirror and gl-matrix are not included via a script tag. Signed-off-by: Valerio Virgillito <valerio@motorola.com> commit 13f52cf0c74f53a919fa864f86669e8155f82961 Merge: dced508 abc04f3 Author: Valerio Virgillito <valerio@motorola.com> Date: Fri Mar 2 15:46:11 2012 -0800 Merge pull request #93 from imix23ways/Timeline Timeline: Critical bug fixes commit dced508bb19a7bcd467ff1b86b5df5bbec4be794 Merge: 0aeb400 cc772ef Author: Valerio Virgillito <valerio@motorola.com> Date: Fri Mar 2 15:45:35 2012 -0800 Merge pull request #92 from mqg734/WebGLFixes Selection Tool Fixes for elements flying off into space when they overlap commit 0aeb400070762cf01d83cf9f9ee25a5595098b7f Merge: ff0a956 aabb48a Author: Valerio Virgillito <valerio@motorola.com> Date: Fri Mar 2 14:05:21 2012 -0800 Merge pull request #94 from ericguzman/PresetsPanel Presets Panel - Fix single-click activation, and transition cut-off bug. commit cc772ef3333ed419d269a2bda7aea5b0150a7bd9 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Fri Mar 2 11:34:58 2012 -0800 Fixing flying off into space bug for translate tool too. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit abc04f3d50311ed1c21067344bc7e448686f8c5c Author: Jonathan Duran <jduran@motorola.com> Date: Fri Mar 2 11:26:25 2012 -0800 Timeline Fix timing function Signed-off-by: Jonathan Duran <jduran@motorola.com> commit aabb48a1c8d34bc968f4c6b0ffee4e31c1d5d286 Author: Eric Guzman <ericg@motorola.com> Date: Fri Mar 2 11:22:44 2012 -0800 Presets Panel - Fix single-click activation, and transition cut-off bug. Use double-click as the activation event for transition presets. Also fixed the bug when applying a style preset before the transition preset, which disabled transitions after the first one. commit f3207f39ea9d8c1c34246217a23d3a689671903d Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Fri Mar 2 11:21:29 2012 -0800 Don't draw transform handles if the stage is the target element. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 5425be91e7125c22955b4459a62412ff574e49a8 Author: Jonathan Duran <jduran@motorola.com> Date: Fri Mar 2 11:11:48 2012 -0800 Timeline: Fix for animation iteration count Add default webkit css properties to allow animations with integer iteration counts. Signed-off-by: Jonathan Duran <jduran@motorola.com> commit 1760bac1da9218315ad1bacdcf3a157495a049e8 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Fri Mar 2 10:48:41 2012 -0800 Fix for jumping issue when moving items that have any 3d on them. We can't translate 3d moves into 2d space due to perspective, so we must update the matrix3d values instead of the top-left values if items have 3d. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 2c04935f0ccb1cb7c98371fc10b43155f2d956c4 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 22:20:06 2012 -0800 Fix for elements flying off into space when moving elements that overlap. This was happening because our hit record's element and the browser's element from point did not match. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 50058746779f714ed9b0287f49e56c9f0d35593e Merge: 500426d ff0a956 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 21:49:44 2012 -0800 Merge branch 'refs/heads/ninja-internal' into WebGLFixes commit 500426dea0ca95a6b45be8ea8d132cfdb4d2c940 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 10:11:39 2012 -0800 Fixed logic error when resizing with the top-left transform handles. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 7980d9bde2b43aa5a494ddf6f1db5c4959a57b91 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 10:04:15 2012 -0800 Re-fixing IKNinja-940 - Can't select objects when in side/top view. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit f04cc0146d8f7573628678613a99c270116768e4 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Wed Feb 29 16:45:40 2012 -0800 Last-used material (instead of FlatMaterial) is applied to shape when turning on use WebGL checkbox in the PI. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> Signed-off-by: Jonathan Duran <jduran@motorola.com>
Diffstat (limited to 'js/helper-classes/3D/math-utils.js')
-rwxr-xr-xjs/helper-classes/3D/math-utils.js87
1 files changed, 53 insertions, 34 deletions
diff --git a/js/helper-classes/3D/math-utils.js b/js/helper-classes/3D/math-utils.js
index 37044763..562a6e73 100755
--- a/js/helper-classes/3D/math-utils.js
+++ b/js/helper-classes/3D/math-utils.js
@@ -86,7 +86,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
86 if (b.length < n) n = b.length; 86 if (b.length < n) n = b.length;
87 if (n > 0) 87 if (n > 0)
88 { 88 {
89 rtnVec = Vector.create([0]); 89 rtnVec = [0];
90 for (var i=0; i<n; i++) 90 for (var i=0; i<n; i++)
91 rtnVec[i] = a[i] - b[i]; 91 rtnVec[i] = a[i] - b[i];
92 } 92 }
@@ -103,7 +103,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
103 if (b.length < n) n = b.length; 103 if (b.length < n) n = b.length;
104 if (n > 0) 104 if (n > 0)
105 { 105 {
106 rtnVec = Vector.create([0]); 106 rtnVec = [0];
107 for (var i=0; i<n; i++) 107 for (var i=0; i<n; i++)
108 rtnVec[i] = a[i] + b[i]; 108 rtnVec[i] = a[i] + b[i];
109 } 109 }
@@ -145,9 +145,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
145 { 145 {
146 var x0 = pt0[0], y0 = pt0[1], z0 = pt0[2]; 146 var x0 = pt0[0], y0 = pt0[1], z0 = pt0[2];
147 var dx = vec[0], dy = vec[1], dz = vec[2]; 147 var dx = vec[0], dy = vec[1], dz = vec[2];
148 rtnPt = Vector.create( [x0 + t*dx, 148 rtnPt = [x0 + t*dx, y0 + t*dy, z0 + t*dz] ;
149 y0 + t*dy,
150 z0 + t*dz] );
151 } 149 }
152 150
153 return rtnPt; 151 return rtnPt;
@@ -267,11 +265,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
267 { 265 {
268 var x0 = pt0[0], y0 = pt0[1], z0 = pt0[2], 266 var x0 = pt0[0], y0 = pt0[1], z0 = pt0[2],
269 x1 = pt1[0], y1 = pt1[1], z1 = pt1[2]; 267 x1 = pt1[0], y1 = pt1[1], z1 = pt1[2];
270 var pt = Vector.create( [ 268 var pt = [ x0 + t*(x1 - x0), y0 + t*(y1 - y0), z0 + t*(z1 - z0) ];
271 x0 + t*(x1 - x0),
272 y0 + t*(y1 - y0),
273 z0 + t*(z1 - z0)
274 ] );
275 269
276 return pt; 270 return pt;
277 } 271 }
@@ -359,8 +353,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
359 return null; //no intersection unless the the intersection point lies on both segments 353 return null; //no intersection unless the the intersection point lies on both segments
360 } 354 }
361 355
362 var intPt = Vector.create([seg0Start[0] + paramSeg0 * (seg0End[0] - seg0Start[0]), 356 var intPt = [seg0Start[0] + paramSeg0 * (seg0End[0] - seg0Start[0]), seg0Start[1] + paramSeg0 * (seg0End[1] - seg0Start[1])];
363 seg0Start[1] + paramSeg0 * (seg0End[1] - seg0Start[1])]);
364 357
365 return intPt; 358 return intPt;
366 } 359 }
@@ -383,10 +376,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
383 return this.vecDist(rayOrig, pt); 376 return this.vecDist(rayOrig, pt);
384 }//if( U < 0.0) { 377 }//if( U < 0.0) {
385 378
386 var intersection = Vector.create([ 379 var intersection = [ rayOrig[0] + U * (rayDir[0]), rayOrig[1] + U * (rayDir[1]), rayOrig[2] + U * (rayDir[2])];
387 rayOrig[0] + U * (rayDir[0]),
388 rayOrig[1] + U * (rayDir[1]),
389 rayOrig[2] + U * (rayDir[2])]);
390 380
391 return this.vecDist(intersection, pt); 381 return this.vecDist(intersection, pt);
392 } 382 }
@@ -424,10 +414,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
424 } 414 }
425 }//if( U < 0.0 || U > 1.0 ) { 415 }//if( U < 0.0 || U > 1.0 ) {
426 416
427 var intersection = Vector.create([ 417 var intersection = [ segP0[0] + U * (segP1[0] - segP0[0]), segP0[1] + U * (segP1[1] - segP0[1]), segP0[2] + U * (segP1[2] - segP0[2])];
428 segP0[0] + U * (segP1[0] - segP0[0]),
429 segP0[1] + U * (segP1[1] - segP0[1]),
430 segP0[2] + U * (segP1[2] - segP0[2])]);
431 418
432 return this.vecDist(intersection, pt); 419 return this.vecDist(intersection, pt);
433 } 420 }
@@ -538,6 +525,39 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
538 } 525 }
539 }, 526 },
540 527
528 isIdentityMatrix: {
529 value: function( mat )
530 {
531 if(!mat)
532 {
533 return false;
534 }
535 else
536 {
537 if(mat[0] !== 1) return false;
538 if(mat[1] !== 0) return false;
539 if(mat[2] !== 0) return false;
540 if(mat[3] !== 0) return false;
541
542 if(mat[4] !== 0) return false;
543 if(mat[5] !== 1) return false;
544 if(mat[6] !== 0) return false;
545 if(mat[7] !== 0) return false;
546
547 if(mat[8] !== 0) return false;
548 if(mat[9] !== 0) return false;
549 if(mat[10] !== 1) return false;
550 if(mat[11] !== 0) return false;
551
552 if(mat[12] !== 0) return false;
553 if(mat[13] !== 0) return false;
554 if(mat[14] !== 0) return false;
555 if(mat[15] !== 1) return false;
556 }
557 return true;
558 }
559 },
560
541 rectsOverlap: 561 rectsOverlap:
542 { 562 {
543 value: function( pt, width, height, elt ) 563 value: function( pt, width, height, elt )
@@ -704,7 +724,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
704 yNrm += (zPts[i] - zPts[j]) * (xPts[i] + xPts[j]); 724 yNrm += (zPts[i] - zPts[j]) * (xPts[i] + xPts[j]);
705 zNrm += (xPts[i] - xPts[j]) * (yPts[i] + yPts[j]); 725 zNrm += (xPts[i] - xPts[j]) * (yPts[i] + yPts[j]);
706 } 726 }
707 var normal = Vector.create( [xNrm, yNrm, zNrm] ); 727 var normal = [xNrm, yNrm, zNrm];
708 728
709 // the area of the polygon is the length of the normal 729 // the area of the polygon is the length of the normal
710 var area = VecUtils.vecMag(3, normal ); 730 var area = VecUtils.vecMag(3, normal );
@@ -727,7 +747,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
727 yNrm += (b[i][2] - b[j][2]) * (b[i][0] + b[j][0]); 747 yNrm += (b[i][2] - b[j][2]) * (b[i][0] + b[j][0]);
728 zNrm += (b[i][0] - b[j][0]) * (b[i][1] + b[j][1]); 748 zNrm += (b[i][0] - b[j][0]) * (b[i][1] + b[j][1]);
729 } 749 }
730 var normal = Vector.create( [xNrm, yNrm, zNrm] ); 750 var normal = [xNrm, yNrm, zNrm];
731 751
732 // the area of the polygon is the length of the normal 752 // the area of the polygon is the length of the normal
733 var area = VecUtils.vecMag(3, normal ); 753 var area = VecUtils.vecMag(3, normal );
@@ -867,7 +887,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
867// var v0 = pt0.slice(0); 887// var v0 = pt0.slice(0);
868// var v1 = pt1.slice(0); 888// var v1 = pt1.slice(0);
869// 889//
870// var origin = Vector.create([0, 0]); 890// var origin = [0, 0];
871// 891//
872// if(origin) 892// if(origin)
873// { 893// {
@@ -931,8 +951,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
931 if(!localPt) 951 if(!localPt)
932 { 952 {
933 return null; 953 return null;
934 return Vector.create( [1, 1]); 954// return [1, 1];
935 return [1, 1];
936 } 955 }
937 localPt = this.transformPoint(localPt, matL); 956 localPt = this.transformPoint(localPt, matL);
938 957
@@ -1023,12 +1042,12 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
1023 perspectiveMatrix, 1042 perspectiveMatrix,
1024 inversePerspectiveMatrix, 1043 inversePerspectiveMatrix,
1025 transposedInversePerspectiveMatrix, 1044 transposedInversePerspectiveMatrix,
1026 perspective = Vector.create([0,0,0,0]), 1045 perspective = [0,0,0,0],
1027 translate = Vector.create([0,0,0]), 1046 translate = [0,0,0],
1028 scale = Vector.create([0,0,0]), 1047 scale = [0,0,0],
1029 skew = Vector.create([0,0,0]), 1048 skew = [0,0,0],
1030 rotate = Vector.create([0,0,0]), 1049 rotate = [0,0,0],
1031 rightHandSide = Vector.create([0,0,0,0]); 1050 rightHandSide = [0,0,0,0];
1032 // Normalize the matrix. 1051 // Normalize the matrix.
1033 if (matrix[15] === 0) 1052 if (matrix[15] === 0)
1034 { 1053 {
@@ -1106,9 +1125,9 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
1106 } 1125 }
1107 1126
1108 // Compute X scale factor and normalize first row.