aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D/snap-manager.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/snap-manager.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/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];