diff options
Diffstat (limited to 'js/helper-classes/3D/math-utils.js')
-rwxr-xr-x | js/helper-classes/3D/math-utils.js | 54 |
1 files changed, 20 insertions, 34 deletions
diff --git a/js/helper-classes/3D/math-utils.js b/js/helper-classes/3D/math-utils.js index de63f880..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 | } |
@@ -737,7 +724,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { | |||
737 | yNrm += (zPts[i] - zPts[j]) * (xPts[i] + xPts[j]); | 724 | yNrm += (zPts[i] - zPts[j]) * (xPts[i] + xPts[j]); |
738 | zNrm += (xPts[i] - xPts[j]) * (yPts[i] + yPts[j]); | 725 | zNrm += (xPts[i] - xPts[j]) * (yPts[i] + yPts[j]); |
739 | } | 726 | } |
740 | var normal = Vector.create( [xNrm, yNrm, zNrm] ); | 727 | var normal = [xNrm, yNrm, zNrm]; |
741 | 728 | ||
742 | // the area of the polygon is the length of the normal | 729 | // the area of the polygon is the length of the normal |
743 | var area = VecUtils.vecMag(3, normal ); | 730 | var area = VecUtils.vecMag(3, normal ); |
@@ -760,7 +747,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { | |||
760 | 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]); |
761 | 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]); |
762 | } | 749 | } |
763 | var normal = Vector.create( [xNrm, yNrm, zNrm] ); | 750 | var normal = [xNrm, yNrm, zNrm]; |
764 | 751 | ||
765 | // the area of the polygon is the length of the normal | 752 | // the area of the polygon is the length of the normal |
766 | var area = VecUtils.vecMag(3, normal ); | 753 | var area = VecUtils.vecMag(3, normal ); |
@@ -900,7 +887,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { | |||
900 | // var v0 = pt0.slice(0); | 887 | // var v0 = pt0.slice(0); |
901 | // var v1 = pt1.slice(0); | 888 | // var v1 = pt1.slice(0); |
902 | // | 889 | // |
903 | // var origin = Vector.create([0, 0]); | 890 | // var origin = [0, 0]; |
904 | // | 891 | // |
905 | // if(origin) | 892 | // if(origin) |
906 | // { | 893 | // { |
@@ -964,8 +951,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { | |||
964 | if(!localPt) | 951 | if(!localPt) |
965 | { | 952 | { |
966 | return null; | 953 | return null; |
967 | return Vector.create( [1, 1]); | 954 | // return [1, 1]; |
968 | return [1, 1]; | ||
969 | } | 955 | } |
970 | localPt = this.transformPoint(localPt, matL); | 956 | localPt = this.transformPoint(localPt, matL); |
971 | 957 | ||
@@ -1056,12 +1042,12 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { | |||
1056 | perspectiveMatrix, | 1042 | perspectiveMatrix, |
1057 | inversePerspectiveMatrix, | 1043 | inversePerspectiveMatrix, |
1058 | transposedInversePerspectiveMatrix, | 1044 | transposedInversePerspectiveMatrix, |
1059 | perspective = Vector.create([0,0,0,0]), | 1045 | perspective = [0,0,0,0], |
1060 | translate = Vector.create([0,0,0]), | 1046 | translate = [0,0,0], |
1061 | scale = Vector.create([0,0,0]), | 1047 | scale = [0,0,0], |
1062 | skew = Vector.create([0,0,0]), | 1048 | skew = [0,0,0], |
1063 | rotate = Vector.create([0,0,0]), | 1049 | rotate = [0,0,0], |
1064 | rightHandSide = Vector.create([0,0,0,0]); | 1050 | rightHandSide = [0,0,0,0]; |
1065 | // Normalize the matrix. | 1051 | // Normalize the matrix. |
1066 | if (matrix[15] === 0) | 1052 | if (matrix[15] === 0) |
1067 | { | 1053 | { |
@@ -1139,9 +1125,9 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { | |||
1139 | } | 1125 | } |
1140 | 1126 | ||
1141 | // Compute X scale factor and normalize first row. | 1127 | // Compute X scale factor and normalize first row. |
1142 | var rowX = Vector.create([row[0], row[0+4], row[0+8]]); | 1128 | var rowX = [row[0], row[0+4], row[0+8]]; |
1143 | var rowY = Vector.create([row[1], row[1+4], row[1+8]]); | 1129 | var rowY = [row[1], row[1+4], row[1+8]]; |
1144 | var rowZ = Vector.create([row[2], row[2+4], row[2+8]]); | 1130 | var rowZ = [row[2], row[2+4], row[2+8]]; |
1145 | scale[0] = VecUtils.vecMag(3, rowX); | 1131 | scale[0] = VecUtils.vecMag(3, rowX); |
1146 | rowX = VecUtils.vecNormalize(3, rowX); | 1132 | rowX = VecUtils.vecNormalize(3, rowX); |
1147 | row[0] = rowX[0]; | 1133 | row[0] = rowX[0]; |