diff options
author | Ananya Sen | 2012-05-31 10:13:40 -0700 |
---|---|---|
committer | Ananya Sen | 2012-05-31 10:13:40 -0700 |
commit | 286457b4f23974277274ba388afd283e8aa085cb (patch) | |
tree | c21bf791e7c4f572d12f97987ea6b89e74da67fe /js/helper-classes/3D/view-utils.js | |
parent | 4d9b481c58090e8f1fc7b0e9d73a81b0f49cccc8 (diff) | |
parent | d49c909cff7f0c5e5d0b127ad84a2fefc6677dc6 (diff) | |
download | ninja-286457b4f23974277274ba388afd283e8aa085cb.tar.gz |
Merge branch 'refs/heads/ninja-internal-master' into cut-copy-paste
Conflicts:
js/controllers/styles-controller.js
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js/helper-classes/3D/view-utils.js')
-rwxr-xr-x | js/helper-classes/3D/view-utils.js | 171 |
1 files changed, 94 insertions, 77 deletions
diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js index 40a19b90..a3d09404 100755 --- a/js/helper-classes/3D/view-utils.js +++ b/js/helper-classes/3D/view-utils.js | |||
@@ -18,18 +18,11 @@ exports.ViewUtils = Montage.create(Component, { | |||
18 | // Instance variables | 18 | // Instance variables |
19 | /////////////////////////////////////////////////////////////////////// | 19 | /////////////////////////////////////////////////////////////////////// |
20 | 20 | ||
21 | m_viewportObj : { value: null, writable: true}, | 21 | m_viewportObj : { value: null}, |
22 | _perspectiveDist: { value: null, writable: true}, | 22 | _perspectiveDist: { value: null}, |
23 | 23 | ||
24 | // keep a stack of viewport objects | 24 | // keep a stack of viewport objects |
25 | _viewportObjStack: { value: [], writable: true }, | 25 | _viewportObjStack: { value: []}, |
26 | |||
27 | _currentDocument: { value: null , writable: true}, | ||
28 | _userContentLeft: { value: null , writable: true}, | ||
29 | _userContentTop: { value: null , writable: true}, | ||
30 | |||
31 | _rootElement: { value: null, writable: true}, | ||
32 | _stageElement: { value: null, writable: true}, | ||
33 | 26 | ||
34 | /////////////////////////////////////////////////////////////////////// | 27 | /////////////////////////////////////////////////////////////////////// |
35 | // Property accessors | 28 | // Property accessors |
@@ -43,18 +36,6 @@ exports.ViewUtils = Montage.create(Component, { | |||
43 | }, | 36 | }, |
44 | getViewportObj: { value: function() { return this.m_viewportObj; } }, | 37 | getViewportObj: { value: function() { return this.m_viewportObj; } }, |
45 | 38 | ||
46 | setRootElement: { value: function( elt ) { this._rootElement = elt; } }, | ||
47 | getRootElement: { value: function () { return this._rootElement; } }, | ||
48 | |||
49 | setStageElement: { value: function( elt ) { this._stageElement = elt; } }, | ||
50 | getStageElement: { value: function () { return this._stageElement; } }, | ||
51 | |||
52 | setCurrentDocument: { value: function(value) { this._currentDocument = value; }}, | ||
53 | |||
54 | setUserContentLeft: { value: function(value) { this._userContentLeft = value; }}, | ||
55 | setUserContentTop: { value: function(value) { this._userContentTop = value; }}, | ||
56 | |||
57 | |||
58 | getPerspectiveDistance: { value: function () { return this._perspectiveDist; } }, | 39 | getPerspectiveDistance: { value: function () { return this._perspectiveDist; } }, |
59 | 40 | ||
60 | /////////////////////////////////////////////////////////////////////// | 41 | /////////////////////////////////////////////////////////////////////// |
@@ -124,35 +105,73 @@ exports.ViewUtils = Montage.create(Component, { | |||
124 | } | 105 | } |
125 | }, | 106 | }, |
126 | 107 | ||
127 | getNormalToUnprojectedElementPlane: { | 108 | /* |
128 | value: function( elt ) { | 109 | * This method will return a normal to a plane containing the Z axis and either the |
129 | var mat = this.getMatrixFromElement(elt); | 110 | * x or y axis of the element. |
111 | */ | ||
112 | getNormalToUnprojectedElementPlane: | ||
113 | { | ||
114 | value: function( elt, axis, localMode ) | ||
115 | { | ||
116 | var objMat = this.getMatrixFromElement(elt); | ||
117 | var objMatInv = glmat4.inverse( objMat, [] ); | ||
130 | 118 | ||
131 | var xVec = [mat[0], mat[1], mat[2], mat[3]]; | 119 | var xVec = [1,0,0]; |
132 | var yVec = [mat[4], mat[5], mat[6], mat[7]]; | 120 | var yVec = [0,1,0]; |
121 | var zVec = [0,0,1]; | ||
133 | 122 | ||
134 | var stage = this.application.ninja.currentDocument.documentRoot; | 123 | var stage = this.application.ninja.currentDocument.model.documentRoot; |
135 | var stageMat = this.getMatrixFromElement(stage); | 124 | var stageMat = this.getMatrixFromElement(stage); |
136 | var stagePlane = [stageMat[8], stageMat[9], stageMat[10], stageMat[11]]; | ||
137 | 125 | ||
138 | if (elt === stage) | 126 | var mat = glmat4.multiply( stageMat, objMat, [] ); |
127 | |||
128 | var viewDir; | ||
129 | if (localMode) | ||
130 | { | ||
131 | var matInv = glmat4.inverse( mat, [] ); | ||
132 | viewDir = MathUtils.transformVector( [0,0,1], matInv ); | ||
133 | } | ||
134 | else | ||
139 | { | 135 | { |
140 | xVec = [1,0,0]; | 136 | var stageInv = glmat4.inverse( stageMat, [] ); |
141 | yVec = [0,1,0]; | 137 | viewDir = MathUtils.transformVector( [0,0,1], stageInv ); |
142 | } | 138 | } |
143 | 139 | ||
144 | var xDot = Math.abs(vecUtils.vecDot(3, xVec, stagePlane)); | 140 | var plane; |
145 | var yDot = Math.abs(vecUtils.vecDot(3, yVec, stagePlane)); | 141 | var xDot, yDot, zDot; |
142 | switch (axis) | ||
143 | { | ||
144 | case 0: | ||
145 | yDot = Math.abs(vecUtils.vecDot(3, yVec, viewDir)); | ||
146 | zDot = Math.abs(vecUtils.vecDot(3, zVec, viewDir)); | ||
147 | if(yDot > zDot) | ||
148 | plane = vecUtils.vecCross( 3, zVec, xVec ); | ||
149 | else | ||
150 | plane = vecUtils.vecCross( 3, yVec, xVec ); | ||
151 | break; | ||
152 | |||
153 | case 1: | ||
154 | xDot = Math.abs(vecUtils.vecDot(3, yVec, viewDir)); | ||
155 | zDot = Math.abs(vecUtils.vecDot(3, zVec, viewDir)); | ||
156 | if(xDot > zDot) | ||
157 | plane = vecUtils.vecCross( 3, zVec, yVec ); | ||
158 | else | ||
159 | plane = vecUtils.vecCross( 3, xVec, yVec ); | ||
160 | break; | ||
161 | break; | ||
162 | |||
163 | case 2: | ||
164 | xDot = Math.abs(vecUtils.vecDot(3, xVec, viewDir)); | ||
165 | yDot = Math.abs(vecUtils.vecDot(3, yVec, viewDir)); | ||
166 | |||
167 | if(xDot > yDot) | ||
168 | plane = vecUtils.vecCross( 3, yVec, zVec ); | ||
169 | else | ||
170 | plane = vecUtils.vecCross( 3, xVec, zVec ); | ||
171 | break; | ||
172 | } | ||
146 | 173 | ||
147 | var plane; | 174 | if (localMode) plane = MathUtils.transformVector( plane, objMat ); |
148 | if(xDot > yDot) | ||
149 | { | ||
150 | plane = xVec; | ||
151 | } | ||
152 | else | ||
153 | { | ||
154 | plane = yVec; | ||
155 | } | ||
156 | 175 | ||
157 | // The translation value is a point on the plane | 176 | // The translation value is a point on the plane |
158 | this.pushViewportObj( elt ); | 177 | this.pushViewportObj( elt ); |
@@ -242,6 +261,11 @@ exports.ViewUtils = Montage.create(Component, { | |||
242 | value: function( localPt, elt ) { | 261 | value: function( localPt, elt ) { |
243 | this.pushViewportObj( elt ); | 262 | this.pushViewportObj( elt ); |
244 | var viewPt = this.screenToView( localPt[0], localPt[1], localPt[2] ); | 263 | var viewPt = this.screenToView( localPt[0], localPt[1], localPt[2] ); |
264 | if ((elt == null) || (elt === this._stageElement)) | ||
265 | { | ||
266 | this.popViewportObj(); | ||
267 | return viewPt; | ||
268 | } | ||
245 | var mat = this.getMatrixFromElement( elt ); | 269 | var mat = this.getMatrixFromElement( elt ); |
246 | var worldPt = MathUtils.transformPoint( viewPt, mat ); | 270 | var worldPt = MathUtils.transformPoint( viewPt, mat ); |
247 | var stageWorldPt = this.postViewToStageWorld( worldPt, elt ); | 271 | var stageWorldPt = this.postViewToStageWorld( worldPt, elt ); |
@@ -256,7 +280,7 @@ exports.ViewUtils = Montage.create(Component, { | |||
256 | // into stage world space. | 280 | // into stage world space. |
257 | postViewToStageWorld: { | 281 | postViewToStageWorld: { |
258 | value: function( localPt, elt ) { | 282 | value: function( localPt, elt ) { |
259 | if ((elt == null) || (elt === this._stageElement)) return localPt; | 283 | if ((elt == null) || (elt === this.application.ninja.currentDocument.model.documentRoot)) return localPt; |
260 | 284 | ||
261 | // get the 3D transformation and 2D offset from the element | 285 | // get the 3D transformation and 2D offset from the element |
262 | var pt = localPt.slice(0); | 286 | var pt = localPt.slice(0); |
@@ -283,7 +307,7 @@ exports.ViewUtils = Montage.create(Component, { | |||
283 | this.popViewportObj(); | 307 | this.popViewportObj(); |
284 | 308 | ||
285 | // check if we are done | 309 | // check if we are done |
286 | if (parent === this._stageElement) break; | 310 | if (parent === this.application.ninja.currentDocument.model.documentRoot) break; |
287 | 311 | ||
288 | if (this.elementHas3D( parent )) | 312 | if (this.elementHas3D( parent )) |
289 | { | 313 | { |
@@ -308,15 +332,17 @@ exports.ViewUtils = Montage.create(Component, { | |||
308 | 332 | ||
309 | // transform the bounds up the tree | 333 | // transform the bounds up the tree |
310 | var child = elt; | 334 | var child = elt; |
311 | var parent = elt.offsetParent; | 335 | while ( child ) |
312 | while ( parent ) | ||
313 | { | 336 | { |
314 | pt = this.childToParent( pt, child ); | 337 | pt = this.childToParent( pt, child ); |
315 | 338 | ||
316 | if (parent === this._rootElement) break; | 339 | // if (child === this.application.ninja.currentDocument.model.documentRoot) break; |
340 | // child = child.offsetParent; | ||
317 | 341 | ||
318 | child = parent; | 342 | if (child === this.application.ninja.currentDocument.model.documentRoot) break; |
319 | parent = parent.offsetParent; | 343 | if (child === this.application.ninja.currentDocument.model.documentRoot.parentNode) break; |
344 | child = child.offsetParent; | ||
345 | if (child === this.application.ninja.currentDocument.model.documentRoot.parentNode) break; | ||
320 | } | 346 | } |
321 | 347 | ||
322 | ///////////////////////////////////////////////////////// | 348 | ///////////////////////////////////////////////////////// |
@@ -352,7 +378,8 @@ exports.ViewUtils = Montage.create(Component, { | |||
352 | 378 | ||
353 | // transform the bounds up the tree | 379 | // transform the bounds up the tree |
354 | var parent = child.offsetParent; | 380 | var parent = child.offsetParent; |
355 | if ( parent ) | 381 | // TODO - Should have a different way to check for new template mode |