aboutsummaryrefslogtreecommitdiff
path: root/js/tools/Rotate3DToolBase.js
diff options
context:
space:
mode:
authorhwc4872012-04-11 16:01:33 -0700
committerhwc4872012-04-11 16:01:33 -0700
commitf522ce09d98bbb2812ed25bb942597d854d71a1c (patch)
treea186dce4bdd589ba6dd102b758f1670a3e1e61ba /js/tools/Rotate3DToolBase.js
parent2d21b01d6dd64af643f5f38818b57fcace05ea0b (diff)
downloadninja-f522ce09d98bbb2812ed25bb942597d854d71a1c.tar.gz
Rotate3D tool changes
Diffstat (limited to 'js/tools/Rotate3DToolBase.js')
-rwxr-xr-xjs/tools/Rotate3DToolBase.js38
1 files changed, 37 insertions, 1 deletions
diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js
index eb2cdba4..e0c5abcb 100755
--- a/js/tools/Rotate3DToolBase.js
+++ b/js/tools/Rotate3DToolBase.js
@@ -56,17 +56,23 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
56 // move the transform origin handle 56 // move the transform origin handle
57 var dx = pt1.x - pt0.x; 57 var dx = pt1.x - pt0.x;
58 var dy = pt1.y - pt0.y; 58 var dy = pt1.y - pt0.y;
59 var dz = pt1.z - pt0.z;
60
59 this._origin[0] += dx; 61 this._origin[0] += dx;
60 this._origin[1] += dy; 62 this._origin[1] += dy;
63 this._origin[2] += dz;
61 64
62 var len = this._targets.length; 65 var len = this._targets.length;
63 if(len === 1) 66 if(len === 1)
64 { 67 {
65 this._startOriginArray[0][0] += dx; 68 this._startOriginArray[0][0] += dx;
66 this._startOriginArray[0][1] += dy; 69 this._startOriginArray[0][1] += dy;
70 this._startOriginArray[0][2] += dz;
71 console.log( "Rotate3DToolBase.modifyElements, _startOriginArray[0]: " + this._startOriginArray[0] );
67 } 72 }
68 this.downPoint.x = pt1.x; 73 this.downPoint.x = pt1.x;
69 this.downPoint.y = pt1.y; 74 this.downPoint.y = pt1.y;
75 this.downPoint.z = pt1.z;
70 this.DrawHandles(); 76 this.DrawHandles();
71 return; 77 return;
72 } 78 }
@@ -159,8 +165,23 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
159 // pre-translate by the transformation center 165 // pre-translate by the transformation center
160 var tMat = Matrix.I(4); 166 var tMat = Matrix.I(4);
161 167
168 // _startOriginArray is the location of the center of rotation
169 // in view space of the element. It is currently calculated during the drag
170 // using delta's in global screen space, hence wrong.
171 // We can put the transformCenter back in element view space here, however
172 // it would be (much) more efficient to cache the localToGlobal and
173 // globalToLocal matrices.
162 var transformCtr = this._startOriginArray[i]; 174 var transformCtr = this._startOriginArray[i];
163 175
176 var localToGlobalMat = viewUtils.getLocalToGlobalMatrix( elt );
177 var globalToLocalMat = glmat4.inverse( localToGlobalMat, [] );
178 var newTransformCtr = MathUtils.transformAndDivideHomogeneousPoint( this._origin, globalToLocalMat );
179 viewUtils.pushViewportObj( elt );
180 newTransformCtr = viewUtils.screenToView( newTransformCtr[0], newTransformCtr[1], newTransformCtr[2] );
181 viewUtils.popViewportObj( elt );
182 //console.log( "transformCtr: " + newTransformCtr );
183 transformCtr = newTransformCtr;
184
164 tMat[12] = transformCtr[0]; 185 tMat[12] = transformCtr[0];
165 tMat[13] = transformCtr[1]; 186 tMat[13] = transformCtr[1];
166 tMat[14] = transformCtr[2]; 187 tMat[14] = transformCtr[2];
@@ -267,6 +288,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
267 288
268 viewUtils.pushViewportObj( this.target ); 289 viewUtils.pushViewportObj( this.target );
269 var eltCtr = viewUtils.getCenterOfProjection(); 290 var eltCtr = viewUtils.getCenterOfProjection();
291 eltCtr[2] = 0;
270 viewUtils.popViewportObj(); 292 viewUtils.popViewportObj();
271 293
272 var ctrOffset = this.target.elementModel.props3D.m_transformCtr; 294 var ctrOffset = this.target.elementModel.props3D.m_transformCtr;
@@ -277,6 +299,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
277 } 299 }
278 300
279 this._origin = viewUtils.localToGlobal(eltCtr, this.target); 301 this._origin = viewUtils.localToGlobal(eltCtr, this.target);
302 console.log( "Rotate3DToolBase.captureSelectionDrawn _origin: " + this._origin );
280 this._updateTargets(); 303 this._updateTargets();
281 this._setTransformOrigin(false); 304 this._setTransformOrigin(false);
282 } 305 }
@@ -533,6 +556,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
533 */ 556 */
534 _showFeedbackOnMouseMove : { 557 _showFeedbackOnMouseMove : {
535 value: function (event) { 558 value: function (event) {
559 this._canSnap = false;
536 if(this._target && this._handles) 560 if(this._target && this._handles)
537 { 561 {
538 var len = this._handles.length; 562 var len = this._handles.length;
@@ -550,7 +574,8 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
550 this.application.ninja.stage.drawingCanvas.style.cursor = "move"; 574 this.application.ninja.stage.drawingCanvas.style.cursor = "move";
551 this._handleMode = i; 575 this._handleMode = i;
552 this._activateOriginHandle = true; 576 this._activateOriginHandle = true;
553 return; 577 this._canSnap = true;
578 return;
554 } 579 }
555 else if(c === 2) 580 else if(c === 2)
556 { 581 {
@@ -569,6 +594,16 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
569 } 594 }
570 }, 595 },
571 596
597 getMousePoints: {
598 value: function()
599 {
600 var pt0 = { x:this.downPoint.x, y:this.downPoint.y, z:this.downPoint.z };
601 var pt1 = { x:this.upPoint.x, y:this.upPoint.y, z:this.upPoint.z };
602
603 return {pt0:pt0, pt1:pt1};
604 }
605 },
606
572 DrawHandles: { 607 DrawHandles: {
573 value: function (angle) { 608 value: function (angle) {
574 this.application.ninja.stage.clearDrawingCanvas(); 609 this.application.ninja.stage.clearDrawingCanvas();
@@ -594,6 +629,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
594 viewUtils.pushViewportObj( this.application.ninja.currentDocument.documentRoot ); 629 viewUtils.pushViewportObj( this.application.ninja.currentDocument.documentRoot );
595 } 630 }
596 var base = this._origin; 631 var base = this._origin;
632 //console.log( "Rotate3DToolBase.DrawHandles, base: " + base );
597 633
598 if( (this._handleMode !== null) && !this._activateOriginHandle ) 634 if( (this._handleMode !== null) && !this._activateOriginHandle )
599 { 635 {