aboutsummaryrefslogtreecommitdiff
path: root/js/tools/Translate3DToolBase.js
diff options
context:
space:
mode:
authorPushkar Joshi2012-04-17 14:49:18 -0700
committerPushkar Joshi2012-04-17 14:49:18 -0700
commitdf903a01e14134cadf109b733d09c6eadfa3966b (patch)
tree2351f1c05b2f852053fa0be533072088a9ad4e7c /js/tools/Translate3DToolBase.js
parent036cf034e124dbc1f4893e90f7c6d240904a3faf (diff)
parentcacb4a21825818af392c2949967b0f3c1df509c5 (diff)
downloadninja-df903a01e14134cadf109b733d09c6eadfa3966b.tar.gz
Merge branch 'master' into pentool
Conflicts: js/tools/PenTool.js
Diffstat (limited to 'js/tools/Translate3DToolBase.js')
-rwxr-xr-xjs/tools/Translate3DToolBase.js180
1 files changed, 74 insertions, 106 deletions
diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js
index 4dca6313..04359567 100755
--- a/js/tools/Translate3DToolBase.js
+++ b/js/tools/Translate3DToolBase.js
@@ -21,14 +21,15 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
21 _clickedOnStage: { value: false }, 21 _clickedOnStage: { value: false },
22 22
23 HandleDoubleClick : { 23 HandleDoubleClick : {
24 value : function() 24 value : function() {
25 {
26 } 25 }
27 }, 26 },
28 27
29 modifyElements : { 28 modifyElements : {
30 value : function(data, event) 29 value : function(data, event)
31 { 30 {
31 //console.log( "modifyElements, data: " + data.pt0 + " => " + data.pt1 );
32
32 // form the translation vector and post translate the matrix by it. 33 // form the translation vector and post translate the matrix by it.
33 var delta = vecUtils.vecSubtract( 3, data.pt1, data.pt0 ); 34 var delta = vecUtils.vecSubtract( 3, data.pt1, data.pt0 );
34 if(this._handleMode !== null) 35 if(this._handleMode !== null)
@@ -66,16 +67,13 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
66 delta[0] = 0; 67 delta[0] = 0;
67 delta[1] = 0; 68 delta[1] = 0;
68 } 69 }
69 else
70 {
71 delta[2] = 0;
72 }
73 this._delta = delta.slice(0); 70 this._delta = delta.slice(0);
74 } 71 }
75 72
76 var transMat = Matrix.Translation( delta ); 73 var transMat = Matrix.Translation( delta );
77 74
78 if(this._inLocalMode && (this._targets.length === 1) ) 75 //console.log( "Translate: " + delta );
76 if(this._inLocalMode && (this.application.ninja.selectedElements.length === 1) )
79 { 77 {
80 this._translateLocally(transMat); 78 this._translateLocally(transMat);
81 } 79 }
@@ -87,53 +85,45 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
87 }, 85 },
88 86
89 87
90 Reset : { 88 Reset: {
91 value : function() 89 value: function() {
92 { 90 var mat, iMat, dist, mod3dObject = [], self = this;
93 var item, 91
94 elt, 92 this.application.ninja.selectedElements.forEach(function(element) {
95 mat, 93 // Reset to the identity matrix
96 dist, 94 //item = this.application.ninja.selectedElements[i];
97 newStyles = [], 95 iMat = Matrix.I(4);
98 previousStyles = [], 96 mat = ElementsMediator.getMatrix(element);
99 len = this._targets.length;
100 for(var i = 0; i < len; i++)
101 {
102 // Reset to the identity matrix but retain the rotation values
103 item = this._targets[i];
104 mat = item.mat.slice(0);
105 mat[12] = 0; 97 mat[12] = 0;
106 mat[13] = 0; 98 mat[13] = 0;
107 mat[14] = 0; 99 mat[14] = 0;
108 100
109 dist = this._undoArray[i].dist; 101 dist = ElementsMediator.getPerspectiveDist(element);
110
111 var previousStyleStr = {dist:dist, mat:item.mat};
112 102
113 var newStyleStr = {dist:dist, mat:mat}; 103 var previousStyleStr = {dist:dist, mat:element.elementModel.getProperty("mat")};
104 var newStyleStr = {dist:dist, mat:iMat};
114 105
115 previousStyles.push(previousStyleStr); 106 mod3dObject.push({element:element, properties:newStyleStr, previousProperties: previousStyleStr});
116 newStyles.push(newStyleStr); 107 });
117 }
118 108
119 ElementsMediator.set3DProperties(this.application.ninja.selectedElements, 109 ElementsMediator.set3DProperties(mod3dObject, "Change", "rotateTool");
120 newStyles,
121 "Change",
122 "translateTool",
123 previousStyles
124 );
125 110
126 this.isDrawing = false; 111 this.isDrawing = false;
127 this.endDraw(event); 112 this.endDraw(event);
128 113
129// this.UpdateSelection(true); 114 // Need to force stage to draw immediately so the new selection center is calculated
130 this.Configure(true); 115 this.application.ninja.stage.draw();
116 // And captureSelectionDrawn to draw the transform handles
117 this.captureSelectionDrawn(null);
131 } 118 }
132 }, 119 },
133 120
134 // We will only translate single elements locally 121 // We will only translate single elements locally
135 _translateLocally: { 122 _translateLocally: {
136 value: function (transMat) { 123 value: function (transMat) {
124 //console.log( "_translateLocally, startMat: " + this._startMat );
125 //console.log( "_translateLocally, transMat: " + transMat );
126 //console.log( "_translateLocally, startMat: " + this._startMat + ", transMat: " + transMat );
137 var mat = glmat4.multiply(this._startMat, transMat, []); 127 var mat = glmat4.multiply(this._startMat, transMat, []);
138 viewUtils.setMatrixForElement( this._target, mat, true ); 128 viewUtils.setMatrixForElement( this._target, mat, true );
139 if(this._mode !== 1) 129 if(this._mode !== 1)
@@ -145,103 +135,81 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
145 135
146 _translateGlobally: { 136 _translateGlobally: {
147 value: function (transMat) { 137 value: function (transMat) {
148 var len = this._targets.length, 138 //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat );
149 i = 0, 139 //console.log( "_translateGlobally, transMat: " + transMat );
150 item, 140 var self = this,
151 elt, 141 curMat = viewUtils.getMatrixFromElement( this._target ),
152 curMat,
153 matInv = glmat4.inverse(this._startMat, []), 142 matInv = glmat4.inverse(this._startMat, []),
154 nMat = glmat4.multiply(transMat, this._startMat, [] ), 143 nMat = glmat4.multiply(transMat, this._startMat, [] );
155 qMat = glmat4.multiply(matInv, nMat, []); 144// qMat = glmat4.multiply(matInv, nMat, []);
145
146 if(this._mode === 1) {
147 var curInv = glmat4.inverse( curMat, [] );
148 transMat = glmat4.multiply( nMat, curInv, [] );
149 }
156 150
157 var shouldUpdateStartMat = true; 151 var shouldUpdateStartMat = true;
158 152
159 if(this._clickedOnStage) 153 if(this._clickedOnStage) {
160 {
161 shouldUpdateStartMat = false; 154 shouldUpdateStartMat = false;
162 } 155 } else if(this._mode !== 1) {
163 else if(this._mode !== 1)
164 {
165 this._startMat = nMat; 156 this._startMat = nMat;
166 } 157 }
167 158
168 for(i = 0; i < len; i++) 159 this.application.ninja.selectedElements.forEach(function(element) {
169 { 160 curMat = element.elementModel.getProperty("mat").slice(0);
170 item = this._targets[i];
171 elt = item.elt;
172 curMat = item.mat.slice(0);
173 161
174// glmat4.multiply(curMat, qMat, curMat); 162// glmat4.multiply(curMat, qMat, curMat);
175// 163// viewUtils.setMatrixForElement( elt, curMat, true);
176// viewUtils.setMatrixForElement( elt, curMat, true);
177 curMat[12] += transMat[12]; 164 curMat[12] += transMat[12];
178 curMat[13] += transMat[13]; 165 curMat[13] += transMat[13];
179 curMat[14] += transMat[14]; 166 curMat[14] += transMat[14];
180 viewUtils.setMatrixForElement( elt, curMat, true);
181 167
182 if(shouldUpdateStartMat) 168 viewUtils.setMatrixForElement(element, curMat, true);
183 { 169
184 this._targets[i].mat = curMat; 170 if(shouldUpdateStartMat) {
185 } 171 //console.log( "\t\tshouldUpdateStartMat" );
186 } 172 element.elementModel.setProperty("mat", curMat);
173 }
174
175 });
187 } 176 }
188 }, 177 },
189 178
190 _updateTargets: { 179 _updateTargets: {
191 value: function(addToUndoStack) { 180 value: function(addToUndo) {
192 var newStyles = [], 181 var mod3dObject = [], self = this;
193 previousStyles = [],
194 len = this.application.ninja.selectedElements.length;
195 this._targets = [];
196 for(var i = 0; i < len; i++)
197 {
198 var elt = this.application.ninja.selectedElements[i];
199 182
200 var curMat = viewUtils.getMatrixFromElement(elt); 183 this.application.ninja.selectedElements.forEach(function(element) {
201 var curMatInv = glmat4.inverse(curMat, []); 184 if(addToUndo) {
185 var previousMat = element.elementModel.getProperty("mat").slice(0);
186 var previousStyleStr = {dist:element.elementModel.getProperty("dist"), mat:MathUtils.scientificToDecimal(previousMat, 5)};
187 var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(element), mat:MathUtils.scientificToDecimal(viewUtils.getMatrixFromElement(element), 5)};
202 188
203 this._targets.push({elt:elt, mat:curMat, matInv:curMatInv}); 189 mod3dObject.push({element:element, properties:newStyleStr, previousProperties: previousStyleStr});
204