aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D/view-utils.js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-04-25 13:34:04 -0700
committerNivesh Rajbhandari2012-04-25 13:34:04 -0700
commit32a24988add5ba0ecf80caa31871cdd90e3eea5b (patch)
treefbf05f2dfc91e57ab9598046ff16798ea0ae1966 /js/helper-classes/3D/view-utils.js
parent60d6346a78fb5257eaf36f17a5fcb764a342c012 (diff)
parentd3a6350163ada5644d34ed8d5c2a00cef4db2afc (diff)
downloadninja-32a24988add5ba0ecf80caa31871cdd90e3eea5b.tar.gz
Merge branch 'refs/heads/ninja-internal' into WebGLMaterials
Diffstat (limited to 'js/helper-classes/3D/view-utils.js')
-rwxr-xr-xjs/helper-classes/3D/view-utils.js100
1 files changed, 67 insertions, 33 deletions
diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js
index 1cd1c313..40a19b90 100755
--- a/js/helper-classes/3D/view-utils.js
+++ b/js/helper-classes/3D/view-utils.js
@@ -135,6 +135,12 @@ exports.ViewUtils = Montage.create(Component, {
135 var stageMat = this.getMatrixFromElement(stage); 135 var stageMat = this.getMatrixFromElement(stage);
136 var stagePlane = [stageMat[8], stageMat[9], stageMat[10], stageMat[11]]; 136 var stagePlane = [stageMat[8], stageMat[9], stageMat[10], stageMat[11]];
137 137
138 if (elt === stage)
139 {
140 xVec = [1,0,0];
141 yVec = [0,1,0];
142 }
143
138 var xDot = Math.abs(vecUtils.vecDot(3, xVec, stagePlane)); 144 var xDot = Math.abs(vecUtils.vecDot(3, xVec, stagePlane));
139 var yDot = Math.abs(vecUtils.vecDot(3, yVec, stagePlane)); 145 var yDot = Math.abs(vecUtils.vecDot(3, yVec, stagePlane));
140 146
@@ -240,7 +246,6 @@ exports.ViewUtils = Montage.create(Component, {
240 var worldPt = MathUtils.transformPoint( viewPt, mat ); 246 var worldPt = MathUtils.transformPoint( viewPt, mat );
241 var stageWorldPt = this.postViewToStageWorld( worldPt, elt ); 247 var stageWorldPt = this.postViewToStageWorld( worldPt, elt );
242 this.popViewportObj(); 248 this.popViewportObj();
243
244 return stageWorldPt; 249 return stageWorldPt;
245 } 250 }
246 }, 251 },
@@ -834,43 +839,22 @@ exports.ViewUtils = Montage.create(Component, {
834 } 839 }
835 }, 840 },
836 841
837 getStageWorldToGlobalMatrix: { 842 getStageWorldToGlobalMatrix:
838 value: function() { 843 {
839 var stage = this.application.ninja.currentDocument.documentRoot, 844 value: function()
840 projMat; 845 {
841 this.pushViewportObj( stage ); 846 var stage = this.application.ninja.currentDocument.documentRoot;
842
843 // get the matrix to the parent
844 var mat = Matrix.I(4);
845 847
848 this.pushViewportObj( stage );
849 // put the point into screen space of the stage - requires
850 // a translation to the top/left only
846 var cop = this.getCenterOfProjection(); 851 var cop = this.getCenterOfProjection();
847 var v2s = Matrix.Translation([cop[0], cop[1], 0]); 852 var v2s = Matrix.Translation([cop[0], cop[1], 0]);
848
849 var p = this.getPerspectiveDistFromElement(stage);
850 if(p)
851 {
852 projMat = glmat4.scale( Matrix.I(4), [p,p,p], [] );
853 projMat[11] = -1;
854 mat = glmat4.multiply( v2s, projMat, [] );
855 }
856 else
857 {
858 mat = v2s;
859 }
860
861 // offset to the parent
862 var offset = this.getElementOffset( stage );
863 var offMat = Matrix.Translation([offset[0], offset[1], 0]);
864 //mat = offMat.multiply( mat );
865 glmat4.multiply( offMat, mat, mat );
866
867 this.popViewportObj(); 853 this.popViewportObj();
868 854
869 // var mat2 = this.getLocalToGlobalMatrix( stage.parentElement ); 855 // append the localToGlobal matrix of the stage.
870 var mat2 = this.getLocalToGlobalMatrix( this._rootElement ); 856 var mat = this.getLocalToGlobalMatrix( stage );
871 //var mat = mat2.multiply( mat ); 857 glmat4.multiply( mat, v2s );
872 glmat4.multiply( mat2, mat, mat );
873
874 return mat; 858 return mat;
875 } 859 }
876 }, 860 },
@@ -1049,6 +1033,56 @@ exports.ViewUtils = Montage.create(Component, {
1049 } 1033 }
1050 }, 1034 },
1051 1035
1036 getLocalToStageWorldMatrix: {
1037 value: function( elt, shouldProject, shouldLocalTransform ) {
1038 var mat = Matrix.I(4);
1039 while (elt)
1040 {
1041 this.pushViewportObj( elt );
1042 var cop = this.getCenterOfProjection();
1043 var s2v = Matrix.Translation([-cop[0], -cop[1], 0]);
1044 var objMat = this.getMatrixFromElement( elt );
1045 var projMat;
1046 if(shouldProject)
1047 {
1048 //projMat = Matrix.I(4).multiply( this.getPerspectiveDistFromElement(elt) );
1049 var pDist = this.getPerspectiveDistFromElement(elt);
1050 var projMat = glmat4.scale(Matrix.I(4), [pDist,pDist,pDist], []);
1051 projMat[11] = -1;
1052 projMat[15] = 1400;
1053 }
1054 var v2s = Matrix.Translation([cop[0], cop[1], 0]);
1055 this.popViewportObj();
1056
1057 // multiply all the matrices together
1058 //mat = s2v.multiply( mat );
1059 glmat4.multiply( s2v, mat, mat );
1060 if (elt === this._stageElement) break;
1061 //mat = objMat.multiply( mat );
1062 if (shouldLocalTransform) {
1063 glmat4.multiply( objMat, mat, mat );
1064 }
1065 if(shouldProject)
1066 {
1067 //mat = projMat.multiply( mat );
1068 glmat4.multiply( projMat, mat, mat );
1069 }
1070 //mat = v2s.multiply( mat );
1071 glmat4.multiply( v2s, mat, mat );
1072
1073 // offset to the parent
1074 var offset = this.getElementOffset( elt );
1075 var offMat = Matrix.Translation([offset[0], offset[1], 0]);
1076 //mat = offMat.multiply( mat );
1077 glmat4.multiply( offMat, mat, mat );
1078
1079 elt = elt.parentElement;
1080 }
1081
1082 return mat;
1083 }
1084 },
1085
1052 getUpVectorFromMatrix: { 1086 getUpVectorFromMatrix: {
1053 value: function( mat ) { 1087 value: function( mat ) {
1054 //var inv = mat.inverse(); 1088 //var inv = mat.inverse();