diff options
Diffstat (limited to 'js/helper-classes/3D')
-rwxr-xr-x | js/helper-classes/3D/view-utils.js | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js index a72b7906..35f4a568 100755 --- a/js/helper-classes/3D/view-utils.js +++ b/js/helper-classes/3D/view-utils.js | |||
@@ -242,7 +242,6 @@ exports.ViewUtils = Montage.create(Component, { | |||
242 | var worldPt = MathUtils.transformPoint( viewPt, mat ); | 242 | var worldPt = MathUtils.transformPoint( viewPt, mat ); |
243 | var stageWorldPt = this.postViewToStageWorld( worldPt, elt ); | 243 | var stageWorldPt = this.postViewToStageWorld( worldPt, elt ); |
244 | this.popViewportObj(); | 244 | this.popViewportObj(); |
245 | |||
246 | return stageWorldPt; | 245 | return stageWorldPt; |
247 | } | 246 | } |
248 | }, | 247 | }, |
@@ -788,6 +787,7 @@ exports.ViewUtils = Montage.create(Component, { | |||
788 | } | 787 | } |
789 | }, | 788 | }, |
790 | 789 | ||
790 | /* | ||
791 | getStageWorldToGlobalMatrix: { | 791 | getStageWorldToGlobalMatrix: { |
792 | value: function() { | 792 | value: function() { |
793 | var stage = this.application.ninja.currentDocument.documentRoot; | 793 | var stage = this.application.ninja.currentDocument.documentRoot; |
@@ -821,6 +821,26 @@ exports.ViewUtils = Montage.create(Component, { | |||
821 | return mat; | 821 | return mat; |
822 | } | 822 | } |
823 | }, | 823 | }, |
824 | */ | ||
825 | getStageWorldToGlobalMatrix: | ||
826 | { | ||
827 | value: function() | ||
828 | { | ||
829 | var stage = this.application.ninja.currentDocument.documentRoot; | ||
830 | |||
831 | this.pushViewportObj( stage ); | ||
832 | // put the point into screen space of the stage - requires | ||
833 | // a translation to the top/left only | ||
834 | var cop = this.getCenterOfProjection(); | ||
835 | var v2s = Matrix.Translation([cop[0], cop[1], 0]); | ||
836 | this.popViewportObj(); | ||
837 | |||
838 | // append the localToGlobal matrix of the stage. | ||
839 | var mat = this.getLocalToGlobalMatrix( stage ); | ||
840 | glmat4.multiply( mat, v2s ); | ||
841 | return mat; | ||
842 | } | ||
843 | }, | ||
824 | 844 | ||
825 | localScreenToLocalWorld: { | 845 | localScreenToLocalWorld: { |
826 | value: function( objPt, elt ) { | 846 | value: function( objPt, elt ) { |
@@ -968,6 +988,56 @@ exports.ViewUtils = Montage.create(Component, { | |||
968 | } | 988 | } |
969 | }, | 989 | }, |
970 | 990 | ||
991 | getLocalToStageWorldMatrix: { | ||
992 | value: function( elt, shouldProject, shouldLocalTransform ) { | ||
993 | var mat = Matrix.I(4); | ||
994 | while (elt) | ||
995 | { | ||
996 | this.pushViewportObj( elt ); | ||
997 | var cop = this.getCenterOfProjection(); | ||
998 | var s2v = Matrix.Translation([-cop[0], -cop[1], 0]); | ||
999 | var objMat = this.getMatrixFromElement( elt ); | ||
1000 | var projMat; | ||
1001 | if(shouldProject) | ||
1002 | { | ||
1003 | //projMat = Matrix.I(4).multiply( this.getPerspectiveDistFromElement(elt) ); | ||
1004 | var pDist = this.getPerspectiveDistFromElement(elt); | ||
1005 | var projMat = glmat4.scale(Matrix.I(4), [pDist,pDist,pDist], []); | ||
1006 | projMat[11] = -1; | ||
1007 | projMat[15] = 1400; | ||
1008 | } | ||
1009 | var v2s = Matrix.Translation([cop[0], cop[1], 0]); | ||
1010 | this.popViewportObj(); | ||
1011 | |||
1012 | // multiply all the matrices together | ||
1013 | //mat = s2v.multiply( mat ); | ||
1014 | glmat4.multiply( s2v, mat, mat ); | ||
1015 | if (elt === this._stageElement) break; | ||
1016 | //mat = objMat.multiply( mat ); | ||
1017 | if (shouldLocalTransform) { | ||
1018 | glmat4.multiply( objMat, mat, mat ); | ||
1019 | } | ||
1020 | if(shouldProject) | ||
1021 | { | ||
1022 | //mat = projMat.multiply( mat ); | ||
1023 | glmat4.multiply( projMat, mat, mat ); | ||
1024 | } | ||
1025 | //mat = v2s.multiply( mat ); | ||
1026 | glmat4.multiply( v2s, mat, mat ); | ||
1027 | |||
1028 | // offset to the parent | ||
1029 | var offset = this.getElementOffset( elt ); | ||
1030 | var offMat = Matrix.Translation([offset[0], offset[1], 0]); | ||
1031 | //mat = offMat.multiply( mat ); | ||
1032 | glmat4.multiply( offMat, mat, mat ); | ||
1033 | |||
1034 | elt = elt.parentElement; | ||
1035 | } | ||
1036 | |||
1037 | return mat; | ||
1038 | } | ||
1039 | }, | ||
1040 | |||
971 | getUpVectorFromMatrix: { | 1041 | getUpVectorFromMatrix: { |
972 | value: function( mat ) { | 1042 | value: function( mat ) { |
973 | //var inv = mat.inverse(); | 1043 | //var inv = mat.inverse(); |