diff options
author | Ananya Sen | 2012-04-17 18:11:55 -0700 |
---|---|---|
committer | Ananya Sen | 2012-04-17 18:11:55 -0700 |
commit | 35abad196cc9feb76ef50c1b63032a38233a6d51 (patch) | |
tree | 914689c66d4ab6c6e088b571eade0a0e35082916 /js/tools/TranslateObject3DTool.js | |
parent | 1f891c58bad0b7746659aa4138001b5ee76d9a0e (diff) | |
parent | 616a8532099fec2a15855eac97cd85cb60c4451c (diff) | |
download | ninja-35abad196cc9feb76ef50c1b63032a38233a6d51.tar.gz |
Merge branch 'refs/heads/ninja-internal-master' into Codeview-improvements
Diffstat (limited to 'js/tools/TranslateObject3DTool.js')
-rwxr-xr-x | js/tools/TranslateObject3DTool.js | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/js/tools/TranslateObject3DTool.js b/js/tools/TranslateObject3DTool.js index 60633e74..74df6c14 100755 --- a/js/tools/TranslateObject3DTool.js +++ b/js/tools/TranslateObject3DTool.js | |||
@@ -4,18 +4,28 @@ 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 | ||
7 | var Translate3DToolBase = require("js/tools/Translate3DToolBase").Translate3DToolBase, | 7 | var Montage = require("montage/core/core").Montage, |
8 | Translate3DToolBase = require("js/tools/Translate3DToolBase").Translate3DToolBase, | ||
8 | drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, | 9 | drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, |
10 | vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, | ||
9 | viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, | 11 | viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, |
10 | snapManager = require("js/helper-classes/3D/snap-manager").SnapManager; | 12 | snapManager = require("js/helper-classes/3D/snap-manager").SnapManager; |
11 | 13 | ||
12 | exports.TranslateObject3DTool = Object.create(Translate3DToolBase, { | 14 | exports.TranslateObject3DTool = Montage.create(Translate3DToolBase, { |
13 | _toolID: { value: "translateObject3DTool" }, | 15 | _toolID: { value: "translateObject3DTool" }, |
14 | _canOperateOnStage: { value: true }, | 16 | _canOperateOnStage: { value: true }, |
15 | 17 | ||
18 | _initializeToolHandles: { | ||
19 | value: function() { | ||
20 | this._inLocalMode = (this.options.selectedMode === "rotateLocally"); | ||
21 | } | ||
22 | }, | ||
23 | |||
16 | initializeSnapping : { | 24 | initializeSnapping : { |
17 | value : function(event) | 25 | value : function(event) |
18 | { | 26 | { |
27 | // console.log( "initializeSnapping" ); | ||
28 | |||
19 | this._mouseDownHitRec = null; | 29 | this._mouseDownHitRec = null; |
20 | this._mouseUpHitRec = null; | 30 | this._mouseUpHitRec = null; |
21 | 31 | ||
@@ -37,8 +47,6 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, { | |||
37 | 47 | ||
38 | if(this._handleMode === null) | 48 | if(this._handleMode === null) |
39 | { | 49 | { |
40 | // this.doSelection(event); | ||
41 | |||
42 | snapManager.enableElementSnap ( true ); | 50 | snapManager.enableElementSnap ( true ); |
43 | snapManager.enableGridSnap ( true ); | 51 | snapManager.enableGridSnap ( true ); |
44 | } | 52 | } |
@@ -57,10 +65,8 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, { | |||
57 | } | 65 | } |
58 | } | 66 | } |
59 | 67 | ||
60 | if(this._targets) | 68 | if(this.application.ninja.selectedElements.length) { |
61 | { | 69 | var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)); |
62 | var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, | ||
63 | new WebKitPoint(event.pageX, event.pageY)); | ||
64 | 70 | ||
65 | // do the snap before setting up the avoid list to allow | 71 | // do the snap before setting up the avoid list to allow |
66 | // a snap on the mouse down | 72 | // a snap on the mouse down |
@@ -88,11 +94,10 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, { | |||
88 | } | 94 | } |
89 | 95 | ||
90 | // we don't want to snap to selected objects during the drag | 96 | // we don't want to snap to selected objects during the drag |
91 | var len = this._targets.length; | 97 | this.application.ninja.selectedElements.forEach(function(element) { |
92 | for(var i=0; i<len; i++) | 98 | snapManager.addToAvoidList(element); |
93 | { | 99 | }); |
94 | snapManager.addToAvoidList( this._targets[i].elt ); | 100 | |
95 | } | ||
96 | if (hitRec) | 101 | if (hitRec) |
97 | { | 102 | { |
98 | // disable snap attributes | 103 | // disable snap attributes |
@@ -107,20 +112,14 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, { | |||
107 | } | 112 | } |
108 | 113 | ||
109 | if(this._handleMode === 2) | 114 | if(this._handleMode === 2) |
110 | { | ||
111 | // TODO - not sure how to parameterize point in z-translate mode | ||
112 | this.clickedObject = this._target; | 115 | this.clickedObject = this._target; |
113 | this._snapParam = [0, 0, 0]; | 116 | |
114 | } | 117 | // parameterize the snap point on the target |
115 | else | 118 | this._snapParam = this.parameterizeSnap( hitRec ); |
116 | { | ||
117 | // parameterize the snap point on the target | ||
118 | this._snapParam = this.parameterizeSnap( hitRec ); | ||
119 | } | ||
120 | 119 | ||
121 | if(!this._dragPlane) | 120 | if(!this._dragPlane) |
122 | { | 121 | { |
123 | if( this._inLocalMode && (this._targets.length === 1) ) | 122 | if( this._inLocalMode && (this.application.ninja.selectedElements.length === 1) ) |
124 | { | 123 | { |
125 | this._dragPlane = viewUtils.getUnprojectedElementPlane(this._clickedObject); | 124 | this._dragPlane = viewUtils.getUnprojectedElementPlane(this._clickedObject); |
126 | snapManager.setupDragPlaneFromPlane(this._dragPlane); | 125 | snapManager.setupDragPlaneFromPlane(this._dragPlane); |
@@ -132,6 +131,11 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, { | |||
132 | 131 | ||
133 | } | 132 | } |
134 | 133 | ||
134 | // only do quadrant snapping if the 4 corners of the element are in the drag plane | ||
135 | |||
136 | var sign = MathUtils.fpSign( vecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); | ||
137 | this._shouldUseQuadPt = (sign == 0); | ||
138 | |||
135 | var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); | 139 | var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); |
136 | this._mouseDownHitRec = wpHitRec; | 140 | this._mouseDownHitRec = wpHitRec; |
137 | this._mouseUpHitRec = null; | 141 | this._mouseUpHitRec = null; |