aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xjs/helper-classes/3D/hit-record.js13
-rwxr-xr-xjs/tools/Rotate3DToolBase.js38
-rwxr-xr-xjs/tools/RotateObject3DTool.js141
-rwxr-xr-xjs/tools/modifier-tool-base.js1
4 files changed, 189 insertions, 4 deletions
diff --git a/js/helper-classes/3D/hit-record.js b/js/helper-classes/3D/hit-record.js
index 96f87c24..6094dae1 100755
--- a/js/helper-classes/3D/hit-record.js
+++ b/js/helper-classes/3D/hit-record.js
@@ -320,13 +320,22 @@ var HitRecord = exports.HitRecord = Object.create(Object.prototype,
320 var globalToLocal = glmat4.inverse( localToGlobal, [] ); 320 var globalToLocal = glmat4.inverse( localToGlobal, [] );
321 var test3 = MathUtils.transformAndDivideHomogeneousPoint( globalPt, globalToLocal ); 321 var test3 = MathUtils.transformAndDivideHomogeneousPoint( globalPt, globalToLocal );
322 dist = vecUtils.vecDist(3, test3, localPt); 322 dist = vecUtils.vecDist(3, test3, localPt);
323 if (MathUtils.fpSign( vecUtils.vecDist(3, test3, localPt)) != 0) 323 if (MathUtils.fpSign(dist) != 0)
324 { 324 {
325 err = true; 325 err = true;
326 console.log( "**** transform error 3 ***** " + dist + ", localPt: " + localPt ); 326 console.log( "**** transform error 3 ***** " + dist + ", localPt: " + localPt );
327 } 327 }
328 328
329 if (!err) console.log( "no hitRecord error" ); 329 var objToStageWorld = viewUtils.getObjToStageWorldMatrix( elt, true );
330 var test4 = MathUtils.transformAndDivideHomogeneousPoint( localPt, objToStageWorld );
331 dist = vecUtils.vecDist(3, test4, stageWorldPt);
332 if (MathUtils.fpSign(dist) != 0)
333 {
334 err = true;
335 console.log( "**** transform error 4 ***** " + dist + ", localPt: " + localPt );
336 }
337
338 //if (!err) console.log( "no hitRecord error" );
330 } 339 }
331 } 340 }
332}); 341});
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 {
diff --git a/js/tools/RotateObject3DTool.js b/js/tools/RotateObject3DTool.js
index 72af6eff..7b4ec083 100755
--- a/js/tools/RotateObject3DTool.js
+++ b/js/tools/RotateObject3DTool.js
@@ -4,7 +4,9 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */ 5</copyright> */
6 6
7var Montage = require("montage/core/core").Montage; 7var Montage = require("montage/core/core").Montage,
8 viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils,
9 snapManager = require("js/helper-classes/3D/snap-manager").SnapManager;
8 10
9var Rotate3DToolBase = require("js/tools/Rotate3DToolBase").Rotate3DToolBase; 11var Rotate3DToolBase = require("js/tools/Rotate3DToolBase").Rotate3DToolBase;
10var toolHandleModule = require("js/stage/tool-handle"); 12var toolHandleModule = require("js/stage/tool-handle");
@@ -54,6 +56,143 @@ exports.RotateObject3DTool = Montage.create(Rotate3DToolBase, {
54 } 56 }
55 }, 57 },
56 58
59 initializeSnapping : {
60 value : function(event)
61 {
62 console.log( "initializeSnapping" );
63
64 this._mouseDownHitRec = null;
65 this._mouseUpHitRec = null;
66
67 snapManager.clearAvoidList();
68 snapManager.clearDragPlane();
69
70 // the translate tool does snap align to the bounds of the object only.
71 // turn off snap align to the cursor. This needs to be re-enabled in the mouse up method
72 snapManager.enableSnapAlign( false );
73
74 // snap to element and snap to grid are conditionally enabled based
75 // on the snap results of the mouse down. enable everything for the first snap
76 this._snapToElements = snapManager.elementSnapEnabledAppLevel();
77 this._snapToGrid = snapManager.gridSnapEnabledAppLevel();
78
79 this._dragPlane = null;
80 this._clickedOnStage = false;
81 var do3DSnap = true;
82
83 if(this._handleMode === null)
84 {
85 snapManager.enableElementSnap ( true );
86 snapManager.enableGridSnap ( true );
87 }
88// else
89// {
90// this._delta = null;
91 // special case for z-translation
92// if(this._handleMode === 0)
93// {
94// this._dragPlane = viewUtils.getNormalToUnprojectedElementPlane(this._target);