aboutsummaryrefslogtreecommitdiff
path: root/js/tools/Rotate3DToolBase.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/Rotate3DToolBase.js')
-rwxr-xr-xjs/tools/Rotate3DToolBase.js243
1 files changed, 201 insertions, 42 deletions
diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js
index 2e121b0b..04bdc946 100755
--- a/js/tools/Rotate3DToolBase.js
+++ b/js/tools/Rotate3DToolBase.js
@@ -46,25 +46,76 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
46 } 46 }
47 }, 47 },
48 48
49 HandleMouseMove: {
50 value: function(event) {
51 if(this._escape) {
52 this._escape = false;
53 this.isDrawing = true;
54 }
55
56 if(this.isDrawing) {
57 this._hasDraw = true; // Flag for position of element
58 this.doDraw(event);
59 } else {
60 this._showFeedbackOnMouseMove(event);
61 if(this._canSnap)
62 {
63 this.doSnap(event);
64 }
65 }
66
67 this.DrawHandles(this._delta);
68
69 if(this._canSnap)
70 {
71 snapManager.drawLastHit();
72 }
73 }
74 },
75
49 modifyElements: { 76 modifyElements: {
50 value: function(data, event) { 77 value: function(data, event) {
51 var mat, angle, pt0 = data.pt0, pt1 = data.pt1; 78 var mat,
52 79 angle,
53 if(this._handleMode !== null) { 80 pt0 = data.pt0,
54 if(this._activateOriginHandle) { 81 pt1 = data.pt1;
55 // move the transform origin handle 82
56 var dx = pt1.x - pt0.x; 83 var selectedElements = this.application.ninja.selectedElements;
57 var dy = pt1.y - pt0.y; 84 if(this.rotateStage) {
58 this._origin[0] += dx; 85 selectedElements = [this.application.ninja.currentDocument.documentRoot];
59 this._origin[1] += dy; 86 }
60 87
61 if( this.rotateStage || (this.application.ninja.selectedElements.length === 1)) { 88 if(this._handleMode !== null)
62 this._startOriginArray[0][0] += dx; 89 {
63 this._startOriginArray[0][1] += dy; 90 if(this._activateOriginHandle)
91 {
92 // move the transform origin handle directly to the snap point (pt1)
93 this._origin[0] = pt1.x;
94 this._origin[1] = pt1.y;
95 this._origin[2] = pt1.z;
96
97 var sw2gMat = viewUtils.getStageWorldToGlobalMatrix();
98 var g2swMat = glmat4.inverse( sw2gMat, [] );
99 var swOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2swMat );
100 //console.log( "modifyElements, _origin: " + this._origin + ", in stageWorld: " + swOrigin );
101
102 var len = selectedElements.length;
103 if(len === 1)
104 {
105 var elt = selectedElements[0];
106 var g2lMat = elt.elementModel.getProperty("g2l");
107 var localOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2lMat );
108
109 viewUtils.pushViewportObj( elt );
110 var viewOrigin = viewUtils.screenToView( localOrigin[0], localOrigin[1], localOrigin[2] );
111 viewUtils.popViewportObj();
112 this._startOriginArray[0] = viewOrigin;
113 //console.log( "Rotate3DToolBase.modifyElements, _startOriginArray[0]: " + this._startOriginArray[0] );
64 } 114 }
65 115
66 this.downPoint.x = pt1.x; 116 this.downPoint.x = pt1.x;
67 this.downPoint.y = pt1.y; 117 this.downPoint.y = pt1.y;
118 this.downPoint.z = pt1.z;
68 this.DrawHandles(); 119 this.DrawHandles();
69 return; 120 return;
70 } 121 }
@@ -133,6 +184,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
133 184
134 if(this._inLocalMode && (this.application.ninja.selectedElements.length === 1 || this.rotateStage) ) 185 if(this._inLocalMode && (this.application.ninja.selectedElements.length === 1 || this.rotateStage) )
135 { 186 {
187// console.log( "modifyElements: rotateLocally " );
136 this._rotateLocally(mat); 188 this._rotateLocally(mat);
137 } 189 }
138 else 190 else
@@ -154,12 +206,14 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
154 } 206 }
155 var len = selectedElements.length; 207 var len = selectedElements.length;
156 for(var i = 0; i < len; i++) { 208 for(var i = 0; i < len; i++) {
157 var elt = selectedElements[i].elementModel.getProperty("elt"); 209 var elt = selectedElements[i];
158 var curMat = selectedElements[i].elementModel.getProperty("mat"); 210 var curMat = elt.elementModel.getProperty("mat");
159 211
160 // pre-translate by the transformation center 212 // pre-translate by the transformation center
161 var tMat = Matrix.I(4); 213 var tMat = Matrix.I(4);
162 214
215 // _startOriginArray is the location of the center of rotation
216 // in view space of the element.
163 var transformCtr = this._startOriginArray[i]; 217 var transformCtr = this._startOriginArray[i];
164 218
165 tMat[12] = transformCtr[0]; 219 tMat[12] = transformCtr[0];
@@ -179,7 +233,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
179 glmat4.multiply(mat, tMat, mat); 233 glmat4.multiply(mat, tMat, mat);
180 234
181 // while moving, set inline style to improve performance 235 // while moving, set inline style to improve performance
182 viewUtils.setMatrixForElement(selectedElements[i], mat, true ); 236 viewUtils.setMatrixForElement( elt, mat, true );
183 } 237 }
184 } 238 }
185 }, 239 },
@@ -197,6 +251,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
197 var transformCtr = this._startOriginArray[i].slice(0); 251 var transformCtr = this._startOriginArray[i].slice(0);
198 transformCtr = MathUtils.transformPoint(transformCtr, curMat); 252 transformCtr = MathUtils.transformPoint(transformCtr, curMat);
199 253
254// console.log( "modifyElements: rotateGlobally, ctr: " + transformCtr );
255
200 tMat[12] = transformCtr[0]; 256 tMat[12] = transformCtr[0];
201 tMat[13] = transformCtr[1]; 257 tMat[13] = transformCtr[1];
202 tMat[14] = transformCtr[2]; 258 tMat[14] = transformCtr[2];
@@ -265,6 +321,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
265 321
266 viewUtils.pushViewportObj( this.target ); 322 viewUtils.pushViewportObj( this.target );
267 var eltCtr = viewUtils.getCenterOfProjection(); 323 var eltCtr = viewUtils.getCenterOfProjection();
324 eltCtr[2] = 0;
268 viewUtils.popViewportObj(); 325 viewUtils.popViewportObj();
269 326
270 var ctrOffset = this.target.elementModel.props3D.m_transformCtr; 327 var ctrOffset = this.target.elementModel.props3D.m_transformCtr;
@@ -275,16 +332,18 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
275 } 332 }
276 333
277 this._origin = viewUtils.localToGlobal(eltCtr, this.target); 334 this._origin = viewUtils.localToGlobal(eltCtr, this.target);
335 //console.log( "Rotate3DToolBase.captureSelectionDrawn _origin: " + this._origin );
278 this._updateTargets(); 336 this._updateTargets();
279 this._setTransformOrigin(false); 337 this._setTransformOrigin(false);
280 } 338 }
281 else 339 else
282 { 340 {
283 this.target = this.application.ninja.currentDocument.documentRoot; 341 this.target = this.application.ninja.currentDocument.documentRoot;
284 this._origin = drawUtils._selectionCtr.slice(0); 342 //this._origin = drawUtils._selectionCtr.slice(0);
285 this._origin[0] += this.application.ninja.stage.userContentLeft; 343 //this._origin[0] += this.application.ninja.stage.userContentLeft;
286 this._origin[1] += this.application.ninja.stage.userContentTop; 344 //this._origin[1] += this.application.ninja.stage.userContentTop;
287 this._updateTargets(); 345 this._updateTargets();
346 this._origin = this.calculateMultiSelOrigin();
288 this._setTransformOrigin(true); 347 this._setTransformOrigin(true);
289 } 348 }
290 } 349 }
@@ -301,17 +360,35 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
301 } 360 }
302 }, 361 },
303 362
363 /*
364 _updateHandlesOrigin: {
365 value: function () { }
366 },
367 */
368
304 _updateTargets: { 369 _updateTargets: {
305 value: function(addToUndo) { 370 value: function(addToUndo) {
306 var mod3dObject = [], self = this; 371 var mod3dObject = [],
372 self = this;
307 373
308 this.application.ninja.selectedElements.forEach(function(element) { 374 this.application.ninja.selectedElements.forEach(function(element) {
309 viewUtils.pushViewportObj(element); 375 var curMat = viewUtils.getMatrixFromElement(element);
376 var curMatInv = glmat4.inverse(curMat, []);
377
378 viewUtils.pushViewportObj( element );
310 var eltCtr = viewUtils.getCenterOfProjection(); 379 var eltCtr = viewUtils.getCenterOfProjection();
311 viewUtils.popViewportObj(); 380 viewUtils.popViewportObj();
312 eltCtr = viewUtils.localToGlobal(eltCtr, element); 381
382 // cache the local to global and global to local matrices
383 var l2gMat = viewUtils.getLocalToGlobalMatrix( element );
384 var g2lMat = glmat4.inverse( l2gMat, [] );
385 eltCtr = MathUtils.transformAndDivideHomogeneousPoint( eltCtr, l2gMat );
313 386
314 element.elementModel.setProperty("ctr", eltCtr); 387 element.elementModel.setProperty("ctr", eltCtr);
388 element.elementModel.setProperty("mat", curMat);
389 element.elementModel.setProperty("matInv", curMatInv);
390 element.elementModel.setProperty("l2g", l2gMat);
391 element.elementModel.setProperty("g2l", g2lMat);
315 392
316 if(addToUndo) { 393 if(addToUndo) {
317 var previousMat = element.elementModel.getProperty("mat").slice(0); 394 var previousMat = element.elementModel.getProperty("mat").slice(0);
@@ -335,40 +412,84 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
335 } 412 }