diff options
author | Eric Guzman | 2012-03-12 15:33:04 -0700 |
---|---|---|
committer | Eric Guzman | 2012-03-12 15:33:04 -0700 |
commit | 7e3161153b87b891875ac65368a19aed12909fa3 (patch) | |
tree | b80f48d711a9729fc39dbbdff28c4f0620e7302d /js/helper-classes/3D/math-utils.js | |
parent | 7a28932ba8a7517bbaaabe1f5edf678416aafc9c (diff) | |
parent | 69d90467865a1384725b2301901be2180c5a841f (diff) | |
download | ninja-7e3161153b87b891875ac65368a19aed12909fa3.tar.gz |
Merge branch 'refs/heads/master' into CSSPanelUpdates
Conflicts:
js/panels/PanelContainer/PanelContainer.reel/PanelContainer.js
Diffstat (limited to 'js/helper-classes/3D/math-utils.js')
-rwxr-xr-x | js/helper-classes/3D/math-utils.js | 87 |
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. | 1127 | // Compute X scale factor and normalize first row. |
1109 | var rowX = Vector.create([row[0], row[0+4], row[0+8]]); | 1128 | var rowX = [row[0], row[0+4], row[0+8]]; |
1110 | var rowY = Vector.create([row[1], row[1+4], row[1+8]]); | 1129 | var rowY = [row[1], row[1+4], row[1+8]]; |
1111 | var rowZ = Vector.create([row[2], row[2+4], row[2+8]]); | 1130 | var rowZ = [row[2], row[2+4], row[2+8]]; |
1112 | scale[0] = VecUtils.vecMag(3, rowX); | 1131 | scale[0] = VecUtils.vecMag(3, rowX); |
1113 | rowX = VecUtils.vecNormalize(3, rowX); | 1132 | rowX = VecUtils.vecNormalize(3, rowX); |
1114 | row[0] = rowX[0]; | 1133 | row[0] = rowX[0]; |