From 8423cceac4f45f3d08d92ae969d17d488674717f Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 2 Apr 2012 16:28:09 -0700 Subject: Translate 3D fix for multi-selection Z translation --- js/tools/Translate3DToolBase.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index 18e2b610..bd2b3af1 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js @@ -147,8 +147,8 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, _translateGlobally: { value: function (transMat) { - //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); //console.log( "_translateGlobally, transMat: " + transMat ); + //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); var len = this._targets.length, i = 0, item, @@ -160,6 +160,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, if (this._mode === 1) { + if (len > 1) curMat = this._targets[0].mat.slice(); var curInv = glmat4.inverse( curMat, [] ); transMat = glmat4.multiply( nMat, curInv, [] ); } -- cgit v1.2.3 From b6fa38e2680ccce73f4a195f9adffa552f1d237c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 4 Apr 2012 12:37:43 -0700 Subject: turned off translation handles during a multi-object drag. --- js/tools/Translate3DToolBase.js | 175 ++++++++++++++++++++-------------------- js/tools/modifier-tool-base.js | 13 ++- 2 files changed, 100 insertions(+), 88 deletions(-) diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index bd2b3af1..32132c9a 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js @@ -73,13 +73,13 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, var transMat = Matrix.Translation( delta ); - //console.log( "Translate: " + delta ); if(this._inLocalMode && (this._targets.length === 1) ) { this._translateLocally(transMat); } else { + console.log( "modifyElements delta: " + delta ); this._translateGlobally(transMat); } } @@ -147,23 +147,23 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, _translateGlobally: { value: function (transMat) { - //console.log( "_translateGlobally, transMat: " + transMat ); - //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); + //console.log( "_translateGlobally, transMat: " + transMat ); + //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); var len = this._targets.length, i = 0, item, elt, curMat = viewUtils.getMatrixFromElement( this._target ), - matInv = glmat4.inverse(this._startMat, []), - nMat = glmat4.multiply(transMat, this._startMat, [] ), - qMat = glmat4.multiply(matInv, nMat, []); - - if (this._mode === 1) - { - if (len > 1) curMat = this._targets[0].mat.slice(); - var curInv = glmat4.inverse( curMat, [] ); - transMat = glmat4.multiply( nMat, curInv, [] ); - } + matInv = glmat4.inverse(this._startMat, []), + nMat = glmat4.multiply(transMat, this._startMat, [] ), + qMat = glmat4.multiply(matInv, nMat, []); + + if (this._mode === 1) + { + if (len > 1) curMat = this._targets[0].mat.slice(); + var curInv = glmat4.inverse( curMat, [] ); + transMat = glmat4.multiply( nMat, curInv, [] ); + } var shouldUpdateStartMat = true; @@ -185,27 +185,27 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, // glmat4.multiply(curMat, qMat, curMat); // // viewUtils.setMatrixForElement( elt, curMat, true); - curMat[12] += transMat[12]; - curMat[13] += transMat[13]; - curMat[14] += transMat[14]; - viewUtils.setMatrixForElement( elt, curMat, true); + curMat[12] += transMat[12]; + curMat[13] += transMat[13]; + curMat[14] += transMat[14]; + viewUtils.setMatrixForElement( elt, curMat, true); if(shouldUpdateStartMat) { - //console.log( "\t\tshouldUpdateStartMat" ); + //console.log( "\t\tshouldUpdateStartMat" ); this._targets[i].mat = curMat; } } } }, - _updateTargets: { + _updateTargets: { value: function(addToUndoStack) - { - console.log( "_updateTargets" ); - var newStyles = [], - previousStyles = [], - len = this.application.ninja.selectedElements.length; + { + //console.log( "_updateTargets" ); + var newStyles = [], + previousStyles = [], + len = this.application.ninja.selectedElements.length; this._targets = []; for(var i = 0; i < len; i++) { @@ -215,47 +215,47 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, var curMatInv = glmat4.inverse(curMat, []); this._targets.push({elt:elt, mat:curMat, matInv:curMatInv}); - if(addToUndoStack) - { - var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; + if(addToUndoStack) + { + var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; - var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)}; + var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)}; - previousStyles.push(previousStyleStr); - newStyles.push(newStyleStr); - } + previousStyles.push(previousStyleStr); + newStyles.push(newStyleStr); + } } if(addToUndoStack) { - ElementsMediator.set3DProperties(this.application.ninja.selectedElements, - newStyles, - "Change", - "translateTool", - previousStyles - ); - if(this._origin && this._delta) - { - if(this._handleMode !== null) - { - this._origin[this._handleMode] += this._delta; - } - else - { - this._origin[0] += this._delta[0]; - this._origin[1] += this._delta[1]; - } - } - this._delta = null; - } - // Save previous value for undo/redo - this._undoArray = []; - for(i = 0, len = this._targets.length; i < len; i++) - { - var elt = this._targets[i].elt; - var _mat = viewUtils.getMatrixFromElement(elt); - var _dist = viewUtils.getPerspectiveDistFromElement(elt); - this._undoArray.push({mat:_mat, dist:_dist}); - } + ElementsMediator.set3DProperties(this.application.ninja.selectedElements, + newStyles, + "Change", + "translateTool", + previousStyles + ); + if(this._origin && this._delta) + { + if(this._handleMode !== null) + { + this._origin[this._handleMode] += this._delta; + } + else + { + this._origin[0] += this._delta[0]; + this._origin[1] += this._delta[1]; + } + } + this._delta = null; + } + // Save previous value for undo/redo + this._undoArray = []; + for(i = 0, len = this._targets.length; i < len; i++) + { + var elt = this._targets[i].elt; + var _mat = viewUtils.getMatrixFromElement(elt); + var _dist = viewUtils.getPerspectiveDistFromElement(elt); + this._undoArray.push({mat:_mat, dist:_dist}); + } } }, @@ -305,27 +305,27 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, } else { - if(this._origin) - { - if(this._delta) - { - if(this._handleMode !== null) - { + if(this._origin) + { + if(this._delta) + { + if(this._handleMode !== null) + { // this._origin[this._handleMode] = this._delta; - } - else - { - this._origin[0] += this._delta[0]; - this._origin[1] += this._delta[1]; - } - } - } - else - { - this._origin = drawUtils._selectionCtr.slice(0); - this._origin[0] += this.application.ninja.stage.userContentLeft; - this._origin[1] += this.application.ninja.stage.userContentTop; - } + } + else + { + this._origin[0] += this._delta[0]; + this._origin[1] += this._delta[1]; + } + } + } + else + { + this._origin = drawUtils._selectionCtr.slice(0); + this._origin[0] += this.application.ninja.stage.userContentLeft; + this._origin[1] += this.application.ninja.stage.userContentTop; + } } } } @@ -364,10 +364,13 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, } // Draw tool handles - - this._updateHandlesOrigin(); + + this._updateHandlesOrigin(); var base = this._origin.slice(0); +// if (this.isDrawing) +// console.log( "handle origin: " + base ); + var len = this.application.ninja.selectedElements.length; var lMode = this._inLocalMode; if(len === 1) @@ -397,10 +400,10 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, this._handles[1]._strokeStyle = 'rgba(0, 255, 0, 0.2)'; break; } - if( delta && (len > 1) ) - { - base[this._handleMode] += ~~delta; - } + if( delta && (len > 1) ) + { + base[this._handleMode] += ~~delta; + } } this._handles[0].draw(base, item, lMode); this._handles[1].draw(base, item, lMode); diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js index 07b28747..e684f58a 100755 --- a/js/tools/modifier-tool-base.js +++ b/js/tools/modifier-tool-base.js @@ -852,8 +852,10 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { } } - this.DrawHandles(this._delta); - if(this._canSnap) + if (!this._isDrawing || (this.application.ninja.selectedElements.length == 1)) + this.DrawHandles(this._delta); + + if(this._canSnap) { snapManager.drawLastHit(); } @@ -892,6 +894,13 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { this._delta = null; } this.endDraw(event); + + this.application.ninja.stage.draw(); + if (this._targets && (this._targets.length > 1)) + { + this._origin = null; + this._updateHandlesOrigin(); + } this.DrawHandles(); } }, -- cgit v1.2.3 From 16f62ca09cc428043e8fef8bdeea11a989e62bc0 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 4 Apr 2012 16:29:16 -0700 Subject: Cap fix for vecUtils. --- js/tools/TranslateObject3DTool.js | 3 ++- js/tools/modifier-tool-base.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/js/tools/TranslateObject3DTool.js b/js/tools/TranslateObject3DTool.js index 7163f005..867bec7f 100755 --- a/js/tools/TranslateObject3DTool.js +++ b/js/tools/TranslateObject3DTool.js @@ -7,6 +7,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot var Translate3DToolBase = require("js/tools/Translate3DToolBase").Translate3DToolBase, drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, + vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, snapManager = require("js/helper-classes/3D/snap-manager").SnapManager; exports.TranslateObject3DTool = Object.create(Translate3DToolBase, { @@ -128,7 +129,7 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, { // only do quadrant snapping if the 4 corners of the element are in the drag plane - var sign = MathUtils.fpSign( VecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); + var sign = MathUtils.fpSign( vecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); this._shouldUseQuadPt = (sign == 0); var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js index e684f58a..b6589cba 100755 --- a/js/tools/modifier-tool-base.js +++ b/js/tools/modifier-tool-base.js @@ -177,7 +177,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { } // only do quadrant snapping if the 4 corners of the element are in the drag plane - var sign = MathUtils.fpSign( VecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); + var sign = MathUtils.fpSign( vecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); this._shouldUseQuadPt = (sign == 0) var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); -- cgit v1.2.3 From 96bfeee2e6b735b87e8482d6e2cf24d5224c6417 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 5 Apr 2012 17:03:14 -0700 Subject: translate3DObject tool fixes. --- js/helper-classes/3D/hit-record.js | 46 +++++++++++++++++++++++++++++++++++- js/helper-classes/3D/snap-manager.js | 1 + js/helper-classes/3D/view-utils.js | 45 ++++++++++++++++++----------------- js/tools/Translate3DToolBase.js | 7 +++--- js/tools/modifier-tool-base.js | 2 ++ 5 files changed, 75 insertions(+), 26 deletions(-) diff --git a/js/helper-classes/3D/hit-record.js b/js/helper-classes/3D/hit-record.js index 2c60adc6..96f87c24 100755 --- a/js/helper-classes/3D/hit-record.js +++ b/js/helper-classes/3D/hit-record.js @@ -284,6 +284,50 @@ var HitRecord = exports.HitRecord = Object.create(Object.prototype, return str; } - } + }, + + test: + { + value: function() + { + var elt = this.getElement(); + var stage = viewUtils.getStage(); + if (elt === stage) return; + + var localPt = this.calculateElementPreTransformScreenPoint(); + var stageWorldPt = this.calculateStageWorldPoint(); + var globalPt = this.getScreenPoint(); + var err = false; + + var test1 = viewUtils.localToGlobal( localPt, elt ); + var dist = vecUtils.vecDist(3, test1, globalPt); + if (MathUtils.fpSign(dist) != 0) + { + err = true; + console.log( "**** transform error 1 ***** " + dist + ", localPt: " + localPt ); + } + + var stageWorldToGlobal = viewUtils.getStageWorldToGlobalMatrix(); + var test2 = MathUtils.transformAndDivideHomogeneousPoint( stageWorldPt, stageWorldToGlobal ); + dist = vecUtils.vecDist(3, test2, globalPt); + if (MathUtils.fpSign(dist) != 0) + { + err = true; + console.log( "**** transform error 2 ***** " + dist + ", localPt: " + localPt ); + } + + var localToGlobal = viewUtils.getLocalToGlobalMatrix( elt ); + var globalToLocal = glmat4.inverse( localToGlobal, [] ); + var test3 = MathUtils.transformAndDivideHomogeneousPoint( globalPt, globalToLocal ); + dist = vecUtils.vecDist(3, test3, localPt); + if (MathUtils.fpSign( vecUtils.vecDist(3, test3, localPt)) != 0) + { + err = true; + console.log( "**** transform error 3 ***** " + dist + ", localPt: " + localPt ); + } + + if (!err) console.log( "no hitRecord error" ); + } + } }); diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index 9f6b9ed1..8eafa7e9 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -300,6 +300,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { this.deactivateDragPlane(); this.setLastHit( rtnHit ); + //rtnHit.test(); // DEBUG CODE. REMOVE THIS return rtnHit; } }, diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js index a72b7906..392de0be 100755 --- a/js/helper-classes/3D/view-utils.js +++ b/js/helper-classes/3D/view-utils.js @@ -112,6 +112,13 @@ exports.ViewUtils = Montage.create(Component, { var mat = this.getMatrixFromElement(elt); var plane = [mat[8], mat[9], mat[10], mat[11]]; + var stage = this.application.ninja.currentDocument.documentRoot; + if (elt === stage) + { + xVec = [1,0,0]; + yVec = [0,1,0]; + } + // The translation value is a point on the plane this.pushViewportObj( elt ); var ptOnPlane = this.getCenterOfProjection(); @@ -137,6 +144,12 @@ exports.ViewUtils = Montage.create(Component, { var stageMat = this.getMatrixFromElement(stage); var stagePlane = [stageMat[8], stageMat[9], stageMat[10], stageMat[11]]; + 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)); @@ -788,35 +801,23 @@ exports.ViewUtils = Montage.create(Component, { } }, - getStageWorldToGlobalMatrix: { - value: function() { + getStageWorldToGlobalMatrix: + { + value: function() + { var stage = this.application.ninja.currentDocument.documentRoot; this.pushViewportObj( stage ); - - // get the matrix to the parent - var mat = Matrix.I(4); - //var projMat = Matrix.I(4).multiply( this.getPerspectiveDistFromElement(stage) ); - var p = this.getPerspectiveDistFromElement(stage); - var projMat = glmat4.scale( Matrix.I(4), [p,p,p], [] ); - projMat[11] = -1; + + // put the point into screen space of the stage - requires + // a translation to the top/left only var cop = this.getCenterOfProjection(); var v2s = Matrix.Translation([cop[0], cop[1], 0]); - //mat = v2s.multiply( projMat ); - mat = glmat4.multiply( v2s, projMat, [] ); - - // offset to the parent - var offset = this.getElementOffset( stage ); - var offMat = Matrix.Translation([offset[0], offset[1], 0]); - //mat = offMat.multiply( mat ); - glmat4.multiply( offMat, mat, mat ); - this.popViewportObj(); - // var mat2 = this.getLocalToGlobalMatrix( stage.parentElement ); - var mat2 = this.getLocalToGlobalMatrix( this._rootElement ); - //var mat = mat2.multiply( mat ); - glmat4.multiply( mat2, mat, mat ); + // append the localToGlobal matrix of the stage. + var mat = this.getLocalToGlobalMatrix( stage ); + glmat4.multiply( mat, v2s ); return mat; } diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index 4799b840..2276178c 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js @@ -71,6 +71,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, this._delta = delta.slice(0); } + //console.log( "modifyElements delta: " + delta ); var transMat = Matrix.Translation( delta ); if(this._inLocalMode && (this._targets.length === 1) ) @@ -79,7 +80,6 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, } else { - console.log( "modifyElements delta: " + delta ); this._translateGlobally(transMat); } } @@ -148,7 +148,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, _translateGlobally: { value: function (transMat) { //console.log( "_translateGlobally, transMat: " + transMat ); - //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); + //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat[12] + ", " + transMat[13] + ", " + transMat[14] ); var len = this._targets.length, i = 0, item, @@ -167,7 +167,8 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, var shouldUpdateStartMat = true; - if(this._clickedOnStage) + //if (this._clickedOnStage) + if(this._clickedOnStage || ((this._handleMode === 2) && (this._targets.length > 1))) { shouldUpdateStartMat = false; } diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js index 2c9b484e..f9fd001c 100755 --- a/js/tools/modifier-tool-base.js +++ b/js/tools/modifier-tool-base.js @@ -405,6 +405,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { var index = this._snapIndex; var pt0; var useViewPoint = (this._inLocalMode && (this._targets.length === 1)); + //console.log( "useViewPoint: " + useViewPoint ); if (this._useQuadPt) { pt0 = this.GetQuadrantPoint(useViewPoint); @@ -427,6 +428,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { pt1 = MathUtils.transformPoint( pt1, this._startMat ); } + //console.log( "getMousePoints, useViewPoint: " + useViewPoint + ", " + pt0 + " => " + pt1 ); return {pt0:pt0, pt1:pt1}; } else -- cgit v1.2.3 From f522ce09d98bbb2812ed25bb942597d854d71a1c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 11 Apr 2012 16:01:33 -0700 Subject: Rotate3D tool changes --- js/helper-classes/3D/hit-record.js | 13 +++- js/tools/Rotate3DToolBase.js | 38 +++++++++- js/tools/RotateObject3DTool.js | 141 ++++++++++++++++++++++++++++++++++++- js/tools/modifier-tool-base.js | 1 + 4 files changed, 189 insertions(+), 4 deletions(-) diff --git a/js/helper-classes/3D/hit-record.js b/js/helper-classes/3D/hit-record.js index 96f87c24..6094dae1 100755 --- a/js/helper-classes/3D/hit-record.js +++ b/js/helper-classes/3D/hit-record.js @@ -320,13 +320,22 @@ var HitRecord = exports.HitRecord = Object.create(Object.prototype, var globalToLocal = glmat4.inverse( localToGlobal, [] ); var test3 = MathUtils.transformAndDivideHomogeneousPoint( globalPt, globalToLocal ); dist = vecUtils.vecDist(3, test3, localPt); - if (MathUtils.fpSign( vecUtils.vecDist(3, test3, localPt)) != 0) + if (MathUtils.fpSign(dist) != 0) { err = true; console.log( "**** transform error 3 ***** " + dist + ", localPt: " + localPt ); } - if (!err) console.log( "no hitRecord error" ); + var objToStageWorld = viewUtils.getObjToStageWorldMatrix( elt, true ); + var test4 = MathUtils.transformAndDivideHomogeneousPoint( localPt, objToStageWorld ); + dist = vecUtils.vecDist(3, test4, stageWorldPt); + if (MathUtils.fpSign(dist) != 0) + { + err = true; + console.log( "**** transform error 4 ***** " + dist + ", localPt: " + localPt ); + } + + //if (!err) console.log( "no hitRecord error" ); } } }); diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js index eb2cdba4..e0c5abcb 100755 --- a/js/tools/Rotate3DToolBase.js +++ b/js/tools/Rotate3DToolBase.js @@ -56,17 +56,23 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { // move the transform origin handle var dx = pt1.x - pt0.x; var dy = pt1.y - pt0.y; + var dz = pt1.z - pt0.z; + this._origin[0] += dx; this._origin[1] += dy; + this._origin[2] += dz; var len = this._targets.length; if(len === 1) { this._startOriginArray[0][0] += dx; this._startOriginArray[0][1] += dy; + this._startOriginArray[0][2] += dz; + console.log( "Rotate3DToolBase.modifyElements, _startOriginArray[0]: " + this._startOriginArray[0] ); } this.downPoint.x = pt1.x; this.downPoint.y = pt1.y; + this.downPoint.z = pt1.z; this.DrawHandles(); return; } @@ -159,8 +165,23 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { // pre-translate by the transformation center var tMat = Matrix.I(4); + // _startOriginArray is the location of the center of rotation + // in view space of the element. It is currently calculated during the drag + // using delta's in global screen space, hence wrong. + // We can put the transformCenter back in element view space here, however + // it would be (much) more efficient to cache the localToGlobal and + // globalToLocal matrices. var transformCtr = this._startOriginArray[i]; + var localToGlobalMat = viewUtils.getLocalToGlobalMatrix( elt ); + var globalToLocalMat = glmat4.inverse( localToGlobalMat, [] ); + var newTransformCtr = MathUtils.transformAndDivideHomogeneousPoint( this._origin, globalToLocalMat ); + viewUtils.pushViewportObj( elt ); + newTransformCtr = viewUtils.screenToView( newTransformCtr[0], newTransformCtr[1], newTransformCtr[2] ); + viewUtils.popViewportObj( elt ); + //console.log( "transformCtr: " + newTransformCtr ); + transformCtr = newTransformCtr; + tMat[12] = transformCtr[0]; tMat[13] = transformCtr[1]; tMat[14] = transformCtr[2]; @@ -267,6 +288,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { viewUtils.pushViewportObj( this.target ); var eltCtr = viewUtils.getCenterOfProjection(); + eltCtr[2] = 0; viewUtils.popViewportObj(); var ctrOffset = this.target.elementModel.props3D.m_transformCtr; @@ -277,6 +299,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } this._origin = viewUtils.localToGlobal(eltCtr, this.target); + console.log( "Rotate3DToolBase.captureSelectionDrawn _origin: " + this._origin ); this._updateTargets(); this._setTransformOrigin(false); } @@ -533,6 +556,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { */ _showFeedbackOnMouseMove : { value: function (event) { + this._canSnap = false; if(this._target && this._handles) { var len = this._handles.length; @@ -550,7 +574,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { this.application.ninja.stage.drawingCanvas.style.cursor = "move"; this._handleMode = i; this._activateOriginHandle = true; - return; + this._canSnap = true; + return; } else if(c === 2) { @@ -569,6 +594,16 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } }, + getMousePoints: { + value: function() + { + var pt0 = { x:this.downPoint.x, y:this.downPoint.y, z:this.downPoint.z }; + var pt1 = { x:this.upPoint.x, y:this.upPoint.y, z:this.upPoint.z }; + + return {pt0:pt0, pt1:pt1}; + } + }, + DrawHandles: { value: function (angle) { this.application.ninja.stage.clearDrawingCanvas(); @@ -594,6 +629,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { viewUtils.pushViewportObj( this.application.ninja.currentDocument.documentRoot ); } var base = this._origin; + //console.log( "Rotate3DToolBase.DrawHandles, base: " + base ); if( (this._handleMode !== null) && !this._activateOriginHandle ) { diff --git a/js/tools/RotateObject3DTool.js b/js/tools/RotateObject3DTool.js index 72af6eff..7b4ec083 100755 --- a/js/tools/RotateObject3DTool.js +++ b/js/tools/RotateObject3DTool.js @@ -4,7 +4,9 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -var Montage = require("montage/core/core").Montage; +var Montage = require("montage/core/core").Montage, + viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, + snapManager = require("js/helper-classes/3D/snap-manager").SnapManager; var Rotate3DToolBase = require("js/tools/Rotate3DToolBase").Rotate3DToolBase; var toolHandleModule = require("js/stage/tool-handle"); @@ -54,6 +56,143 @@ exports.RotateObject3DTool = Montage.create(Rotate3DToolBase, { } }, + initializeSnapping : { + value : function(event) + { + console.log( "initializeSnapping" ); + + this._mouseDownHitRec = null; + this._mouseUpHitRec = null; + + snapManager.clearAvoidList(); + snapManager.clearDragPlane(); + + // the translate tool does snap align to the bounds of the object only. + // turn off snap align to the cursor. This needs to be re-enabled in the mouse up method + snapManager.enableSnapAlign( false ); + + // snap to element and snap to grid are conditionally enabled based + // on the snap results of the mouse down. enable everything for the first snap + this._snapToElements = snapManager.elementSnapEnabledAppLevel(); + this._snapToGrid = snapManager.gridSnapEnabledAppLevel(); + + this._dragPlane = null; + this._clickedOnStage = false; + var do3DSnap = true; + + if(this._handleMode === null) + { + snapManager.enableElementSnap ( true ); + snapManager.enableGridSnap ( true ); + } +// else +// { +// this._delta = null; + // special case for z-translation +// if(this._handleMode === 0) +// { +// this._dragPlane = viewUtils.getNormalToUnprojectedElementPlane(this._target); +// snapManager.setupDragPlaneFromPlane(this._dragPlane); +// do3DSnap = false; + +// snapManager.enableElementSnap ( false ); +// snapManager.enableGridSnap ( false ); +// } +// } + + if (this._targets) + { + var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, + new WebKitPoint(event.pageX, event.pageY)); + + // do the snap before setting up the avoid list to allow + // a snap on the mouse down + var hitRec = snapManager.snap(point.x, point.y, do3DSnap); + +// if(this._handleMode === 2) +// { +// // translate z doesn't snap to element so hitRec's element will always be different +// // from what the browser says we clicked on. So, skip this check. +// } +// else +// { +// // Check that hitRec's element matches element that browser says we clicked on +// // TODO - This is still not working when using a handle that is on top of an +// // element that is not currently selected +// var elt = this.application.ninja.stage.GetSelectableElement(event); +// if(elt && (elt !== hitRec.getElement())) +// { +// hitRec = snapManager.findHitRecordForElement(elt); +// } +// if(elt === this.application.ninja.currentSelectedContainer) +// { +// this._clickedOnStage = true; +// } +// } + + // we don't want to snap to selected objects during the drag +// var len = this._targets.length; +// for(var i=0; i 0) || (back > 0)) ? dark : light; context.beginPath(); if ((right > 0) || (back > 0)) { context.beginPath(); - p = this.viewUtils.localToGlobal2( [x1, y0, z0], ssMat ); context.moveTo( p[0], p[1] ); + p = this.viewUtils.localToGlobal2( [x1, y0, z0], ssMat ); context.moveTo( p[0], p[1] ); p = this.viewUtils.localToGlobal2( [x1, y1, z0], ssMat ); context.lineTo( p[0], p[1] ); context.closePath(); context.stroke(); } diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js index 392de0be..f803a274 100755 --- a/js/helper-classes/3D/view-utils.js +++ b/js/helper-classes/3D/view-utils.js @@ -112,13 +112,6 @@ exports.ViewUtils = Montage.create(Component, { var mat = this.getMatrixFromElement(elt); var plane = [mat[8], mat[9], mat[10], mat[11]]; - var stage = this.application.ninja.currentDocument.documentRoot; - if (elt === stage) - { - xVec = [1,0,0]; - yVec = [0,1,0]; - } - // The translation value is a point on the plane this.pushViewportObj( elt ); var ptOnPlane = this.getCenterOfProjection(); diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js index e0c5abcb..402023ff 100755 --- a/js/tools/Rotate3DToolBase.js +++ b/js/tools/Rotate3DToolBase.js @@ -14,7 +14,8 @@ var Montage = require("montage/core/core").Montage, viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, - ElementsMediator = require("js/mediators/element-mediator").ElementMediator; + ElementsMediator = require("js/mediators/element-mediator").ElementMediator, + Rectangle = require("js/helper-classes/3D/rectangle").Rectangle; exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { _canSnap: { value: false }, @@ -61,14 +62,22 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { this._origin[0] += dx; this._origin[1] += dy; this._origin[2] += dz; + console.log( "modifyElements, _origin: " + this._origin ); var len = this._targets.length; if(len === 1) { - this._startOriginArray[0][0] += dx; - this._startOriginArray[0][1] += dy; - this._startOriginArray[0][2] += dz; - console.log( "Rotate3DToolBase.modifyElements, _startOriginArray[0]: " + this._startOriginArray[0] ); +// this._startOriginArray[0][0] += dx; +// this._startOriginArray[0][1] += dy; +// this._startOriginArray[0][2] += dz; + var g2lMat = this._targets[0].g2l; + var localOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2lMat ); + var elt = this._targets[0].elt; + viewUtils.pushViewportObj( elt ); + var viewOrigin = viewUtils.screenToView( localOrigin[0], localOrigin[1], localOrigin[2] ); + viewUtils.popViewportObj(); + this._startOriginArray[0] = viewOrigin; + //console.log( "Rotate3DToolBase.modifyElements, _startOriginArray[0]: " + this._startOriginArray[0] ); } this.downPoint.x = pt1.x; this.downPoint.y = pt1.y; @@ -139,8 +148,10 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } } + if(this._inLocalMode && (this._targets.length === 1) ) { + console.log( "modifyElements: rotateLocally " ); this._rotateLocally(mat); } else @@ -166,22 +177,9 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { var tMat = Matrix.I(4); // _startOriginArray is the location of the center of rotation - // in view space of the element. It is currently calculated during the drag - // using delta's in global screen space, hence wrong. - // We can put the transformCenter back in element view space here, however - // it would be (much) more efficient to cache the localToGlobal and - // globalToLocal matrices. + // in view space of the element. var transformCtr = this._startOriginArray[i]; - var localToGlobalMat = viewUtils.getLocalToGlobalMatrix( elt ); - var globalToLocalMat = glmat4.inverse( localToGlobalMat, [] ); - var newTransformCtr = MathUtils.transformAndDivideHomogeneousPoint( this._origin, globalToLocalMat ); - viewUtils.pushViewportObj( elt ); - newTransformCtr = viewUtils.screenToView( newTransformCtr[0], newTransformCtr[1], newTransformCtr[2] ); - viewUtils.popViewportObj( elt ); - //console.log( "transformCtr: " + newTransformCtr ); - transformCtr = newTransformCtr; - tMat[12] = transformCtr[0]; tMat[13] = transformCtr[1]; tMat[14] = transformCtr[2]; @@ -219,6 +217,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { var transformCtr = this._startOriginArray[i].slice(0); transformCtr = MathUtils.transformPoint(transformCtr, curMat); + console.log( "modifyElements: rotateGlobally, ctr: " + transformCtr ); + tMat[12] = transformCtr[0]; tMat[13] = transformCtr[1]; tMat[14] = transformCtr[2]; @@ -306,11 +306,12 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { else { this.target = this.application.ninja.currentDocument.documentRoot; - this._origin = drawUtils._selectionCtr.slice(0); - this._origin[0] += this.application.ninja.stage.userContentLeft; - this._origin[1] += this.application.ninja.stage.userContentTop; + //this._origin = drawUtils._selectionCtr.slice(0); + //this._origin[0] += this.application.ninja.stage.userContentLeft; + //this._origin[1] += this.application.ninja.stage.userContentTop; this._updateTargets(); - this._setTransformOrigin(true); + this._origin = this.calculateMultiSelOrigin(); + this._setTransformOrigin(true); } } else @@ -326,8 +327,15 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } }, + /* + _updateHandlesOrigin: { + value: function () { } + }, + */ + _updateTargets: { value: function(addToUndoStack) { + console.log( "Rotate3DToolBase._updateTargets" ); var newStyles = [], previousStyles = [], len = this.application.ninja.selectedElements.length; @@ -345,10 +353,14 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { var eltCtr = viewUtils.getCenterOfProjection(); viewUtils.popViewportObj(); - eltCtr = viewUtils.localToGlobal(eltCtr, elt); + // cache the local to global and global to local matrices + var l2gMat = viewUtils.getLocalToGlobalMatrix( elt ); + var g2lMat = glmat4.inverse( l2gMat, [] ); + eltCtr = MathUtils.transformAndDivideHomogeneousPoint( eltCtr, l2gMat ); - this._targets.push({elt:elt, mat:curMat, matInv:curMatInv, ctr:eltCtr}); - if(addToUndoStack) + this._targets.push({elt:elt, mat:curMat, matInv:curMatInv, ctr:eltCtr, l2g:l2gMat, g2l:g2lMat}); + + if(addToUndoStack) { var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; @@ -379,12 +391,54 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } }, + calculateMultiSelOrigin: + { + value: function() + { + var minPt, maxPt, i,j; + this._startOriginArray = []; + var len = this.application.ninja.selectedElements.length; + for (i = 0; i < len; i++) + { + // get the next element and localToGlobal matrix + elt = this._targets[i].elt; + var l2g = this._targets[i].l2g; + + // get the element bounds in 'plane' space + bounds = viewUtils.getElementViewBounds3D( elt ); + for (j=0; j<4; j++) + { + var localPt = bounds[j]; + //var pt = MathUtils.transformAndDivideHomogeneousPoint( localPt, l2g ); + var pt = viewUtils.localToStageWorld( localPt, elt ); + if (!minPt) + { + minPt = pt.slice(); + maxPt = pt.slice(); + } + else + { + minPt[0] = Math.min(minPt[0],pt[0]); minPt[1] = Math.min(minPt[1],pt[1]); minPt[2] = Math.min(minPt[2],pt[2]); + maxPt[0] = Math.max(maxPt[0],pt[0]); maxPt[1] = Math.max(maxPt[1],pt[1]); maxPt[2] = Math.max(maxPt[2],pt[2]); + } + } + } + var stageWorldCtr = [ 0.5*(minPt[0] + maxPt[0]), 0.5*(minPt[1] + maxPt[1]), 0.5*(minPt[2] + maxPt[2]) ]; + var globalCtr = MathUtils.transformAndDivideHomogeneousPoint( stageWorldCtr, viewUtils.getStageWorldToGlobalMatrix() ); + console.log( "resetting _origin to: " + this._origin ); + + return globalCtr; + } + }, + _setTransformOrigin: { value: function(shouldUpdateCenter) { if(!this._origin) { return; } + console.log( "_setTransformOrigin, _activateOriginHandle: " + this._activateOriginHandle ); + var len = this._targets.length; var elt, eltCtr, @@ -396,13 +450,14 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { if(shouldUpdateCenter) { - eltCtr = this._targets[0].ctr; - ctrOffset = vecUtils.vecSubtract(3, this._origin, eltCtr); +// eltCtr = this._targets[0].ctr; +// ctrOffset = vecUtils.vecSubtract(3, this._origin, eltCtr); - matInv = this._targets[0].matInv; - ctrOffset = MathUtils.transformVector(ctrOffset, matInv); +// matInv = this._targets[0].matInv; +// ctrOffset = MathUtils.transformVector(ctrOffset, matInv); - elt.elementModel.props3D.m_transformCtr = ctrOffset; +// elt.elementModel.props3D.m_transformCtr = ctrOffset; + elt.elementModel.props3D.m_transformCtr = this._startOriginArray[0].slice(); } else { @@ -412,21 +467,41 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { { ctrOffset = [0,0,0]; } + this._startOriginArray[0] = ctrOffset; } - this._startOriginArray[0] = ctrOffset; } else { - // Update transform ctr for all elements if transform origin was modified - this._startOriginArray = []; - for (var i = 0; i < len; i++) { + /* + this._startOriginArray = []; + for (var i = 0; i < len; i++) { + elt = this._targets[i].elt; + eltCtr = this._targets[i].ctr; + ctrOffset = vecUtils.vecSubtract(3, this._origin, eltCtr); + matInv = this._targets[i].matInv; + ctrOffset = MathUtils.transformVector(ctrOffset, matInv); + this._startOriginArray[i] = ctrOffset; + } + */ + + // Update transform ctr for all elements if transform origin was modified + if (!this._origin) this._origin = this.calculateMultiSelOrigin(); + var globalCtr = this._origin; + for (i=0; i 1)) { - this._origin = null; + //this._origin = null; this._updateHandlesOrigin(); } this.DrawHandles(); } }, + _updateHandlesOrigin: { + value: function () { } + }, + handleToolDoubleClick: { value: function(event) { if(!this._target) -- cgit v1.2.3 From 642d7b45446894a2f3038dcc07a867b260968256 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 13 Apr 2012 13:48:07 -0700 Subject: 3D rotation --- js/helper-classes/3D/snap-manager.js | 2 +- js/tools/Rotate3DToolBase.js | 19 ++++++++----------- js/tools/Translate3DToolBase.js | 5 ----- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index 5735a145..14a621d0 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -307,7 +307,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { this.setLastHit( rtnHit ); - rtnHit.test(); // DEBUG CODE. REMOVE THIS + //rtnHit.test(); // DEBUG CODE. REMOVE THIS return rtnHit; } }, diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js index e65dc842..880eefc4 100755 --- a/js/tools/Rotate3DToolBase.js +++ b/js/tools/Rotate3DToolBase.js @@ -54,22 +54,19 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { { if(this._activateOriginHandle) { - // move the transform origin handle - var dx = pt1.x - pt0.x; - var dy = pt1.y - pt0.y; - var dz = pt1.z - pt0.z; + // move the transform origin handle directly to the snap point (pt1) + this._origin[0] = pt1.x; + this._origin[1] = pt1.y; + this._origin[2] = pt1.z; - this._origin[0] += dx; - this._origin[1] += dy; - this._origin[2] += dz; - console.log( "modifyElements, _origin: " + this._origin ); + var sw2gMat = viewUtils.getStageWorldToGlobalMatrix(); + var g2swMat = glmat4.inverse( sw2gMat, [] ); + var swOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2swMat ); + //console.log( "modifyElements, _origin: " + this._origin + ", in stageWorld: " + swOrigin ); var len = this._targets.length; if(len === 1) { -// this._startOriginArray[0][0] += dx; -// this._startOriginArray[0][1] += dy; -// this._startOriginArray[0][2] += dz; var g2lMat = this._targets[0].g2l; var localOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2lMat ); var elt = this._targets[0].elt; diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index ac98d018..a39dafad 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js @@ -204,11 +204,6 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, _updateTargets: { value: function(addToUndoStack) { - { - { -// console.log( "_updateTargets" ); - console.log( "_updateTargets" ); - //console.log( "_updateTargets" ); var newStyles = [], previousStyles = [], len = this.application.ninja.selectedElements.length; -- cgit v1.2.3 From a62cfc5976b03a9b6c7ee2f308312319b6b0e142 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 16 Apr 2012 10:34:14 -0700 Subject: 3D translation fixes --- js/tools/Rotate3DToolBase.js | 27 ++++++++++ js/tools/Translate3DToolBase.js | 115 ++++++++++++++++++++++++++++++++-------- 2 files changed, 120 insertions(+), 22 deletions(-) diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js index 880eefc4..d08b3a31 100755 --- a/js/tools/Rotate3DToolBase.js +++ b/js/tools/Rotate3DToolBase.js @@ -43,6 +43,33 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } }, + HandleMouseMove: { + value: function(event) { + if(this._escape) { + this._escape = false; + this.isDrawing = true; + } + + if(this.isDrawing) { + this._hasDraw = true; // Flag for position of element + this.doDraw(event); + } else { + this._showFeedbackOnMouseMove(event); + if(this._canSnap) + { + this.doSnap(event); + } + } + + this.DrawHandles(this._delta); + + if(this._canSnap) + { + snapManager.drawLastHit(); + } + } + }, + modifyElements: { value: function(data, event) { var mat, diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index a39dafad..41dbb3ae 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js @@ -296,42 +296,113 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, viewUtils.popViewportObj(); ctr[2] = 0; -// var ctrOffset = item.elementModel.props3D.m_transformCtr; -// if(ctrOffset) -// { -// ctr = vecUtils.vecAdd(3, ctr, ctrOffset); -// } - this._origin = viewUtils.localToGlobal(ctr, item); } else { - if(this._origin) + this._origin = undefined; + this._origin = this.calculateMultiSelOrigin(); + } + } + } + }, + + captureSelectionDrawn: { + value: function(event){ + this._origin = null; + this._targets = []; + this._startOriginArray = null; + + var len = this.application.ninja.selectedElements.length; + if(len) + { + if(len === 1) + { + this.target = this.application.ninja.selectedElements[0]; + drawUtils.addElement(this.target); + + viewUtils.pushViewportObj( this.target ); + var eltCtr = viewUtils.getCenterOfProjection(); + eltCtr[2] = 0; + viewUtils.popViewportObj(); + + var ctrOffset = this.target.elementModel.props3D.m_transformCtr; + if(ctrOffset) + { + eltCtr[2] = 0; + eltCtr = vecUtils.vecAdd(3, eltCtr, ctrOffset); + } + + this._origin = viewUtils.localToGlobal(eltCtr, this.target); + console.log( "Rotate3DToolBase.captureSelectionDrawn _origin: " + this._origin ); + this._updateTargets(); + //this._setTransformOrigin(false); + } + else + { + this.target = this.application.ninja.currentDocument.documentRoot; + //this._origin = drawUtils._selectionCtr.slice(0); + //this._origin[0] += this.application.ninja.stage.userContentLeft; + //this._origin[1] += this.application.ninja.stage.userContentTop; + this._updateTargets(); + this._origin = this.calculateMultiSelOrigin(); + //this._setTransformOrigin(true); + } + } + else + { + this.target = null; + } + this.DrawHandles(); + + if(event) + { + this.eventManager.removeEventListener("selectionDrawn", this, true); + } + } + }, + + calculateMultiSelOrigin: + { + value: function() + { + var minPt, maxPt, i,j; + this._startOriginArray = []; + var len = this.application.ninja.selectedElements.length; + for (i = 0; i < len; i++) + { + // get the next element and localToGlobal matrix + elt = this._targets[i].elt; + var l2g = this._targets[i].l2g; + + // get the element bounds in 'plane' space + bounds = viewUtils.getElementViewBounds3D( elt ); + for (j=0; j<4; j++) + { + var localPt = bounds[j]; + //var pt = MathUtils.transformAndDivideHomogeneousPoint( localPt, l2g ); + var pt = viewUtils.localToStageWorld( localPt, elt ); + if (!minPt) { - if(this._delta) - { - if(this._handleMode !== null) - { -// this._origin[this._handleMode] = this._delta; - } - else - { - this._origin[0] += this._delta[0]; - this._origin[1] += this._delta[1]; - } - } + minPt = pt.slice(); + maxPt = pt.slice(); } else { - this._origin = drawUtils._selectionCtr.slice(0); - this._origin[0] += this.application.ninja.stage.userContentLeft; - this._origin[1] += this.application.ninja.stage.userContentTop; + minPt[0] = Math.min(minPt[0],pt[0]); minPt[1] = Math.min(minPt[1],pt[1]); minPt[2] = Math.min(minPt[2],pt[2]); + maxPt[0] = Math.max(maxPt[0],pt[0]); maxPt[1] = Math.max(maxPt[1],pt[1]); maxPt[2] = Math.max(maxPt[2],pt[2]); } } } + var stageWorldCtr = [ 0.5*(minPt[0] + maxPt[0]), 0.5*(minPt[1] + maxPt[1]), 0.5*(minPt[2] + maxPt[2]) ]; + var globalCtr = MathUtils.transformAndDivideHomogeneousPoint( stageWorldCtr, viewUtils.getStageWorldToGlobalMatrix() ); + console.log( "resetting _origin to: " + this._origin ); + + return globalCtr; } }, + DrawHandles: { value: function (delta) { this.application.ninja.stage.clearDrawingCanvas(); -- cgit v1.2.3 From 19115d65a309ccbeab8e07d426ac398dae8a9d68 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 16 Apr 2012 13:10:27 -0700 Subject: snapping for stage rotation tool --- js/tools/RotateStage3DTool.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/js/tools/RotateStage3DTool.js b/js/tools/RotateStage3DTool.js index f5cc4040..c0808de3 100755 --- a/js/tools/RotateStage3DTool.js +++ b/js/tools/RotateStage3DTool.js @@ -72,9 +72,11 @@ exports.RotateStage3DTool = Montage.create(Rotate3DToolBase, { var eltCtr = viewUtils.getCenterOfProjection(); viewUtils.popViewportObj(); - eltCtr = viewUtils.localToGlobal(eltCtr, elt); - - this._targets.push({elt:elt, mat:curMat, matInv:curMatInv, ctr:eltCtr}); + // cache the local to global and global to local matrices + var l2gMat = viewUtils.getLocalTo