aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D/view-utils.js
diff options
context:
space:
mode:
authorKruti Shah2012-07-17 12:40:00 -0700
committerKruti Shah2012-07-17 12:40:00 -0700
commitbf2d7bdb22c28089dc1067bc9094ebc590daac87 (patch)
tree2156d9920ea1b7db49ed6460545fea7cda121bae /js/helper-classes/3D/view-utils.js
parent7e2c2dbd040ed79a3f0678f91bd4b6db9cf69231 (diff)
parentb4b3e45d6684e77d361b4f8ca5be4889428320c5 (diff)
downloadninja-bf2d7bdb22c28089dc1067bc9094ebc590daac87.tar.gz
Merge branch 'refs/heads/TimelineUberJD' into Timeline-local-kruti
Diffstat (limited to 'js/helper-classes/3D/view-utils.js')
-rwxr-xr-xjs/helper-classes/3D/view-utils.js351
1 files changed, 176 insertions, 175 deletions
<
diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js
index 3462428f..25e40bac 100755
--- a/js/helper-classes/3D/view-utils.js
+++ b/js/helper-classes/3D/view-utils.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
@@ -140,15 +141,15 @@ exports.ViewUtils = Montage.create(Component, {
140 }, 141 },
141 142
142 /* 143 /*
143 * This method will return a normal to a plane containing the Z axis and either the 144 * This method will return a normal to a plane containing the Z axis and either the
144 * x or y axis of the element. 145 * x or y axis of the element.
145 */ 146 */
146 getNormalToUnprojectedElementPlane: 147 getNormalToUnprojectedElementPlane:
147 { 148 {
148 value: function( elt, axis, localMode ) 149 value: function( elt, axis, localMode )
149 { 150 {
150 var objMat = this.getMatrixFromElement(elt); 151 var objMat = this.getMatrixFromElement(elt);
151 var objMatInv = glmat4.inverse( objMat, [] ); 152 var objMatInv = glmat4.inverse( objMat, [] );
152 153
153 var xVec = [1,0,0]; 154 var xVec = [1,0,0];
154 var yVec = [0,1,0]; 155 var yVec = [0,1,0];
@@ -157,55 +158,55 @@ exports.ViewUtils = Montage.create(Component, {
157 var stage = this.application.ninja.currentDocument.model.documentRoot; 158 var stage = this.application.ninja.currentDocument.model.documentRoot;
158 var stageMat = this.getMatrixFromElement(stage); 159 var stageMat = this.getMatrixFromElement(stage);
159 160
160 var mat = glmat4.multiply( stageMat, objMat, [] ); 161 var mat = glmat4.multiply( stageMat, objMat, [] );
161 162
162 var viewDir; 163 var viewDir;
163 if (localMode) 164 if (localMode)
164 { 165 {
165 var matInv = glmat4.inverse( mat, [] ); 166 var matInv = glmat4.inverse( mat, [] );
166 viewDir = MathUtils.transformVector( [0,0,1], matInv ); 167 viewDir = MathUtils.transformVector( [0,0,1], matInv );
167 } 168 }
168 else 169 else
169 { 170 {
170 var stageInv = glmat4.inverse( stageMat, [] ); 171 var stageInv = glmat4.inverse( stageMat, [] );
171 viewDir = MathUtils.transformVector( [0,0,1], stageInv ); 172 viewDir = MathUtils.transformVector( [0,0,1], stageInv );
172 } 173 }
173 174
174 var plane; 175 var plane;
175 var xDot, yDot, zDot; 176 var xDot, yDot, zDot;
176 switch (axis) 177 switch (axis)
177 { 178 {
178 case 0: 179 case 0:
179 yDot = Math.abs(vecUtils.vecDot(3, yVec, viewDir)); 180 yDot = Math.abs(vecUtils.vecDot(3, yVec, viewDir));
180 zDot = Math.abs(vecUtils.vecDot(3, zVec, viewDir)); 181 zDot = Math.abs(vecUtils.vecDot(3, zVec, viewDir));
181 if(yDot > zDot) 182 if(yDot > zDot)
182 plane = vecUtils.vecCross( 3, zVec, xVec ); 183 plane = vecUtils.vecCross( 3, zVec, xVec );
183 else 184 else
184 plane = vecUtils.vecCross( 3, yVec, xVec ); 185 plane = vecUtils.vecCross( 3, yVec, xVec );
185 break; 186 break;
186 187
187 case 1: 188 case 1:
188 xDot = Math.abs(vecUtils.vecDot(3, yVec, viewDir)); 189 xDot = Math.abs(vecUtils.vecDot(3, yVec, viewDir));
189 zDot = Math.abs(vecUtils.vecDot(3, zVec, viewDir)); 190 zDot = Math.abs(vecUtils.vecDot(3, zVec, viewDir));
190 if(xDot > zDot) 191 if(xDot > zDot)
191 plane = vecUtils.vecCross( 3, zVec, yVec ); 192 plane = vecUtils.vecCross( 3, zVec, yVec );
192 else 193 else
193 plane = vecUtils.vecCross( 3, xVec, yVec ); 194 plane = vecUtils.vecCross( 3, xVec, yVec );
194 break; 195 break;
195 break; 196 break;
196 197
197 case 2: 198 case 2:
198 xDot = Math.abs(vecUtils.vecDot(3, xVec, viewDir)); 199 xDot = Math.abs(vecUtils.vecDot(3, xVec, viewDir));
199 yDot = Math.abs(vecUtils.vecDot(3, yVec, viewDir)); 200 yDot = Math.abs(vecUtils.vecDot(3, yVec, viewDir));
200 201
201 if(xDot > yDot) 202 if(xDot > yDot)
202 plane = vecUtils.vecCross( 3, yVec, zVec ); 203 plane = vecUtils.vecCross( 3, yVec, zVec );
203 else 204 else
204 plane = vecUtils.vecCross( 3, xVec, zVec ); 205 plane = vecUtils.vecCross( 3, xVec, zVec );
205 break; 206 break;
206 } 207 }
207 208
208 if (localMode) plane = MathUtils.transformVector( plane, objMat ); 209 if (localMode) plane = MathUtils.transformVector( plane, objMat );
209 210
210 // The translation value is a point on the plane 211 // The translation value is a point on the plane
211 this.pushViewportObj( elt ); 212 this.pushViewportObj( elt );
@@ -332,11 +333,11 @@ exports.ViewUtils = Montage.create(Component, {
332 value: function( localPt, elt ) { 333 value: function( localPt, elt ) {
333 this.pushViewportObj( elt ); 334 this.pushViewportObj( elt );
334 var viewPt = this.screenToView( localPt[0], localPt[1], localPt[2] ); 335 var viewPt = this.screenToView( localPt[0], localPt[1], localPt[2] );
335 if ((elt == null) || (elt === this._stageElement)) 336 if ((elt == null) || (elt === this._stageElement))
336 { 337 {
337 this.popViewportObj(); 338 this.popViewportObj();
338 return viewPt; 339 return viewPt;
339 } 340 }
340 var mat = this.getMatrixFromElement( elt ); 341 var mat = this.getMatrixFromElement( elt );
341 var worldPt = MathUtils.transformPoint( viewPt, mat ); 342 var worldPt = MathUtils.transformPoint( viewPt, mat );
342 var stageWorldPt = this.postViewToStageWorld( worldPt, elt ); 343 var stageWorldPt = this.postViewToStageWorld( worldPt, elt );
@@ -571,7 +572,7 @@ exports.ViewUtils = Montage.create(Component, {
571 return localPlane; 572 return localPlane;
572 } 573 }
573 }, 574 },
574 575
575 parentToChild: { 576 parentToChild: {
576 value: function( parentPt, child, passthrough ) { 577 value: function( parentPt, child, passthrough ) {
577 var pt = parentPt.slice(0); 578 var pt = parentPt.slice(0);
@@ -620,7 +621,7 @@ exports.ViewUtils = Montage.create(Component, {
620 return childPt; 621 return childPt;
621 } 622 }
622 }, 623 },
623 624
624 parentToChildWorld: { 625 parentToChildWorld: {
625 value: function( parentPt, child ) { 626 value: function( parentPt, child ) {
626 var pt = parentPt.slice(0); 627 var pt = parentPt.slice(0);
@@ -694,7 +695,7 @@ exports.ViewUtils = Montage.create(Component, {
694 return vec; 695 return vec;
695 } 696 }
696 }, 697 },
697 698
698 getElementBounds: { 699 getElementBounds: {
699 value: function( elt, localSpace ) { 700 value: function( elt, localSpace ) {
700 // optional argument localSpace, if true, puts the top left at (0,0). 701 // optional argument localSpace, if true, puts the top left at (0,0).
@@ -876,7 +877,7 @@ exports.ViewUtils = Montage.create(Component, {
876 } 877 }
877 }, 878 },
878 879
879 880
880 unproject: { 881 unproject: {
881 value: function( pt ) { 882 value: function( pt ) {
882 if(!this._perspectiveDist) 883 if(!this._perspectiveDist)
@@ -968,7 +969,7 @@ exports.ViewUtils = Montage.create(Component, {