aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D/view-utils.js
diff options
context:
space:
mode:
authorValerio Virgillito2012-04-24 15:36:59 -0700
committerValerio Virgillito2012-04-24 15:36:59 -0700
commitd3a6350163ada5644d34ed8d5c2a00cef4db2afc (patch)
tree8862827848c55b36cc2e2bc0bb0c07a5e50dc1ca /js/helper-classes/3D/view-utils.js
parent55e6d621b9555abac06ab4adff44dfe29a78ec4e (diff)
parente7bbd9b08b4cd87530596b370366d994ca766650 (diff)
downloadninja-d3a6350163ada5644d34ed8d5c2a00cef4db2afc.tar.gz
Merge pull request #174 from pushkarjoshi/pentool
Pentool
Diffstat (limited to 'js/helper-classes/3D/view-utils.js')
-rwxr-xr-xjs/helper-classes/3D/view-utils.js85
1 files changed, 56 insertions, 29 deletions
diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js
index ee822f1f..40a19b90 100755
--- a/js/helper-classes/3D/view-utils.js
+++ b/js/helper-classes/3D/view-utils.js
@@ -246,7 +246,6 @@ exports.ViewUtils = Montage.create(Component, {
246 var worldPt = MathUtils.transformPoint( viewPt, mat ); 246 var worldPt = MathUtils.transformPoint( viewPt, mat );
247 var stageWorldPt = this.postViewToStageWorld( worldPt, elt ); 247 var stageWorldPt = this.postViewToStageWorld( worldPt, elt );
248 this.popViewportObj(); 248 this.popViewportObj();
249
250 return stageWorldPt; 249 return stageWorldPt;
251 } 250 }
252 }, 251 },
@@ -841,43 +840,21 @@ exports.ViewUtils = Montage.create(Component, {
841 }, 840 },
842 841
843 getStageWorldToGlobalMatrix: 842 getStageWorldToGlobalMatrix:
844 { 843 {
845 value: function() 844 value: function()
846 { 845 {
847 var stage = this.application.ninja.currentDocument.documentRoot; 846 var stage = this.application.ninja.currentDocument.documentRoot;
848 //projMat;
849
850 // get the matrix to the parent
851 //var mat = Matrix.I(4);
852 847
853 this.pushViewportObj( stage ); 848 this.pushViewportObj( stage );
849 // put the point into screen space of the stage - requires
850 // a translation to the top/left only
854 var cop = this.getCenterOfProjection(); 851 var cop = this.getCenterOfProjection();
855 var v2s = Matrix.Translation([cop[0], cop[1], 0]); 852 var v2s = Matrix.Translation([cop[0], cop[1], 0]);
856 this.popViewportObj(); 853 this.popViewportObj();
857 854
858 /* 855 // append the localToGlobal matrix of the stage.
859 var p = this.getPerspectiveDistFromElement(stage);
860 if(p)
861 {
862 projMat = glmat4.scale( Matrix.I(4), [p,p,p], [] );
863 projMat[11] = -1;
864 }
865 else
866 {
867 mat = v2s;
868 }
869 // offset to the parent
870 var offset = this.getElementOffset( stage );
871 var offMat = Matrix.Translation([offset[0], offset[1], 0]);
872 //mat = offMat.multiply( mat );
873 glmat4.multiply( offMat, mat, mat );
874 this.popViewportObj();
875 */
876
877 // append the localToGlobal matrix of the stage.
878 var mat = this.getLocalToGlobalMatrix( stage ); 856 var mat = this.getLocalToGlobalMatrix( stage );
879 glmat4.multiply( mat, v2s ); 857 glmat4.multiply( mat, v2s );
880
881 return mat; 858 return mat;
882 } 859 }
883 }, 860 },
@@ -1056,6 +1033,56 @@ exports.ViewUtils = Montage.create(Component, {
1056 } 1033 }
1057 }, 1034 },
1058 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
1059 getUpVectorFromMatrix: { 1086 getUpVectorFromMatrix: {
1060 value: function( mat ) { 1087 value: function( mat ) {
1061 //var inv = mat.inverse(); 1088 //var inv = mat.inverse();