aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D/snap-manager.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/3D/snap-manager.js')
-rwxr-xr-xjs/helper-classes/3D/snap-manager.js78
1 files changed, 48 insertions, 30 deletions
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js
index 372be345..cf8a91db 100755
--- a/js/helper-classes/3D/snap-manager.js
+++ b/js/helper-classes/3D/snap-manager.js
@@ -40,6 +40,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
40 40
41 // keep a reference to the most recent hitRecord. Used for drawing feedback on the stage 41 // keep a reference to the most recent hitRecord. Used for drawing feedback on the stage
42 _lastHit : { value: null, writable: true }, 42 _lastHit : { value: null, writable: true },
43 _hitRecords : { value: [], writable: true },
43 44
44 // keep a list of objects to avoid snapping to 45 // keep a list of objects to avoid snapping to
45 _avoidList : { value: [], writable: true }, 46 _avoidList : { value: [], writable: true },
@@ -210,9 +211,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
210 var stage = this.getStage(); 211 var stage = this.getStage();
211 var parentPt; 212 var parentPt;
212 if (quadPt) 213 if (quadPt)
213 parentPt = Vector.create([quadPt[0], quadPt[1], 0.0]); 214 parentPt = [quadPt[0], quadPt[1], 0.0];
214 else 215 else
215 parentPt = Vector.create([xScreen, yScreen, 0.0]); 216 parentPt = [xScreen, yScreen, 0.0];
216 var vec = viewUtils.parentToChildVec(parentPt, stage); 217 var vec = viewUtils.parentToChildVec(parentPt, stage);
217 if (vec) 218 if (vec)
218 { 219 {
@@ -274,6 +275,11 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
274 } //if (hitRecArray.length == 0) 275 } //if (hitRecArray.length == 0)
275 276
276 var rtnHit; 277 var rtnHit;
278
279 // Save reference to hit records to verify last hit record's element matches browser's elementFromPoint
280 this._hitRecords.length = 0;
281 this._hitRecords = hitRecArray;
282
277 if (hitRecArray.length > 0) 283 if (hitRecArray.length > 0)
278 { 284 {
279 this.sortHitRecords( hitRecArray ); 285 this.sortHitRecords( hitRecArray );
@@ -315,7 +321,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
315 321
316 // 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
317 // see if it falls within the snap distance 323 // see if it falls within the snap distance
318 var origin = Vector.create( [-0.5*this.getStageWidth(), -0.5*this.getStageHeight()] ); 324 var origin = [-0.5*this.getStageWidth(), -0.5*this.getStageHeight()];
319 var planePt = hitRec.getLocalPoint(); 325 var planePt = hitRec.getLocalPoint();
320 var dToOrigin = MathUtils.vecSubtract(planePt, origin); 326 var dToOrigin = MathUtils.vecSubtract(planePt, origin);
321 var nx = Math.floor( dToOrigin[0]/dx), 327 var nx = Math.floor( dToOrigin[0]/dx),
@@ -332,11 +338,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
332 return false; 338 return false;
333 } 339 }
334 340
335 var pt00 = Vector.create( [ 341 var pt00 = [ origin[0] + nx*dx, origin[1] + ny*dy, 0.0 ];
336 origin[0] + nx*dx,
337 origin[1] + ny*dy,
338 0.0
339 ] );
340 var planeMat = hitRec.getPlaneMatrix(); 342 var planeMat = hitRec.getPlaneMatrix();
341 var scrPt2 = viewUtils.postViewToStageWorld( MathUtils.transformPoint(pt00,planeMat), stage ); 343 var scrPt2 = viewUtils.postViewToStageWorld( MathUtils.transformPoint(pt00,planeMat), stage );
342 scrPt2 = MathUtils.makeDimension3( scrPt2 ); 344 scrPt2 = MathUtils.makeDimension3( scrPt2 );
@@ -360,11 +362,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
360 return true; 362 return true;
361 363
362 // check the far corner point and 2 edges out from it 364 // check the far corner point and 2 edges out from it
363 var pt11 = Vector.create( [ 365 var pt11 = [ origin[0] + (nx+1)*dx, origin[1] + (ny+1)*dy, 0.0 ];
364 origin[0] + (nx+1)*dx,
365 origin[1] + (ny+1)*dy,
366 0.0
367 ] );
368 var scrPt4 = viewUtils.postViewToStageWorld( MathUtils.transformPoint(pt11,planeMat), stage ); 366 var scrPt4 = viewUtils.postViewToStageWorld( MathUtils.transformPoint(pt11,planeMat), stage );
369 scrPt4 = MathUtils.makeDimension3( scrPt4 ); 367 scrPt4 = MathUtils.makeDimension3( scrPt4 );
370 scrPt4 = vecUtils.vecAdd(3, viewUtils.viewToScreen( MathUtils.transformPoint(scrPt4, stageMat) ), offset ); 368 scrPt4 = vecUtils.vecAdd(3, viewUtils.viewToScreen( MathUtils.transformPoint(scrPt4, stageMat) ), offset );
@@ -414,11 +412,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
414 horizontalLineCount = 2; 412 horizontalLineCount = 2;
415 } 413 }
416 414
417 var edgePt = Vector.create( [ 415 var edgePt = [ gridOrigin[0] + nx*dx, gridOrigin[1] + ny*dy, 0.0 ];
418 gridOrigin[0] + nx*dx,
419 gridOrigin[1] + ny*dy,
420 0.0
421 ] );
422 var scrPt2 = viewUtils.postViewToStageWorld( MathUtils.transformPoint(edgePt,planeMat), stage ); 416 var scrPt2 = viewUtils.postViewToStageWorld( MathUtils.transformPoint(edgePt,planeMat), stage );
423 scrPt2 = MathUtils.makeDimension3( scrPt2 ); 417 scrPt2 = MathUtils.makeDimension3( scrPt2 );
424 scrPt2 = vecUtils.vecAdd(3, viewUtils.viewToScreen( MathUtils.transformPoint(scrPt2, stageMat) ), offset ); 418 scrPt2 = vecUtils.vecAdd(3, viewUtils.viewToScreen( MathUtils.transformPoint(scrPt2, stageMat) ), offset );
@@ -843,7 +837,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
843 MathUtils.makeDimension3( stageOffset ); 837 MathUtils.makeDimension3( stageOffset );
844 838
845 var x = vPt[0], y = hPt[1]; 839 var x = vPt[0], y = hPt[1];
846 var localPt = Vector.create( [x,y,0,1] ); 840 var localPt = [x,y,0,1];
847 var viewPt = MathUtils.transformPoint( localPt, planeToViewMat ); 841 var viewPt = MathUtils.transformPoint( localPt, planeToViewMat );
848 var scrPt = vecUtils.vecAdd(3, viewUtils.viewToScreen( viewPt ), stageOffset ); 842 var scrPt = vecUtils.vecAdd(3, viewUtils.viewToScreen( viewPt ), stageOffset );
849 843
@@ -1185,7 +1179,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1185 // Calculate the local point 1179 // Calculate the local point
1186 var planeMat; 1180 var planeMat;
1187 var mat = viewUtils.getMatrixFromElement( elt ); 1181 var mat = viewUtils.getMatrixFromElement( elt );
1188 var wp = Vector.create([0,0,1,0]); 1182 var wp = [0,0,1,0];
1189 wp = MathUtils.transformPlane( wp, mat ); 1183 wp = MathUtils.transformPlane( wp, mat );
1190 var wpMat = drawUtils.getPlaneToWorldMatrix(wp, MathUtils.getPointOnPlane(wp)); 1184 var wpMat = drawUtils.getPlaneToWorldMatrix(wp, MathUtils.getPointOnPlane(wp));
1191 //var wpMatInv = wpMat.inverse(); 1185 //var wpMatInv = wpMat.inverse();
@@ -1277,7 +1271,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1277 { 1271 {
1278 // convert to GL coordinates 1272 // convert to GL coordinates
1279 var glPt = this.globalScreenToWebGL( targetScrPt, elt ); 1273 var glPt = this.globalScreenToWebGL( targetScrPt, elt );
1280 var eyePt = Vector.create( [0, 0, world.getViewDistance()] ); 1274 var eyePt = [0, 0, world.getViewDistance()];
1281 var dir = vecUtils.vecSubtract(3, glPt, eyePt); 1275 var dir = vecUtils.vecSubtract(3, glPt, eyePt);
1282 1276
1283 // recursively go through the tree testing all objects 1277 // recursively go through the tree testing all objects
@@ -1528,7 +1522,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1528 viewUtils.pushViewportObj( elt ); 1522 viewUtils.pushViewportObj( elt );
1529 var cop = viewUtils.getCenterOfProjection(); 1523 var cop = viewUtils.getCenterOfProjection();
1530 viewUtils.popViewportObj(); 1524 viewUtils.popViewportObj();
1531 var s2v = Matrix.Translation(Vector.create([-cop[0], -cop[1], 0])); 1525 var s2v = Matrix.Translation([-cop[0], -cop[1], 0]);
1532 var vToNDC = Matrix.I(4); 1526 var vToNDC = Matrix.I(4);
1533 vToNDC[0] = 1.0/(0.5*world.getViewportWidth()); 1527 vToNDC[0] = 1.0/(0.5*world.getViewportWidth());
1534 vToNDC[5] = 1.0/(0.5*world.getViewportHeight()); 1528 vToNDC[5] = 1.0/(0.5*world.getViewportHeight());
@@ -1566,11 +1560,11 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1566 tmpPt2 = MathUtils.applyHomogeneousCoordinate( tmpPt2 ); 1560 tmpPt2 = MathUtils.applyHomogeneousCoordinate( tmpPt2 );
1567 1561
1568 // 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
1569 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]);
1570 //console.log( "object space pt: " + tmpPt3 ); 1564 //console.log( "object space pt: " + tmpPt3 );
1571 1565
1572 // get the z value in NDC space of the projection plane 1566 // get the z value in NDC space of the projection plane
1573 var ndcPt = MathUtils.transformHomogeneousPoint( Vector.create( [0, 0, 0] ), glToNDC ); 1567 var ndcPt = MathUtils.transformHomogeneousPoint( [0, 0, 0], glToNDC );
1574 ndcPt = MathUtils.applyHomogeneousCoordinate( ndcPt ); 1568 ndcPt = MathUtils.applyHomogeneousCoordinate( ndcPt );
1575 var zNDC = ndcPt[2]; 1569 var zNDC = ndcPt[2];
1576 1570
@@ -1642,7 +1636,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1642 var drawingGrid = drawUtils.isDrawingGrid(); 1636 var drawingGrid = drawUtils.isDrawingGrid();
1643 1637
1644 // get the Z axis of the matrix 1638 // get the Z axis of the matrix
1645 var dir = Vector.create([mat[8], mat[9], mat[10]]); 1639 var dir = [mat[8], mat[9], mat[10]];
1646 dir = vecUtils.vecNormalize(3, dir, 1.0); 1640 dir = vecUtils.vecNormalize(3, dir, 1.0);
1647 var x = Math.abs(dir[0]), 1641 var x = Math.abs(dir[0]),
1648 y = Math.abs(dir[1]), 1642 y = Math.abs(dir[1]),
@@ -1653,7 +1647,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1653 //x = 0; y = 0; z = 1; // X/Y plane 1647 //x = 0; y = 0; z = 1; // X/Y plane
1654 1648
1655 var id; 1649 var id;
1656 var plane = Vector.create([0, 0, 0, 0]); 1650 var plane = [0, 0, 0, 0];
1657 var change = false; 1651 var change = false;
1658 if (x > y) { 1652 if (x > y) {
1659 if (x > z) { 1653 if (x > z) {
@@ -1823,7 +1817,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1823 MathUtils.makeDimension3( stageOffset ); 1817 MathUtils.makeDimension3( stageOffset );
1824 1818
1825 var x = vPt[0], y = hPt[1]; 1819 var x = vPt[0], y = hPt[1];
1826 var localPt = Vector.create( [x,y,0,1] ); 1820 var localPt = [x,y,0,1];
1827 var planeToViewMat = this.getPlaneToViewMat(); 1821 var planeToViewMat = this.getPlaneToViewMat();
1828 var viewPt = MathUtils.transformPoint( localPt, planeToViewMat ); 1822 var viewPt = MathUtils.transformPoint( localPt, planeToViewMat );
1829 var scrPt = vecUtils.vecAdd(3, viewUtils.viewToScreen( viewPt ), stageOffset ); 1823 var scrPt = vecUtils.vecAdd(3, viewUtils.viewToScreen( viewPt ), stageOffset );
@@ -1872,7 +1866,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1872 MathUtils.makeDimension3( stageOffset ); 1866 MathUtils.makeDimension3( stageOffset );
1873