aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValerio Virgillito2012-05-08 14:41:27 -0700
committerValerio Virgillito2012-05-08 14:41:27 -0700
commitd220c02e246b30509b28a47fa04916ca2b8122e4 (patch)
tree4b9165b807b026fb67ec34e8a40dfcb7f1152685
parent53747ce689ddcdc19e586b30d6f356b3b0539731 (diff)
parent15c7bdad38a83d192bd5a1d55a54362c12c73d38 (diff)
downloadninja-d220c02e246b30509b28a47fa04916ca2b8122e4.tar.gz
Merge pull request #201 from ericmueller/Snapping
fixes for 2D and 3D translation.
-rwxr-xr-xjs/helper-classes/3D/snap-manager.js4
-rwxr-xr-xjs/helper-classes/3D/view-utils.js80
-rwxr-xr-xjs/tools/SelectionTool.js2
-rwxr-xr-xjs/tools/TranslateObject3DTool.js9
-rwxr-xr-xjs/tools/drawing-tool-base.js5
5 files changed, 75 insertions, 25 deletions
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, {
1957 var localPt = hitRec.getLocalPoint(); 1957 var localPt = hitRec.getLocalPoint();
1958 var planeMat = hitRec.getPlaneMatrix(); 1958 var planeMat = hitRec.getPlaneMatrix();
1959 var stageWorldPt; 1959 var stageWorldPt;
1960
1961 /*
1960 if(inGlobalMode) 1962 if(inGlobalMode)
1961 { 1963 {
1962 stageWorldPt = MathUtils.transformPoint(localPt,planeMat); 1964 stageWorldPt = MathUtils.transformPoint(localPt,planeMat);
@@ -1965,6 +1967,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1965 { 1967 {
1966 stageWorldPt = viewUtils.postViewToStageWorld( MathUtils.transformPoint(localPt,planeMat), elt ); 1968 stageWorldPt = viewUtils.postViewToStageWorld( MathUtils.transformPoint(localPt,planeMat), elt );
1967 } 1969 }
1970 */
1971 stageWorldPt = viewUtils.postViewToStageWorld( MathUtils.transformPoint(localPt,planeMat), elt );
1968 1972
1969 /* 1973 /*
1970 // get a working plane parallel to the current working plane through the stage world point 1974 // 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, {
124 } 124 }
125 }, 125 },
126 126
127 getNormalToUnprojectedElementPlane: { 127 /*
128 value: function( elt ) { 128 * This method will return a normal to a plane containing the Z axis and either the
129 var mat = this.getMatrixFromElement(elt); 129 * x or y axis of the element.
130 */
131 getNormalToUnprojectedElementPlane:
132 {
133 value: function( elt, axis, localMode )
134 {
135 var objMat = this.getMatrixFromElement(elt);
136 var objMatInv = glmat4.inverse( objMat, [] );
130 137
131 var xVec = [mat[0], mat[1], mat[2], mat[3]]; 138 var xVec = [1,0,0];
132 var yVec = [mat[4], mat[5], mat[6], mat[7]]; 139 var yVec = [0,1,0];
140 var zVec = [0,0,1];
133 141
134 var stage = this.application.ninja.currentDocument.documentRoot; 142 var stage = this.application.ninja.currentDocument.documentRoot;
135 var stageMat = this.getMatrixFromElement(stage); 143 var stageMat = this.getMatrixFromElement(stage);
136 var stagePlane = [stageMat[8], stageMat[9], stageMat[10], stageMat[11]];
137 144
145 var mat = glmat4.multiply( stageMat, objMat, [] );
146
147 var viewDir;
148 if (localMode)
149 {
150 var matInv = glmat4.inverse( mat, [] );
151 viewDir = MathUtils.transformVector( [0,0,1], matInv );
152 }
153 else
154 {
155 var stageInv = glmat4.inverse( stageMat, [] );
156 viewDir = MathUtils.transformVector( [0,0,1], stageInv );
157 }
158
159 /*
138 if (elt === stage) 160 if (elt === stage)
139 { 161 {
140 xVec = [1,0,0]; 162 xVec = [1,0,0];
141 yVec = [0,1,0]; 163 yVec = [0,1,0];
142 } 164 }
165 */
143 166
144 var xDot = Math.abs(vecUtils.vecDot(3, xVec, stagePlane)); 167 var plane;
145 var yDot = Math.abs(vecUtils.vecDot(3, yVec, stagePlane)); 168 var xDot, yDot, zDot;
169 switch (axis)
170 {
171 case 0:
172 yDot = Math.abs(vecUtils.vecDot(3, yVec, viewDir));
173 zDot = Math.abs(vecUtils.vecDot(3, zVec, viewDir));
174 if(yDot > zDot)
175 plane = vecUtils.vecCross( 3, zVec, xVec );
176 else
177 plane = vecUtils.vecCross( 3, yVec, xVec );
178 break;
179
180 case 1:
181 xDot = Math.abs(vecUtils.vecDot(3, yVec, viewDir));
182 zDot = Math.abs(vecUtils.vecDot(3, zVec, viewDir));
183 if(xDot > zDot)
184 plane = vecUtils.vecCross( 3, zVec, yVec );
185 else
186 plane = vecUtils.vecCross( 3, xVec, yVec );
187 break;
188 break;
189
190 case 2:
191 xDot = Math.abs(vecUtils.vecDot(3, xVec, viewDir));
192 yDot = Math.abs(vecUtils.vecDot(3, yVec, viewDir));
193
194 if(xDot > yDot)
195 plane = vecUtils.vecCross( 3, yVec, zVec );
196 else
197 plane = vecUtils.vecCross( 3, xVec, zVec );
198 break;
199 }
146 200
147 var plane; 201 if (localMode) plane = MathUtils.transformVector( plane, objMat );
148 if(xDot > yDot)
149 {
150 plane = xVec;
151 }
152 else
153 {
154 plane = yVec;
155 }
156 202
157 // The translation value is a point on the plane 203 // The translation value is a point on the plane
158 this.pushViewportObj( elt ); 204 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, {
504 delta = vecUtils.vecSubtract( 3, data.pt1, data.pt0 ); 504 delta = vecUtils.vecSubtract( 3, data.pt1, data.pt0 );
505 delta[0] = ~~delta[0]; 505 delta[0] = ~~delta[0];
506 delta[1] = ~~delta[1]; 506 delta[1] = ~~delta[1];
507 delta[2] = 0; 507 //delta[2] = 0;
508 var transMat = Matrix.Translation( delta ); 508 var transMat = Matrix.Translation( delta );
509 this._moveElements(transMat); 509 this._moveElements(transMat);
510 } 510 }
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, {
54 else 54 else
55 { 55 {
56 this._delta = null; 56 this._delta = null;
57 // special case for z-translation 57 //if(this._handleMode === 2)
58 if(this._handleMode === 2)
59 { 58 {
60 this._dragPlane = viewUtils.getNormalToUnprojectedElementPlane(this._target); 59 this._dragPlane = viewUtils.getNormalToUnprojectedElementPlane(this._target, this._handleMode, this._inLocalMode);
60 //console.log( "dragPlane: " + this._dragPlane );
61 snapManager.setupDragPlaneFromPlane(this._dragPlane); 61 snapManager.setupDragPlaneFromPlane(this._dragPlane);
62 do3DSnap = false; 62 do3DSnap = false;
63 63
@@ -86,7 +86,8 @@ exports.TranslateObject3DTool = Montage.create(Translate3DToolBase, {
86 var elt = this.application.ninja.stage.getElement(event, true); 86 var elt = this.application.ninja.stage.getElement(event, true);
87 if(elt && (elt !== hitRec.getElement())) 87 if(elt && (elt !== hitRec.getElement()))
88 { 88 {
89 hitRec = snapManager.findHitRecordForElement(elt); 89 var otherSnap = snapManager.findHitRecordForElement(elt);
90 if (otherSnap) hitRec = otherSnap;
90 } 91 }
91 if(elt === this.application.ninja.currentSelectedContainer) 92 if(elt === this.application.ninja.currentSelectedContainer)
92 { 93 {
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, {
36 * 2 - Y value converted to screen point 36 * 2 - Y value converted to screen point
37 */ 37 */
38 getInitialSnapPoint: { 38 getInitialSnapPoint: {
39 value: function(x, y, shapeCanvas) { 39 value: function(x, y, shapeCanvas)
40 snapManager.clearDragPlane(); 40 {
41
42 // update the snap settings 41 // update the snap settings
43 snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); 42 snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() );
44 snapManager.enableElementSnap( snapManager.elementSnapEnabledAppLevel() ); 43 snapManager.enableElementSnap( snapManager.elementSnapEnabledAppLevel() );