aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D/snap-manager.js
diff options
context:
space:
mode:
authorValerio Virgillito2012-03-06 11:05:00 -0800
committerValerio Virgillito2012-03-06 11:05:00 -0800
commit4540b5b4ea2065c3e0d67b46bba8b6764801fbea (patch)
tree4e1561530b1b90ea497bac8e41d193fa605e98b4 /js/helper-classes/3D/snap-manager.js
parent4e35725e6c9044c37bef28b8c8d36f4b5c89bfd9 (diff)
parent84332ab81c1b445195f1d9be8bbeae0725c8e758 (diff)
downloadninja-4540b5b4ea2065c3e0d67b46bba8b6764801fbea.tar.gz
Merge branch 'refs/heads/master' into panels
Diffstat (limited to 'js/helper-classes/3D/snap-manager.js')
-rwxr-xr-xjs/helper-classes/3D/snap-manager.js46
1 files changed, 17 insertions, 29 deletions
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js
index 596ba56a..cf8a91db 100755
--- a/js/helper-classes/3D/snap-manager.js
+++ b/js/helper-classes/3D/snap-manager.js
@@ -211,9 +211,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
211 var stage = this.getStage(); 211 var stage = this.getStage();
212 var parentPt; 212 var parentPt;
213 if (quadPt) 213 if (quadPt)
214 parentPt = Vector.create([quadPt[0], quadPt[1], 0.0]); 214 parentPt = [quadPt[0], quadPt[1], 0.0];
215 else 215 else
216 parentPt = Vector.create([xScreen, yScreen, 0.0]); 216 parentPt = [xScreen, yScreen, 0.0];
217 var vec = viewUtils.parentToChildVec(parentPt, stage); 217 var vec = viewUtils.parentToChildVec(parentPt, stage);
218 if (vec) 218 if (vec)
219 { 219 {
@@ -321,7 +321,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
321 321
322 // get the point to the lower left of the plane point and 322 // get the point to the lower left of the plane point and
323 // see if it falls within the snap distance 323 // see if it falls within the snap distance
324 var origin = Vector.create( [-0.5*this.getStageWidth(), -0.5*this.getStageHeight()] ); 324 var origin = [-0.5*this.getStageWidth(), -0.5*this.getStageHeight()];
325 var planePt = hitRec.getLocalPoint(); 325 var planePt = hitRec.getLocalPoint();
326 var dToOrigin = MathUtils.vecSubtract(planePt, origin); 326 var dToOrigin = MathUtils.vecSubtract(planePt, origin);
327 var nx = Math.floor( dToOrigin[0]/dx), 327 var nx = Math.floor( dToOrigin[0]/dx),
@@ -338,11 +338,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
338 return false; 338 return false;
339 } 339 }
340 340
341 var pt00 = Vector.create( [ 341 var pt00 = [ origin[0] + nx*dx, origin[1] + ny*dy, 0.0 ];
342 origin[0] + nx*dx,
343 origin[1] + ny*dy,
344 0.0
345 ] );
346 var planeMat = hitRec.getPlaneMatrix(); 342 var planeMat = hitRec.getPlaneMatrix();
347 var scrPt2 = viewUtils.postViewToStageWorld( MathUtils.transformPoint(pt00,planeMat), stage ); 343 var scrPt2 = viewUtils.postViewToStageWorld( MathUtils.transformPoint(pt00,planeMat), stage );
348 scrPt2 = MathUtils.makeDimension3( scrPt2 ); 344 scrPt2 = MathUtils.makeDimension3( scrPt2 );
@@ -366,11 +362,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
366 return true; 362 return true;
367 363
368 // check the far corner point and 2 edges out from it 364 // check the far corner point and 2 edges out from it
369 var pt11 = Vector.create( [ 365 var pt11 = [ origin[0] + (nx+1)*dx, origin[1] + (ny+1)*dy, 0.0 ];
370 origin[0] + (nx+1)*dx,
371 origin[1] + (ny+1)*dy,
372 0.0
373 ] );
374 var scrPt4 = viewUtils.postViewToStageWorld( MathUtils.transformPoint(pt11,planeMat), stage ); 366 var scrPt4 = viewUtils.postViewToStageWorld( MathUtils.transformPoint(pt11,planeMat), stage );
375 scrPt4 = MathUtils.makeDimension3( scrPt4 ); 367 scrPt4 = MathUtils.makeDimension3( scrPt4 );
376 scrPt4 = vecUtils.vecAdd(3, viewUtils.viewToScreen( MathUtils.transformPoint(scrPt4, stageMat) ), offset ); 368 scrPt4 = vecUtils.vecAdd(3, viewUtils.viewToScreen( MathUtils.transformPoint(scrPt4, stageMat) ), offset );
@@ -420,11 +412,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
420 horizontalLineCount = 2; 412 horizontalLineCount = 2;
421 } 413 }
422 414
423 var edgePt = Vector.create( [ 415 var edgePt = [ gridOrigin[0] + nx*dx, gridOrigin[1] + ny*dy, 0.0 ];
424 gridOrigin[0] + nx*dx,
425 gridOrigin[1] + ny*dy,
426 0.0
427 ] );
428 var scrPt2 = viewUtils.postViewToStageWorld( MathUtils.transformPoint(edgePt,planeMat), stage ); 416 var scrPt2 = viewUtils.postViewToStageWorld( MathUtils.transformPoint(edgePt,planeMat), stage );
429 scrPt2 = MathUtils.makeDimension3( scrPt2 ); 417 scrPt2 = MathUtils.makeDimension3( scrPt2 );
430 scrPt2 = vecUtils.vecAdd(3, viewUtils.viewToScreen( MathUtils.transformPoint(scrPt2, stageMat) ), offset ); 418 scrPt2 = vecUtils.vecAdd(3, viewUtils.viewToScreen( MathUtils.transformPoint(scrPt2, stageMat) ), offset );
@@ -849,7 +837,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
849 MathUtils.makeDimension3( stageOffset ); 837 MathUtils.makeDimension3( stageOffset );
850 838
851 var x = vPt[0], y = hPt[1]; 839 var x = vPt[0], y = hPt[1];
852 var localPt = Vector.create( [x,y,0,1] ); 840 var localPt = [x,y,0,1];
853 var viewPt = MathUtils.transformPoint( localPt, planeToViewMat ); 841 var viewPt = MathUtils.transformPoint( localPt, planeToViewMat );
854 var scrPt = vecUtils.vecAdd(3, viewUtils.viewToScreen( viewPt ), stageOffset ); 842 var scrPt = vecUtils.vecAdd(3, viewUtils.viewToScreen( viewPt ), stageOffset );
855 843
@@ -1191,7 +1179,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1191 // Calculate the local point 1179 // Calculate the local point
1192 var planeMat; 1180 var planeMat;
1193 var mat = viewUtils.getMatrixFromElement( elt ); 1181 var mat = viewUtils.getMatrixFromElement( elt );
1194 var wp = Vector.create([0,0,1,0]); 1182 var wp = [0,0,1,0];
1195 wp = MathUtils.transformPlane( wp, mat ); 1183 wp = MathUtils.transformPlane( wp, mat );
1196 var wpMat = drawUtils.getPlaneToWorldMatrix(wp, MathUtils.getPointOnPlane(wp)); 1184 var wpMat = drawUtils.getPlaneToWorldMatrix(wp, MathUtils.getPointOnPlane(wp));
1197 //var wpMatInv = wpMat.inverse(); 1185 //var wpMatInv = wpMat.inverse();
@@ -1283,7 +1271,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1283 { 1271 {
1284 // convert to GL coordinates 1272 // convert to GL coordinates
1285 var glPt = this.globalScreenToWebGL( targetScrPt, elt ); 1273 var glPt = this.globalScreenToWebGL( targetScrPt, elt );
1286 var eyePt = Vector.create( [0, 0, world.getViewDistance()] ); 1274 var eyePt = [0, 0, world.getViewDistance()];
1287 var dir = vecUtils.vecSubtract(3, glPt, eyePt); 1275 var dir = vecUtils.vecSubtract(3, glPt, eyePt);
1288 1276
1289 // recursively go through the tree testing all objects 1277 // recursively go through the tree testing all objects
@@ -1534,7 +1522,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1534 viewUtils.pushViewportObj( elt ); 1522 viewUtils.pushViewportObj( elt );
1535 var cop = viewUtils.getCenterOfProjection(); 1523 var cop = viewUtils.getCenterOfProjection();
1536 viewUtils.popViewportObj(); 1524 viewUtils.popViewportObj();
1537 var s2v = Matrix.Translation(Vector.create([-cop[0], -cop[1], 0])); 1525 var s2v = Matrix.Translation([-cop[0], -cop[1], 0]);
1538 var vToNDC = Matrix.I(4); 1526 var vToNDC = Matrix.I(4);
1539 vToNDC[0] = 1.0/(0.5*world.getViewportWidth()); 1527 vToNDC[0] = 1.0/(0.5*world.getViewportWidth());
1540 vToNDC[5] = 1.0/(0.5*world.getViewportHeight()); 1528 vToNDC[5] = 1.0/(0.5*world.getViewportHeight());
@@ -1572,11 +1560,11 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1572 tmpPt2 = MathUtils.applyHomogeneousCoordinate( tmpPt2 ); 1560 tmpPt2 = MathUtils.applyHomogeneousCoordinate( tmpPt2 );
1573 1561
1574 // project the 2 object space points onto the original plane of the object 1562 // project the 2 object space points onto the original plane of the object
1575 var tmpPt3 = MathUtils.vecIntersectPlane( tmpPt1, vecUtils.vecSubtract(3, tmpPt2, tmpPt1), Vector.create([0,0,1,0]) ); 1563 var tmpPt3 = MathUtils.vecIntersectPlane( tmpPt1, vecUtils.vecSubtract(3, tmpPt2, tmpPt1), [0,0,1,0]);
1576 //console.log( "object space pt: " + tmpPt3 ); 1564 //console.log( "object space pt: " + tmpPt3 );
1577 1565
1578 // get the z value in NDC space of the projection plane 1566 // get the z value in NDC space of the projection plane
1579 var ndcPt = MathUtils.transformHomogeneousPoint( Vector.create( [0, 0, 0] ), glToNDC ); 1567 var ndcPt = MathUtils.transformHomogeneousPoint( [0, 0, 0], glToNDC );
1580 ndcPt = MathUtils.applyHomogeneousCoordinate( ndcPt ); 1568 ndcPt = MathUtils.applyHomogeneousCoordinate( ndcPt );
1581 var zNDC = ndcPt[2]; 1569 var zNDC = ndcPt[2];
1582 1570
@@ -1648,7 +1636,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1648 var drawingGrid = drawUtils.isDrawingGrid(); 1636 var drawingGrid = drawUtils.isDrawingGrid();
1649 1637
1650 // get the Z axis of the matrix 1638 // get the Z axis of the matrix
1651 var dir = Vector.create([mat[8], mat[9], mat[10]]); 1639 var dir = [mat[8], mat[9], mat[10]];
1652 dir = vecUtils.vecNormalize(3, dir, 1.0); 1640 dir = vecUtils.vecNormalize(3, dir, 1.0);
1653 var x = Math.abs(dir[0]), 1641 var x = Math.abs(dir[0]),
1654 y = Math.abs(dir[1]), 1642 y = Math.abs(dir[1]),
@@ -1659,7 +1647,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1659 //x = 0; y = 0; z = 1; // X/Y plane 1647 //x = 0; y = 0; z = 1; // X/Y plane
1660 1648
1661 var id; 1649 var id;
1662 var plane = Vector.create([0, 0, 0, 0]); 1650 var plane = [0, 0, 0, 0];
1663 var change = false; 1651 var change = false;
1664 if (x > y) { 1652 if (x > y) {
1665 if (x > z) { 1653 if (x > z) {
@@ -1829,7 +1817,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1829 MathUtils.makeDimension3( stageOffset ); 1817 MathUtils.makeDimension3( stageOffset );
1830 1818
1831 var x = vPt[0], y = hPt[1]; 1819 var x = vPt[0], y = hPt[1];
1832 var localPt = Vector.create( [x,y,0,1] ); 1820 var localPt = [x,y,0,1];
1833 var planeToViewMat = this.getPlaneToViewMat(); 1821 var planeToViewMat = this.getPlaneToViewMat();
1834 var viewPt = MathUtils.transformPoint( localPt, planeToViewMat ); 1822 var viewPt = MathUtils.transformPoint( localPt, planeToViewMat );
1835 var scrPt = vecUtils.vecAdd(3, viewUtils.viewToScreen( viewPt ), stageOffset ); 1823 var scrPt = vecUtils.vecAdd(3, viewUtils.viewToScreen( viewPt ), stageOffset );
@@ -1878,7 +1866,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1878 MathUtils.makeDimension3( stageOffset ); 1866 MathUtils.makeDimension3( stageOffset );
1879 1867
1880 var y = hPt[1], x = vPt[0]; 1868 var y = hPt[1], x = vPt[0];
1881 var localPt = Vector.create( [x,y,0,1] ); 1869 var localPt = [x,y,0,1];
1882 var planeToViewMat = this.getPlaneToViewMat(); 1870 var planeToViewMat = this.getPlaneToViewMat();
1883 var viewPt = MathUtils.transformPoint( localPt, planeToViewMat ); 1871 var viewPt = MathUtils.transformPoint( localPt, planeToViewMat );
1884 var scrPt = vecUtils.vecAdd(3, viewUtils.viewToScreen( viewPt ), stageOffset ); 1872 var scrPt = vecUtils.vecAdd(3, viewUtils.viewToScreen( viewPt ), stageOffset );
@@ -1933,7 +1921,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1933 MathUtils.makeDimension3( stageOffset ); 1921 MathUtils.makeDimension3( stageOffset );
1934 1922
1935 var y = hPt[1], x = vPt[0]; 1923 var y = hPt[1], x = vPt[0];
1936 var localPt = Vector.create( [x,y,0,1] ); 1924 var localPt = [x,y,0,1];
1937 var planeToViewMat = this.getPlaneToViewMat(); 1925 var planeToViewMat = this.getPlaneToViewMat();
1938 var viewPt = MathUtils.transformPoint( localPt, planeToViewMat );