diff options
Diffstat (limited to 'js/tools')
-rwxr-xr-x | js/tools/Translate3DToolBase.js | 25 | ||||
-rwxr-xr-x | js/tools/TranslateObject3DTool.js | 21 | ||||
-rwxr-xr-x | js/tools/modifier-tool-base.js | 14 |
3 files changed, 41 insertions, 19 deletions
diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index 07b6d04d..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) |
@@ -66,15 +68,12 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
66 | delta[0] = 0; | 68 | delta[0] = 0; |
67 | delta[1] = 0; | 69 | delta[1] = 0; |
68 | } | 70 | } |
69 | else | ||
70 | { | ||
71 | delta[2] = 0; | ||
72 | } | ||
73 | this._delta = delta.slice(0); | 71 | this._delta = delta.slice(0); |
74 | } | 72 | } |
75 | 73 | ||
76 | var transMat = Matrix.Translation( delta ); | 74 | var transMat = Matrix.Translation( delta ); |
77 | 75 | ||
76 | //console.log( "Translate: " + delta ); | ||
78 | if(this._inLocalMode && (this._targets.length === 1) ) | 77 | if(this._inLocalMode && (this._targets.length === 1) ) |
79 | { | 78 | { |
80 | this._translateLocally(transMat); | 79 | this._translateLocally(transMat); |
@@ -134,6 +133,9 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
134 | // We will only translate single elements locally | 133 | // We will only translate single elements locally |
135 | _translateLocally: { | 134 | _translateLocally: { |
136 | 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 ); | ||
137 | var mat = glmat4.multiply(this._startMat, transMat, []); | 139 | var mat = glmat4.multiply(this._startMat, transMat, []); |
138 | viewUtils.setMatrixForElement( this._target, mat, true ); | 140 | viewUtils.setMatrixForElement( this._target, mat, true ); |
139 | if(this._mode !== 1) | 141 | if(this._mode !== 1) |
@@ -145,14 +147,22 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
145 | 147 | ||
146 | _translateGlobally: { | 148 | _translateGlobally: { |
147 | value: function (transMat) { | 149 | value: function (transMat) { |
150 | //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); | ||
151 | //console.log( "_translateGlobally, transMat: " + transMat ); | ||
148 | var len = this._targets.length, | 152 | var len = this._targets.length, |
149 | i = 0, | 153 | i = 0, |
150 | item, | 154 | item, |
151 | elt, | 155 | elt, |
152 | curMat, | 156 | curMat = viewUtils.getMatrixFromElement( this._target ), |
153 | matInv = glmat4.inverse(this._startMat, []), | 157 | matInv = glmat4.inverse(this._startMat, []), |
154 | nMat = glmat4.multiply(transMat, this._startMat, [] ), | 158 | nMat = glmat4.multiply(transMat, this._startMat, [] ), |
155 | 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 | } | ||
156 | 166 | ||
157 | var shouldUpdateStartMat = true; | 167 | var shouldUpdateStartMat = true; |
158 | 168 | ||
@@ -181,6 +191,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
181 | 191 | ||
182 | if(shouldUpdateStartMat) | 192 | if(shouldUpdateStartMat) |
183 | { | 193 | { |
194 | //console.log( "\t\tshouldUpdateStartMat" ); | ||
184 | this._targets[i].mat = curMat; | 195 | this._targets[i].mat = curMat; |
185 | } | 196 | } |
186 | } | 197 | } |
@@ -188,7 +199,9 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
188 | }, | 199 | }, |
189 | 200 | ||
190 | _updateTargets: { | 201 | _updateTargets: { |
191 | value: function(addToUndoStack) { | 202 | value: function(addToUndoStack) |
203 | { | ||
204 | console.log( "_updateTargets" ); | ||
192 | var newStyles = [], | 205 | var newStyles = [], |
193 | previousStyles = [], | 206 | previousStyles = [], |
194 | 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 94b806fd..07b28747 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 |