aboutsummaryrefslogtreecommitdiff
path: root/js/tools/Translate3DToolBase.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/Translate3DToolBase.js')
-rwxr-xr-xjs/tools/Translate3DToolBase.js143
1 files changed, 105 insertions, 38 deletions
diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js
index 24a68ad1..e4f1fb99 100755
--- a/js/tools/Translate3DToolBase.js
+++ b/js/tools/Translate3DToolBase.js
@@ -18,6 +18,7 @@ var Montage = require("montage/core/core").Montage,
18exports.Translate3DToolBase = Montage.create(ModifierToolBase, 18exports.Translate3DToolBase = Montage.create(ModifierToolBase,
19{ 19{
20 _inLocalMode: { value: true, enumerable: true }, 20 _inLocalMode: { value: true, enumerable: true },
21 _clickedOnStage: { value: false },
21 22
22 HandleDoubleClick : { 23 HandleDoubleClick : {
23 value : function() 24 value : function()
@@ -28,6 +29,8 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
28 modifyElements : { 29 modifyElements : {
29 value : function(data, event) 30 value : function(data, event)
30 { 31 {
32 //console.log( "modifyElements, data: " + data.pt0 + " => " + data.pt1 );
33
31 // form the translation vector and post translate the matrix by it. 34 // form the translation vector and post translate the matrix by it.
32 var delta = vecUtils.vecSubtract( 3, data.pt1, data.pt0 ); 35 var delta = vecUtils.vecSubtract( 3, data.pt1, data.pt0 );
33 if(this._handleMode !== null) 36 if(this._handleMode !== null)
@@ -47,17 +50,30 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
47 delta[1] = 0; 50 delta[1] = 0;
48 break; 51 break;
49 } 52 }
53 if( (this.application.ninja.selectedElements.length > 1) && this._clickedOnStage )
54 {
55 this._delta = ~~(delta[this._handleMode]);
56 }
57 else
58 {
59 this._delta += ~~(delta[this._handleMode]);
60 }
50 61
51 this._updateDelta(delta, this._handleMode);
52 } 62 }
53 else if(this._mode === 1) 63 else
54 { 64 {
55 delta[2] = delta[1]; 65 if(this._mode === 1)
56 delta[0] = 0; 66 {
57 delta[1] = 0; 67 delta[2] = delta[1];
68 delta[0] = 0;
69 delta[1] = 0;
70 }
71 this._delta = delta.slice(0);
58 } 72 }
59 73
60 var transMat = Matrix.Translation( delta ); 74 var transMat = Matrix.Translation( delta );
75
76 //console.log( "Translate: " + delta );
61 if(this._inLocalMode && (this._targets.length === 1) ) 77 if(this._inLocalMode && (this._targets.length === 1) )
62 { 78 {
63 this._translateLocally(transMat); 79 this._translateLocally(transMat);
@@ -74,22 +90,21 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
74 value : function() 90 value : function()
75 { 91 {
76 var item, 92 var item,
77 elt,
78 mat, 93 mat,
79 dist, 94 dist,
80 newStyles = [], 95 newStyles = [],
81 previousStyles = [], 96 previousStyles = [],
82 len = this._targets.length; 97 len = this.application.ninja.selectedElements.length;
83 for(var i = 0; i < len; i++) 98 for(var i = 0; i < len; i++)
84 { 99 {
85 // Reset to the identity matrix but retain the rotation values 100 // Reset to the identity matrix but retain the rotation values
86 item = this._targets[i]; 101 item = this.application.ninja.selectedElements[i];
87 mat = item.mat.slice(0); 102 mat = ElementsMediator.getMatrix(item);
88 mat[12] = 0; 103 mat[12] = 0;
89 mat[13] = 0; 104 mat[13] = 0;
90 mat[14] = 0; 105 mat[14] = 0;
91 106
92 dist = this._undoArray[i].dist; 107 dist = ElementsMediator.getPerspectiveDist(item);
93 108
94 var previousStyleStr = {dist:dist, mat:item.mat}; 109 var previousStyleStr = {dist:dist, mat:item.mat};
95 110
@@ -109,14 +124,20 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
109 this.isDrawing = false; 124 this.isDrawing = false;
110 this.endDraw(event); 125 this.endDraw(event);
111 126
112// this.UpdateSelection(true); 127
113 this.Configure(true); 128 // Need to force stage to draw immediately so the new selection center is calculated
129 this.application.ninja.stage.draw();
130 // And captureSelectionDrawn to draw the transform handles
131 this.captureSelectionDrawn(null);
114 } 132 }
115 }, 133 },
116 134
117 // We will only translate single elements locally 135 // We will only translate single elements locally
118 _translateLocally: { 136 _translateLocally: {
119 value: function (transMat) { 137 value: function (transMat) {
138 //console.log( "_translateLocally, startMat: " + this._startMat );
139 //console.log( "_translateLocally, transMat: " + transMat );
140 //console.log( "_translateLocally, startMat: " + this._startMat + ", transMat: " + transMat );
120 var mat = glmat4.multiply(this._startMat, transMat, []); 141 var mat = glmat4.multiply(this._startMat, transMat, []);
121 viewUtils.setMatrixForElement( this._target, mat, true ); 142 viewUtils.setMatrixForElement( this._target, mat, true );
122 if(this._mode !== 1) 143 if(this._mode !== 1)
@@ -128,18 +149,26 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
128 149
129 _translateGlobally: { 150 _translateGlobally: {
130 value: function (transMat) { 151 value: function (transMat) {
152 //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat );
153 //console.log( "_translateGlobally, transMat: " + transMat );
131 var len = this._targets.length, 154 var len = this._targets.length,
132 i = 0, 155 i = 0,
133 item, 156 item,
134 elt, 157 elt,
135 curMat, 158 curMat = viewUtils.getMatrixFromElement( this._target ),
136 matInv = glmat4.inverse(this._startMat, []), 159 matInv = glmat4.inverse(this._startMat, []),
137 nMat = glmat4.multiply(transMat, this._startMat, [] ), 160 nMat = glmat4.multiply(transMat, this._startMat, [] ),
138 qMat = glmat4.multiply(matInv, nMat, []); 161 qMat = glmat4.multiply(matInv, nMat, []);
162
163 if (this._mode === 1)
164 {
165 var curInv = glmat4.inverse( curMat, [] );
166 transMat = glmat4.multiply( nMat, curInv, [] );
167 }
139 168
140 var shouldUpdateStartMat = true; 169 var shouldUpdateStartMat = true;
141 170
142 if(this._clickedObject === this.application.ninja.currentDocument.documentRoot) 171 if(this._clickedOnStage)
143 { 172 {
144 shouldUpdateStartMat = false; 173 shouldUpdateStartMat = false;
145 } 174 }
@@ -152,14 +181,19 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
152 { 181 {
153 item = this._targets[i]; 182 item = this._targets[i];
154 elt = item.elt; 183 elt = item.elt;
155 curMat = item.mat; 184 curMat = item.mat.slice(0);
156
157 glmat4.multiply(curMat, qMat, curMat);
158 185
159 viewUtils.setMatrixForElement( elt, curMat, true); 186// glmat4.multiply(curMat, qMat, curMat);
187//
188// viewUtils.setMatrixForElement( elt, curMat, true);
189 curMat[12] += transMat[12];
190 curMat[13] += transMat[13];
191 curMat[14] += transMat[14];
192 viewUtils.setMatrixForElement( elt, curMat, true);
160 193
161 if(shouldUpdateStartMat) 194 if(shouldUpdateStartMat)
162 { 195 {
196 //console.log( "\t\tshouldUpdateStartMat" );
163 this._targets[i].mat = curMat; 197 this._targets[i].mat = curMat;
164 } 198 }
165 } 199 }
@@ -168,13 +202,14 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
168 202
169 _updateTargets: { 203 _updateTargets: {
170 value: function(addToUndoStack) { 204 value: function(addToUndoStack) {
205// console.log( "_updateTargets" );
171 var newStyles = [], 206 var newStyles = [],
172 previousStyles = [], 207 previousStyles = [],
173 len = this.application.ninja.selectedElements.length; 208 len = this.application.ninja.selectedElements.length;
174 this._targets = []; 209 this._targets = [];
175 for(var i = 0; i < len; i++) 210 for(var i = 0; i < len; i++)
176 { 211 {
177 var elt = this.application.ninja.selectedElements[i]._element; 212 var elt = this.application.ninja.selectedElements[i];
178 213
179 var curMat = viewUtils.getMatrixFromElement(elt); 214 var curMat = viewUtils.getMatrixFromElement(elt);
180 var curMatInv = glmat4.inverse(curMat, []); 215 var curMatInv = glmat4.inverse(curMat, []);
@@ -198,6 +233,19 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
198 "translateTool", 233 "translateTool",
199 previousStyles 234 previousStyles
200 ); 235 );
236 if(this._origin && this._delta)
237 {
238 if(this._handleMode !== null)
239 {
240 this._origin[this._handleMode] += this._delta;
241 }
242 else
243 {
244 this._origin[0] += this._delta[0];