diff options
author | Nivesh Rajbhandari | 2012-04-18 12:08:46 -0700 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-04-18 12:08:46 -0700 |
commit | fb20a74856a8c272d09d106765eb2e44c883f0c3 (patch) | |
tree | d41468b2fff52d73c6308de9730c17be05a71394 /js/tools/Translate3DToolBase.js | |
parent | e2510cba3b75bba78c587d784f39c137c1618369 (diff) | |
parent | 616a8532099fec2a15855eac97cd85cb60c4451c (diff) | |
download | ninja-fb20a74856a8c272d09d106765eb2e44c883f0c3.tar.gz |
Merge branch 'refs/heads/ninja-internal' into EricMerge
Conflicts:
js/tools/Rotate3DToolBase.js
js/tools/RotateStage3DTool.js
js/tools/Translate3DToolBase.js
js/tools/modifier-tool-base.js
Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'js/tools/Translate3DToolBase.js')
-rwxr-xr-x | js/tools/Translate3DToolBase.js | 238 |
1 files changed, 98 insertions, 140 deletions
diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index 41dbb3ae..bf07e89e 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js | |||
@@ -21,8 +21,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
21 | _clickedOnStage: { value: false }, | 21 | _clickedOnStage: { value: false }, |
22 | 22 | ||
23 | HandleDoubleClick : { | 23 | HandleDoubleClick : { |
24 | value : function() | 24 | value : function() { |
25 | { | ||
26 | } | 25 | } |
27 | }, | 26 | }, |
28 | 27 | ||
@@ -74,7 +73,8 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
74 | //console.log( "modifyElements delta: " + delta ); | 73 | //console.log( "modifyElements delta: " + delta ); |
75 | var transMat = Matrix.Translation( delta ); | 74 | var transMat = Matrix.Translation( delta ); |
76 | 75 | ||
77 | if(this._inLocalMode && (this._targets.length === 1) ) | 76 | //console.log( "Translate: " + delta ); |
77 | if(this._inLocalMode && (this.application.ninja.selectedElements.length === 1) ) | ||
78 | { | 78 | { |
79 | this._translateLocally(transMat); | 79 | this._translateLocally(transMat); |
80 | } | 80 | } |
@@ -86,45 +86,32 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
86 | }, | 86 | }, |
87 | 87 | ||
88 | 88 | ||
89 | Reset : { | 89 | Reset: { |
90 | value : function() | 90 | value: function() { |
91 | { | 91 | var mat, iMat, dist, mod3dObject = [], self = this; |
92 | var item, | 92 | |
93 | mat, | 93 | this.application.ninja.selectedElements.forEach(function(element) { |
94 | dist, | 94 | // Reset to the identity matrix |
95 | newStyles = [], | 95 | //item = this.application.ninja.selectedElements[i]; |
96 | previousStyles = [], | 96 | iMat = Matrix.I(4); |
97 | len = this.application.ninja.selectedElements.length; | 97 | mat = ElementsMediator.getMatrix(element); |
98 | for(var i = 0; i < len; i++) | ||
99 | { | ||
100 | // Reset to the identity matrix but retain the rotation values | ||
101 | item = this.application.ninja.selectedElements[i]; | ||
102 | mat = ElementsMediator.getMatrix(item); | ||
103 | mat[12] = 0; | 98 | mat[12] = 0; |
104 | mat[13] = 0; | 99 | mat[13] = 0; |
105 | mat[14] = 0; | 100 | mat[14] = 0; |
106 | 101 | ||
107 | dist = ElementsMediator.getPerspectiveDist(item); | 102 | dist = ElementsMediator.getPerspectiveDist(element); |
108 | |||
109 | var previousStyleStr = {dist:dist, mat:item.mat}; | ||
110 | 103 | ||
111 | var newStyleStr = {dist:dist, mat:mat}; | 104 | var previousStyleStr = {dist:dist, mat:element.elementModel.getProperty("mat")}; |
105 | var newStyleStr = {dist:dist, mat:iMat}; | ||
112 | 106 | ||
113 | previousStyles.push(previousStyleStr); | 107 | mod3dObject.push({element:element, properties:newStyleStr, previousProperties: previousStyleStr}); |
114 | newStyles.push(newStyleStr); | 108 | }); |
115 | } | ||
116 | 109 | ||
117 | ElementsMediator.set3DProperties(this.application.ninja.selectedElements, | 110 | ElementsMediator.set3DProperties(mod3dObject, "Change", "rotateTool"); |
118 | newStyles, | ||
119 | "Change", | ||
120 | "translateTool", | ||
121 | previousStyles | ||
122 | ); | ||
123 | 111 | ||
124 | this.isDrawing = false; | 112 | this.isDrawing = false; |
125 | this.endDraw(event); | 113 | this.endDraw(event); |
126 | 114 | ||
127 | |||
128 | // Need to force stage to draw immediately so the new selection center is calculated | 115 | // Need to force stage to draw immediately so the new selection center is calculated |
129 | this.application.ninja.stage.draw(); | 116 | this.application.ninja.stage.draw(); |
130 | // And captureSelectionDrawn to draw the transform handles | 117 | // And captureSelectionDrawn to draw the transform handles |
@@ -149,27 +136,27 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
149 | 136 | ||
150 | _translateGlobally: { | 137 | _translateGlobally: { |
151 | value: function (transMat) { | 138 | value: function (transMat) { |
152 | //console.log( "_translateGlobally, transMat: " + transMat ); | 139 | //console.log( "_translateGlobally, transMat: " + transMat ); |
153 | //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat[12] + ", " + transMat[13] + ", " + transMat[14] ); | 140 | var selectedElements = this.application.ninja.selectedElements; |
154 | var len = this._targets.length, | 141 | if(this.rotateStage) { |
155 | i = 0, | 142 | selectedElements = [this.application.ninja.currentDocument.documentRoot]; |
156 | item, | 143 | } |
157 | elt, | 144 | |
158 | curMat = viewUtils.getMatrixFromElement( this._target ), | 145 | var self = this, |
159 | matInv = glmat4.inverse(this._startMat, []), | 146 | target = selectedElements[0], |
160 | nMat = glmat4.multiply(transMat, this._startMat, [] ), | 147 | curMat = viewUtils.getMatrixFromElement( target ), |
161 | qMat = glmat4.multiply(matInv, nMat, []); | 148 | matInv = glmat4.inverse(this._startMat, []), |
162 | 149 | nMat = glmat4.multiply(transMat, this._startMat, [] ); | |
163 | if (this._mode === 1) | 150 | // qMat = glmat4.multiply(matInv, nMat, []); |
164 | { | 151 | |
165 | if (len > 1) curMat = this._targets[0].mat.slice(); | 152 | if(this._mode === 1) { |
166 | var curInv = glmat4.inverse( curMat, [] ); | 153 | if (len > 1) curMat = target.elementModel.getProperty("mat").slice(); |
167 | transMat = glmat4.multiply( nMat, curInv, [] ); | 154 | var curInv = glmat4.inverse( curMat, [] ); |
168 | } | 155 | transMat = glmat4.multiply( nMat, curInv, [] ); |
156 | } | ||
169 | 157 | ||
170 | var shouldUpdateStartMat = true; | 158 | var shouldUpdateStartMat = true; |
171 | 159 | ||
172 | //if (this._clickedOnStage) | ||
173 | if(this._clickedOnStage || ((this._handleMode === 2) && (this._targets.length > 1))) | 160 | if(this._clickedOnStage || ((this._handleMode === 2) && (this._targets.length > 1))) |
174 | { | 161 | { |
175 | shouldUpdateStartMat = false; | 162 | shouldUpdateStartMat = false; |
@@ -179,84 +166,60 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, | |||
179 | this._startMat = nMat; | 166 | this._startMat = nMat; |
180 | } | 167 | } |
181 | 168 | ||
182 | for(i = 0; i < len; i++) | 169 | this.application.ninja.selectedElements.forEach(function(element) { |
183 | { | 170 | curMat = element.elementModel.getProperty("mat").slice(0); |
184 | item = this._targets[i]; | 171 | |
185 | elt = item.elt; | 172 | // glmat4.multiply(curMat, qMat, curMat); |
186 | curMat = item.mat.slice(0); | 173 | // viewUtils.setMatrixForElement( elt, curMat, true); |
187 | 174 | curMat[12] += transMat[12]; | |
188 | // glmat4.multiply(curMat, qMat, curMat); | 175 | curMat[13] += transMat[13]; |
189 | // | 176 | curMat[14] += transMat[14]; |
190 | // viewUtils.setMatrixForElement( elt, curMat, true); | 177 | |
191 | curMat[12] += transMat[12]; | 178 | viewUtils.setMatrixForElement(element, curMat, true); |
192 | curMat[13] += transMat[13]; | 179 | |
193 | curMat[14] += transMat[14]; | 180 | if(shouldUpdateStartMat) { |
194 | viewUtils.setMatrixForElement( elt, curMat, true); | 181 | //console.log( "\t\tshouldUpdateStartMat" ); |
195 | 182 | element.elementModel.setProperty("mat", curMat); | |
196 | if(shouldUpdateStartMat) | 183 | } |
197 | { | 184 | |
198 | //console.log( "\t\tshouldUpdateStartMat" ); | 185 | }); |
199 | this._targets[i].mat = curMat; | ||
200 | } | ||
201 | } | ||
202 | } | 186 | } |
203 | }, | 187 | }, |
204 | 188 | ||
205 | _updateTargets: { | 189 | _updateTargets: { |
206 | value: function(addToUndoStack) { | 190 | value: function(addToUndo) { |
207 | var newStyles = [], | 191 | var mod3dObject = [], self = this; |
208 | previousStyles = [], | ||
209 | len = this.application.ninja.selectedElements.length; | ||
210 | this._targets = []; | ||
211 | for(var i = 0; i < len; i++) | ||
212 | { | ||
213 | var elt = this.application.ninja.selectedElements[i]; | ||
214 | 192 | ||
215 | var curMat = viewUtils.getMatrixFromElement(elt); | 193 | this.application.ninja.selectedElements.forEach(function(element) { |
216 | var curMatInv = glmat4.inverse(curMat, []); | 194 | if(addToUndo) { |
195 | var previousMat = element.elementModel.getProperty("mat").slice(0); | ||
196 | var previousStyleStr = {dist:element.elementModel.getProperty("dist"), mat:MathUtils.scientificToDecimal(previousMat, 5)}; | ||
197 | var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(element), mat:MathUtils.scientificToDecimal(viewUtils.getMatrixFromElement(element), 5)}; | ||
217 | 198 | ||
218 | this._targets.push({elt:elt, mat:curMat, matInv:curMatInv}); | 199 | mod3dObject.push({element:element, properties:newStyleStr, previousProperties: previousStyleStr}); |
219 | if(addToUndoStack) | ||
220 | { | ||
221 | var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; | ||
222 | 200 | ||
223 | var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)}; | 201 | } |
202 | }); | ||
224 | 203 | ||
225 | previousStyles.push(previousStyleStr); | 204 | if(addToUndo) { |
226 | newStyles.push(newStyleStr); | 205 | ElementsMediator.set3DProperties(mod3dObject, "Change", "translateTool"); |
227 | } | 206 | |
228 | } | 207 | if(this._origin && this._delta) { |
229 | if(addToUndoStack) | 208 | if(this._handleMode !== null) { |
230 | { | 209 | this._origin[this._handleMode] += this._delta; |
231 | ElementsMediator.set3DProperties(this.application.ninja.selectedElements, | 210 | } else { |
232 | newStyles, | 211 | this._origin[0] += this._delta[0]; |
233 | "Change", | 212 | this._origin[1] += this._delta[1]; |
234 | "translateTool", | 213 | } |
235 | previousStyles |