From 9eeb03e8bb86a4462609d3a18b528daa1516b91c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 7 May 2012 13:57:18 -0700 Subject: fixes for 2D and 3D translation. --- js/helper-classes/3D/snap-manager.js | 4 ++ js/helper-classes/3D/view-utils.js | 80 ++++++++++++++++++++++++++++-------- js/tools/SelectionTool.js | 2 +- js/tools/TranslateObject3DTool.js | 9 ++-- 4 files changed, 73 insertions(+), 22 deletions(-) (limited to 'js') diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index f4bfc12b..6766ac7f 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -1957,6 +1957,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { var localPt = hitRec.getLocalPoint(); var planeMat = hitRec.getPlaneMatrix(); var stageWorldPt; + + /* if(inGlobalMode) { stageWorldPt = MathUtils.transformPoint(localPt,planeMat); @@ -1965,6 +1967,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { { stageWorldPt = viewUtils.postViewToStageWorld( MathUtils.transformPoint(localPt,planeMat), elt ); } + */ + stageWorldPt = viewUtils.postViewToStageWorld( MathUtils.transformPoint(localPt,planeMat), elt ); /* // get a working plane parallel to the current working plane through the stage world point diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js index 40a19b90..919f7c50 100755 --- a/js/helper-classes/3D/view-utils.js +++ b/js/helper-classes/3D/view-utils.js @@ -124,35 +124,81 @@ exports.ViewUtils = Montage.create(Component, { } }, - getNormalToUnprojectedElementPlane: { - value: function( elt ) { - var mat = this.getMatrixFromElement(elt); + /* + * This method will return a normal to a plane containing the Z axis and either the + * x or y axis of the element. + */ + getNormalToUnprojectedElementPlane: + { + value: function( elt, axis, localMode ) + { + var objMat = this.getMatrixFromElement(elt); + var objMatInv = glmat4.inverse( objMat, [] ); - var xVec = [mat[0], mat[1], mat[2], mat[3]]; - var yVec = [mat[4], mat[5], mat[6], mat[7]]; + var xVec = [1,0,0]; + var yVec = [0,1,0]; + var zVec = [0,0,1]; var stage = this.application.ninja.currentDocument.documentRoot; var stageMat = this.getMatrixFromElement(stage); - var stagePlane = [stageMat[8], stageMat[9], stageMat[10], stageMat[11]]; + var mat = glmat4.multiply( stageMat, objMat, [] ); + + var viewDir; + if (localMode) + { + var matInv = glmat4.inverse( mat, [] ); + viewDir = MathUtils.transformVector( [0,0,1], matInv ); + } + else + { + var stageInv = glmat4.inverse( stageMat, [] ); + viewDir = MathUtils.transformVector( [0,0,1], stageInv ); + } + + /* if (elt === stage) { xVec = [1,0,0]; yVec = [0,1,0]; } + */ - var xDot = Math.abs(vecUtils.vecDot(3, xVec, stagePlane)); - var yDot = Math.abs(vecUtils.vecDot(3, yVec, stagePlane)); + var plane; + var xDot, yDot, zDot; + switch (axis) + { + case 0: + yDot = Math.abs(vecUtils.vecDot(3, yVec, viewDir)); + zDot = Math.abs(vecUtils.vecDot(3, zVec, viewDir)); + if(yDot > zDot) + plane = vecUtils.vecCross( 3, zVec, xVec ); + else + plane = vecUtils.vecCross( 3, yVec, xVec ); + break; + + case 1: + xDot = Math.abs(vecUtils.vecDot(3, yVec, viewDir)); + zDot = Math.abs(vecUtils.vecDot(3, zVec, viewDir)); + if(xDot > zDot) + plane = vecUtils.vecCross( 3, zVec, yVec ); + else + plane = vecUtils.vecCross( 3, xVec, yVec ); + break; + break; + + case 2: + xDot = Math.abs(vecUtils.vecDot(3, xVec, viewDir)); + yDot = Math.abs(vecUtils.vecDot(3, yVec, viewDir)); + + if(xDot > yDot) + plane = vecUtils.vecCross( 3, yVec, zVec ); + else + plane = vecUtils.vecCross( 3, xVec, zVec ); + break; + } - var plane; - if(xDot > yDot) - { - plane = xVec; - } - else - { - plane = yVec; - } + if (localMode) plane = MathUtils.transformVector( plane, objMat ); // The translation value is a point on the plane this.pushViewportObj( elt ); diff --git a/js/tools/SelectionTool.js b/js/tools/SelectionTool.js index 855c7b8c..07c26b8c 100755 --- a/js/tools/SelectionTool.js +++ b/js/tools/SelectionTool.js @@ -504,7 +504,7 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { delta = vecUtils.vecSubtract( 3, data.pt1, data.pt0 ); delta[0] = ~~delta[0]; delta[1] = ~~delta[1]; - delta[2] = 0; + //delta[2] = 0; var transMat = Matrix.Translation( delta ); this._moveElements(transMat); } diff --git a/js/tools/TranslateObject3DTool.js b/js/tools/TranslateObject3DTool.js index b4f55bd9..f8b32d23 100755 --- a/js/tools/TranslateObject3DTool.js +++ b/js/tools/TranslateObject3DTool.js @@ -54,10 +54,10 @@ exports.TranslateObject3DTool = Montage.create(Translate3DToolBase, { else { this._delta = null; - // special case for z-translation - if(this._handleMode === 2) + //if(this._handleMode === 2) { - this._dragPlane = viewUtils.getNormalToUnprojectedElementPlane(this._target); + this._dragPlane = viewUtils.getNormalToUnprojectedElementPlane(this._target, this._handleMode, this._inLocalMode); + //console.log( "dragPlane: " + this._dragPlane ); snapManager.setupDragPlaneFromPlane(this._dragPlane); do3DSnap = false; @@ -86,7 +86,8 @@ exports.TranslateObject3DTool = Montage.create(Translate3DToolBase, { var elt = this.application.ninja.stage.getElement(event, true); if(elt && (elt !== hitRec.getElement())) { - hitRec = snapManager.findHitRecordForElement(elt); + var otherSnap = snapManager.findHitRecordForElement(elt); + if (otherSnap) hitRec = otherSnap; } if(elt === this.application.ninja.currentSelectedContainer) { -- cgit v1.2.3 From 15c7bdad38a83d192bd5a1d55a54362c12c73d38 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 8 May 2012 12:10:07 -0700 Subject: Fixed a snapping issue on the mouse down in drawing tools. --- js/tools/drawing-tool-base.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'js') diff --git a/js/tools/drawing-tool-base.js b/js/tools/drawing-tool-base.js index 376b3a27..84641754 100755 --- a/js/tools/drawing-tool-base.js +++ b/js/tools/drawing-tool-base.js @@ -36,9 +36,8 @@ exports.DrawingToolBase = Montage.create(Montage, { * 2 - Y value converted to screen point */ getInitialSnapPoint: { - value: function(x, y, shapeCanvas) { - snapManager.clearDragPlane(); - + value: function(x, y, shapeCanvas) + { // update the snap settings snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); snapManager.enableElementSnap( snapManager.elementSnapEnabledAppLevel() ); -- cgit v1.2.3