aboutsummaryrefslogtreecommitdiff
path: root/js/tools/Translate3DToolBase.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/Translate3DToolBase.js')
-rwxr-xr-xjs/tools/Translate3DToolBase.js453
1 files changed, 227 insertions, 226 deletions
diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js
index 00408b6e..57a379e4 100755
--- a/js/tools/Translate3DToolBase.js
+++ b/js/tools/Translate3DToolBase.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -41,16 +42,16 @@ var Montage = require("montage/core/core").Montage,
41 42
42exports.Translate3DToolBase = Montage.create(ModifierToolBase, 43exports.Translate3DToolBase = Montage.create(ModifierToolBase,
43{ 44{
44 _inLocalMode: { value: true, enumerable: true }, 45 _inLocalMode: { value: true, enumerable: true },
45 _clickedOnStage: { value: false }, 46 _clickedOnStage: { value: false },
46 47
47 HandleDoubleClick : { 48 HandleDoubleClick : {
48 value : function() { 49 value : function() {
49 } 50 }
50 }, 51 },
51 52
52 modifyElements : { 53 modifyElements : {
53 value : function(data, event) 54 value : function(data, event)
54 { 55 {
55 //console.log( "modifyElements, data: " + data.pt0 + " => " + data.pt1 ); 56 //console.log( "modifyElements, data: " + data.pt0 + " => " + data.pt1 );
56 57
@@ -94,7 +95,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
94 this._delta = delta.slice(0); 95 this._delta = delta.slice(0);
95 } 96 }
96 97
97 //console.log( "modifyElements delta: " + delta ); 98 //console.log( "modifyElements delta: " + delta );
98 var transMat = Matrix.Translation( delta ); 99 var transMat = Matrix.Translation( delta );
99 100
100 //console.log( "Translate: " + delta ); 101 //console.log( "Translate: " + delta );
@@ -107,11 +108,11 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
107 this._translateGlobally(transMat); 108 this._translateGlobally(transMat);
108 } 109 }
109 } 110 }
110 }, 111 },
111 112
112 113
113 Reset: { 114 Reset: {
114 value: function() { 115 value: function() {
115 var mat, iMat, dist, mod3dObject = [], self = this; 116 var mat, iMat, dist, mod3dObject = [], self = this;
116 117
117 this.application.ninja.selectedElements.forEach(function(element) { 118 this.application.ninja.selectedElements.forEach(function(element) {
@@ -133,60 +134,60 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
133 134
134 ElementsMediator.set3DProperties(mod3dObject, "Change", "rotateTool"); 135 ElementsMediator.set3DProperties(mod3dObject, "Change", "rotateTool");
135 136
136 this.isDrawing = false; 137 this.isDrawing = false;
137 this.endDraw(event); 138 this.endDraw(event);
138 139
139 // Need to force stage to draw immediately so the new selection center is calculated 140 // Need to force stage to draw immediately so the new selection center is calculated
140 this.application.ninja.stage.draw(); 141 this.application.ninja.stage.draw();
141 // And captureSelectionDrawn to draw the transform handles 142 // And captureSelectionDrawn to draw the transform handles
142 this.captureSelectionDrawn(null); 143 this.captureSelectionDrawn(null);
143 } 144 }
144 }, 145 },
145 146
146 // We will only translate single elements locally 147 // We will only translate single elements locally
147 _translateLocally: { 148 _translateLocally: {
148 value: function (transMat) { 149 value: function (transMat) {
149 //console.log( "_translateLocally, startMat: " + this._startMat ); 150 //console.log( "_translateLocally, startMat: " + this._startMat );
150 //console.log( "_translateLocally, transMat: " + transMat ); 151 //console.log( "_translateLocally, transMat: " + transMat );
151 //console.log( "_translateLocally, startMat: " + this._startMat + ", transMat: " + transMat ); 152 //console.log( "_translateLocally, startMat: " + this._startMat + ", transMat: " + transMat );
152 var mat = glmat4.multiply(this._startMat, transMat, []); 153 var mat = glmat4.multiply(this._startMat, transMat, []);
153 viewUtils.setMatrixForElement( this._target, mat, true ); 154 viewUtils.setMatrixForElement( this._target, mat, true );
154 if(this._mode !== 1) 155 if(this._mode !== 1)
155 { 156 {
156 this._startMat = mat; 157 this._startMat = mat;
157 } 158 }
158 } 159 }
159 }, 160 },
160 161
161 _translateGlobally: { 162 _translateGlobally: {
162 value: function (transMat) { 163 value: function (transMat) {
163 //console.log( "_translateGlobally, transMat: " + transMat ); 164 //console.log( "_translateGlobally, transMat: " + transMat );
164 var selectedElements = this.application.ninja.selectedElements; 165 var selectedElements = this.application.ninja.selectedElements;
165 166
166 var len = selectedElements.length, 167 var len = selectedElements.length,
167 self = this, 168 self = this,
168 target = selectedElements[0], 169 target = selectedElements[0],
169 curMat = viewUtils.getMatrixFromElement( target ), 170 curMat = viewUtils.getMatrixFromElement( target ),
170 matInv = glmat4.inverse(this._startMat, []), 171 matInv = glmat4.inverse(this._startMat, []),
171 nMat = glmat4.multiply(transMat, this._startMat, [] ); 172 nMat = glmat4.multiply(transMat, this._startMat, [] );
172// qMat = glmat4.multiply(matInv, nMat, []); 173// qMat = glmat4.multiply(matInv, nMat, []);
173 174
174 if(this._mode === 1) { 175 if(this._mode === 1) {
175 if (len > 1) curMat = target.elementModel.getProperty("mat").slice(); 176 if (len > 1) curMat = target.elementModel.getProperty("mat").slice();
176 var curInv = glmat4.inverse( curMat, [] ); 177 var curInv = glmat4.inverse( curMat, [] );
177 transMat = glmat4.multiply( nMat, curInv, [] ); 178 transMat = glmat4.multiply( nMat, curInv, [] );
178 } 179 }
179 180
180 var shouldUpdateStartMat = true; 181 var shouldUpdateStartMat = true;
181 182
182 if(this._clickedOnStage || ((this._handleMode === 2) && (len > 1))) 183 if(this._clickedOnStage || ((this._handleMode === 2) && (len > 1)))
183 { 184 {
184 shouldUpdateStartMat = false; 185 shouldUpdateStartMat = false;
185 } 186 }
186 else if(this._mode !== 1) 187 else if(this._mode !== 1)
187 { 188 {
188 this._startMat = nMat; 189 this._startMat = nMat;
189 } 190 }
190 191
191 selectedElements.forEach(function(element) { 192 selectedElements.forEach(function(element) {
192 curMat = element.elementModel.getProperty("mat").slice(0); 193 curMat = element.elementModel.getProperty("mat").slice(0);
@@ -205,11 +206,11 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
205 } 206 }
206 207
207 }); 208 });
208 } 209 }
209 }, 210 },
210 211
211 _updateTargets: { 212 _updateTargets: {
212 value: function(addToUndo) { 213 value: function(addToUndo) {
213 var mod3dObject = [], self = this; 214 var mod3dObject = [], self = this;
214 215
215 this.application.ninja.selectedElements.forEach(function(element) { 216 this.application.ninja.selectedElements.forEach(function(element) {
@@ -223,7 +224,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
223 } 224 }
224 }); 225 });
225 226
226 if(addToUndo) { 227 if(addToUndo) {
227 ElementsMediator.set3DProperties(mod3dObject, "Change", "translateTool"); 228 ElementsMediator.set3DProperties(mod3dObject, "Change", "translateTool");
228 229
229 if(this._origin && this._delta) { 230 if(this._origin && this._delta) {
@@ -243,54 +244,54 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase,
243 element.elementModel.setProperty("dist", viewUtils.getPerspectiveDistFromElement(element)); 244 element.elementModel.setProperty("dist", viewUtils.getPerspectiveDistFromElement(element));
244 }); 245 });
245 246
246 } 247 }
247 }, 248 },
248 249
249 HandleAltKeyDown: { 250 HandleAltKeyDown: {