aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools')
-rwxr-xr-xjs/tools/Translate3DToolBase.js21
-rwxr-xr-xjs/tools/TranslateObject3DTool.js21
-rwxr-xr-xjs/tools/modifier-tool-base.js14
3 files changed, 41 insertions, 15 deletions
diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js
index 005b9749..18e2b610 100755
--- a/js/tools/Translate3DToolBase.js
+++ b/js/tools/Translate3DToolBase.js
@@ -29,6 +29,8 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
29 modifyElements : { 29 modifyElements : {
30 value : function(data, event) 30 value : function(data, event)
31 { 31 {
32 //console.log( "modifyElements, data: " + data.pt0 + " => " + data.pt1 );
33
32 // form the translation vector and post translate the matrix by it. 34 // form the translation vector and post translate the matrix by it.
33 var delta = vecUtils.vecSubtract( 3, data.pt1, data.pt0 ); 35 var delta = vecUtils.vecSubtract( 3, data.pt1, data.pt0 );
34 if(this._handleMode !== null) 36 if(this._handleMode !== null)
@@ -71,6 +73,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
71 73
72 var transMat = Matrix.Translation( delta ); 74 var transMat = Matrix.Translation( delta );
73 75
76 //console.log( "Translate: " + delta );
74 if(this._inLocalMode && (this._targets.length === 1) ) 77 if(this._inLocalMode && (this._targets.length === 1) )
75 { 78 {
76 this._translateLocally(transMat); 79 this._translateLocally(transMat);
@@ -130,6 +133,9 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
130 // We will only translate single elements locally 133 // We will only translate single elements locally
131 _translateLocally: { 134 _translateLocally: {
132 value: function (transMat) { 135 value: function (transMat) {
136 //console.log( "_translateLocally, startMat: " + this._startMat );
137 //console.log( "_translateLocally, transMat: " + transMat );
138 //console.log( "_translateLocally, startMat: " + this._startMat + ", transMat: " + transMat );
133 var mat = glmat4.multiply(this._startMat, transMat, []); 139 var mat = glmat4.multiply(this._startMat, transMat, []);
134 viewUtils.setMatrixForElement( this._target, mat, true ); 140 viewUtils.setMatrixForElement( this._target, mat, true );
135 if(this._mode !== 1) 141 if(this._mode !== 1)
@@ -141,14 +147,22 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
141 147
142 _translateGlobally: { 148 _translateGlobally: {
143 value: function (transMat) { 149 value: function (transMat) {
150 //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat );
151 //console.log( "_translateGlobally, transMat: " + transMat );
144 var len = this._targets.length, 152 var len = this._targets.length,
145 i = 0, 153 i = 0,
146 item, 154 item,
147 elt, 155 elt,
148 curMat, 156 curMat = viewUtils.getMatrixFromElement( this._target ),
149 matInv = glmat4.inverse(this._startMat, []), 157 matInv = glmat4.inverse(this._startMat, []),
150 nMat = glmat4.multiply(transMat, this._startMat, [] ), 158 nMat = glmat4.multiply(transMat, this._startMat, [] ),
151 qMat = glmat4.multiply(matInv, nMat, []); 159 qMat = glmat4.multiply(matInv, nMat, []);
160
161 if (this._mode === 1)
162 {
163 var curInv = glmat4.inverse( curMat, [] );
164 transMat = glmat4.multiply( nMat, curInv, [] );
165 }
152 166
153 var shouldUpdateStartMat = true; 167 var shouldUpdateStartMat = true;
154 168
@@ -177,6 +191,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
177 191
178 if(shouldUpdateStartMat) 192 if(shouldUpdateStartMat)
179 { 193 {
194 //console.log( "\t\tshouldUpdateStartMat" );
180 this._targets[i].mat = curMat; 195 this._targets[i].mat = curMat;
181 } 196 }
182 } 197 }
@@ -184,7 +199,9 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
184 }, 199 },
185 200
186 _updateTargets: { 201 _updateTargets: {
187 value: function(addToUndoStack) { 202 value: function(addToUndoStack)
203 {
204 console.log( "_updateTargets" );
188 var newStyles = [], 205 var newStyles = [],
189 previousStyles = [], 206 previousStyles = [],
190 len = this.application.ninja.selectedElements.length; 207 len = this.application.ninja.selectedElements.length;
diff --git a/js/tools/TranslateObject3DTool.js b/js/tools/TranslateObject3DTool.js
index 60633e74..7163f005 100755
--- a/js/tools/TranslateObject3DTool.js
+++ b/js/tools/TranslateObject3DTool.js
@@ -16,6 +16,8 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, {
16 initializeSnapping : { 16 initializeSnapping : {
17 value : function(event) 17 value : function(event)
18 { 18 {
19 console.log( "initializeSnapping" );
20
19 this._mouseDownHitRec = null; 21 this._mouseDownHitRec = null;
20 this._mouseUpHitRec = null; 22 this._mouseUpHitRec = null;
21 23
@@ -37,8 +39,6 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, {
37 39
38 if(this._handleMode === null) 40 if(this._handleMode === null)
39 { 41 {
40// this.doSelection(event);
41
42 snapManager.enableElementSnap ( true ); 42 snapManager.enableElementSnap ( true );
43 snapManager.enableGridSnap ( true ); 43 snapManager.enableGridSnap ( true );
44 } 44 }
@@ -107,16 +107,10 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, {
107 } 107 }
108 108
109 if(this._handleMode === 2) 109 if(this._handleMode === 2)
110 {
111 // TODO - not sure how to parameterize point in z-translate mode
112 this.clickedObject = this._target; 110 this.clickedObject = this._target;
113 this._snapParam = [0, 0, 0]; 111
114 } 112 // parameterize the snap point on the target
115 else 113 this._snapParam = this.parameterizeSnap( hitRec );
116 {
117 // parameterize the snap point on the target
118 this._snapParam = this.parameterizeSnap( hitRec );
119 }
120 114
121 if(!this._dragPlane) 115 if(!this._dragPlane)
122 { 116 {
@@ -132,6 +126,11 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, {
132 126
133 } 127 }
134 128
129 // only do quadrant snapping if the 4 corners of the element are in the drag plane
130
131 var sign = MathUtils.fpSign( VecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0);
132 this._shouldUseQuadPt = (sign == 0);
133
135 var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); 134 var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane );
136 this._mouseDownHitRec = wpHitRec; 135 this._mouseDownHitRec = wpHitRec;
137 this._mouseUpHitRec = null; 136 this._mouseUpHitRec = null;
diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js
index a1812650..5f2d29be 100755
--- a/js/tools/modifier-tool-base.js
+++ b/js/tools/modifier-tool-base.js
@@ -25,6 +25,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
25 _snapParam: { value: null }, 25 _snapParam: { value: null },
26 _snapIndex: { value: -1 }, 26 _snapIndex: { value: -1 },
27 _useQuadPt: { value: false }, 27 _useQuadPt: { value: false },
28 _shouldUseQuadPt: { value: false },
28 29
29 // we set snapping capabilities depending on the tool. 30 // we set snapping capabilities depending on the tool.
30 // The following variables are set in a tool's initializeSnapping method called on mouse down. 31 // The following variables are set in a tool's initializeSnapping method called on mouse down.
@@ -175,6 +176,10 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
175// } 176// }
176 } 177 }
177 178
179 // only do quadrant snapping if the 4 corners of the element are in the drag plane
180 var sign = MathUtils.fpSign( VecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0);
181 this._shouldUseQuadPt = (sign == 0)
182
178 var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); 183 var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane );
179 this._mouseDownHitRec = wpHitRec; 184 this._mouseDownHitRec = wpHitRec;
180 this._mouseUpHitRec = null; 185 this._mouseUpHitRec = null;
@@ -236,6 +241,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
236 } 241 }
237 } 242 }
238 243
244 //console.log( "ParameterizeSnap: " + paramPt );
239 return paramPt; 245 return paramPt;
240 } 246 }
241 }, 247 },
@@ -284,14 +290,16 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
284 y = x0 + ty*dy, 290 y = x0 + ty*dy,
285 z = 0.0; 291 z = 0.0;
286 var localPt = [x,y,z]; 292 var localPt = [x,y,z];
293
287 globalPt = viewUtils.localToGlobal( localPt, elt ); 294 globalPt = viewUtils.localToGlobal( localPt, elt );
288 295
289 // add in the delta 296 // add in the delta
290 var hitPt = this.GetObjectHitPoint(); 297 var hitPt = this.GetObjectHitPoint();
291 var scrPt = viewUtils.localToGlobal( hitPt, this._clickedObject ); 298 var scrPt = viewUtils.localToGlobal( hitPt, this._clickedObject );
292 var delta = [xEvent-scrPt[0], yEvent-scrPt[1]]; 299 var delta = [xEvent-scrPt[0], yEvent-scrPt[1], 0-scrPt[2]];
293 globalPt[0] += delta[0]; 300 globalPt[0] += delta[0];
294 globalPt[1] += delta[1]; 301 globalPt[1] += delta[1];
302 globalPt[2] += delta[2];
295 } 303 }
296 304
297 return globalPt; 305 return globalPt;
@@ -518,7 +526,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
518 526
519 // do the snap 527 // do the snap
520 var quadPt; 528 var quadPt;
521 if (mouseIsDown) 529 if (mouseIsDown && !do3DSnap && this._shouldUseQuadPt && (this._handleMode === null) && (this._mode === 0))
522 quadPt = this.GetQuadrantSnapPoint(x,y); 530 quadPt = this.GetQuadrantSnapPoint(x,y);
523 var hitRec = snapManager.snap(x, y, do3DSnap, quadPt ); 531 var hitRec = snapManager.snap(x, y, do3DSnap, quadPt );
524 532
@@ -812,6 +820,8 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
812 HandleLeftButtonDown: {