diff options
author | Jose Antonio Marquez | 2012-04-26 11:07:09 -0700 |
---|---|---|
committer | Jose Antonio Marquez | 2012-04-26 11:07:09 -0700 |
commit | d193e087bf24b538b6d88ae501b4b6e9781f501b (patch) | |
tree | 9a735388752f575fddf72240803c385316ff5c43 /js/helper-classes | |
parent | 7f5eb2105c2e5e0970072af88fa90baded7e55d6 (diff) | |
parent | bcc8f8616f5ad4bf310928da6cbc01da12f6e468 (diff) | |
download | ninja-d193e087bf24b538b6d88ae501b4b6e9781f501b.tar.gz |
Merge branch 'refs/heads/Ninja-Internal' into FileIO
Diffstat (limited to 'js/helper-classes')
-rwxr-xr-x | js/helper-classes/3D/vec-utils.js | 19 | ||||
-rwxr-xr-x | js/helper-classes/3D/view-utils.js | 85 |
2 files changed, 75 insertions, 29 deletions
diff --git a/js/helper-classes/3D/vec-utils.js b/js/helper-classes/3D/vec-utils.js index 4eacd856..0916c840 100755 --- a/js/helper-classes/3D/vec-utils.js +++ b/js/helper-classes/3D/vec-utils.js | |||
@@ -113,6 +113,25 @@ var VecUtils = exports.VecUtils = Object.create(Object.prototype, | |||
113 | } | 113 | } |
114 | }, | 114 | }, |
115 | 115 | ||
116 | vecDistSq : { | ||
117 | value: function( dimen, a, b ) { | ||
118 | var sum; | ||
119 | |||
120 | if ((a.length < dimen) || (b.length < dimen)) | ||
121 | { | ||
122 | throw new Error( "dimension error in VecUtils.vecDistSq" ); | ||
123 | } | ||
124 | |||
125 | var sum = 0.0; | ||
126 | for (var i=0; i<dimen; i++) | ||
127 | { | ||
128 | var d = a[i] - b[i]; | ||
129 | sum += d*d; | ||
130 | } | ||
131 | return sum; | ||
132 | } | ||
133 | }, | ||
134 | |||
116 | vecDot : { | 135 | vecDot : { |
117 | value: function( dimen, v0, v1 ) { | 136 | value: function( dimen, v0, v1 ) { |
118 | if ((v0.length < dimen) || (v1.length < dimen)) | 137 | if ((v0.length < dimen) || (v1.length < dimen)) |
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(); |