diff options
Diffstat (limited to 'js/helper-classes/3D')
-rwxr-xr-x | js/helper-classes/3D/vec-utils.js | 19 | ||||
-rwxr-xr-x | js/helper-classes/3D/view-utils.js | 72 |
2 files changed, 90 insertions, 1 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 1cd1c313..dabb1fcf 100755 --- a/js/helper-classes/3D/view-utils.js +++ b/js/helper-classes/3D/view-utils.js | |||
@@ -240,7 +240,6 @@ exports.ViewUtils = Montage.create(Component, { | |||
240 | var worldPt = MathUtils.transformPoint( viewPt, mat ); | 240 | var worldPt = MathUtils.transformPoint( viewPt, mat ); |
241 | var stageWorldPt = this.postViewToStageWorld( worldPt, elt ); | 241 | var stageWorldPt = this.postViewToStageWorld( worldPt, elt ); |
242 | this.popViewportObj(); | 242 | this.popViewportObj(); |
243 | |||
244 | return stageWorldPt; | 243 | return stageWorldPt; |
245 | } | 244 | } |
246 | }, | 245 | }, |
@@ -834,6 +833,7 @@ exports.ViewUtils = Montage.create(Component, { | |||
834 | } | 833 | } |
835 | }, | 834 | }, |
836 | 835 | ||
836 | /* | ||
837 | getStageWorldToGlobalMatrix: { | 837 | getStageWorldToGlobalMatrix: { |
838 | value: function() { | 838 | value: function() { |
839 | var stage = this.application.ninja.currentDocument.documentRoot, | 839 | var stage = this.application.ninja.currentDocument.documentRoot, |
@@ -874,6 +874,26 @@ exports.ViewUtils = Montage.create(Component, { | |||
874 | return mat; | 874 | return mat; |
875 | } | 875 | } |
876 | }, | 876 | }, |
877 | */ | ||
878 | getStageWorldToGlobalMatrix: | ||
879 | { | ||
880 | value: function() | ||
881 | { | ||
882 | var stage = this.application.ninja.currentDocument.documentRoot; | ||
883 | |||
884 | this.pushViewportObj( stage ); | ||
885 | // put the point into screen space of the stage - requires | ||
886 | // a translation to the top/left only | ||
887 | var cop = this.getCenterOfProjection(); | ||
888 | var v2s = Matrix.Translation([cop[0], cop[1], 0]); | ||
889 | this.popViewportObj(); | ||
890 | |||
891 | // append the localToGlobal matrix of the stage. | ||
892 | var mat = this.getLocalToGlobalMatrix( stage ); | ||
893 | glmat4.multiply( mat, v2s ); | ||
894 | return mat; | ||
895 | } | ||
896 | }, | ||
877 | 897 | ||
878 | localScreenToLocalWorld: { | 898 | localScreenToLocalWorld: { |
879 | value: function( objPt, elt ) { | 899 | value: function( objPt, elt ) { |
@@ -1049,6 +1069,56 @@ exports.ViewUtils = Montage.create(Component, { | |||
1049 | } | 1069 | } |
1050 | }, | 1070 | }, |
1051 | 1071 | ||
1072 | getLocalToStageWorldMatrix: { | ||
1073 | value: function( elt, shouldProject, shouldLocalTransform ) { | ||
1074 | var mat = Matrix.I(4); | ||
1075 | while (elt) | ||
1076 | { | ||
1077 | this.pushViewportObj( elt ); | ||
1078 | var cop = this.getCenterOfProjection(); | ||
1079 | var s2v = Matrix.Translation([-cop[0], -cop[1], 0]); | ||
1080 | var objMat = this.getMatrixFromElement( elt ); | ||
1081 | var projMat; | ||
1082 | if(shouldProject) | ||
1083 | { | ||
1084 | //projMat = Matrix.I(4).multiply( this.getPerspectiveDistFromElement(elt) ); | ||
1085 | var pDist = this.getPerspectiveDistFromElement(elt); | ||
1086 | var projMat = glmat4.scale(Matrix.I(4), [pDist,pDist,pDist], []); | ||
1087 | projMat[11] = -1; | ||
1088 | projMat[15] = 1400; | ||
1089 | } | ||
1090 | var v2s = Matrix.Translation([cop[0], cop[1], 0]); | ||
1091 | this.popViewportObj(); | ||
1092 | |||
1093 | // multiply all the matrices together | ||
1094 | //mat = s2v.multiply( mat ); | ||
1095 | glmat4.multiply( s2v, mat, mat ); | ||
1096 | if (elt === this._stageElement) break; | ||
1097 | //mat = objMat.multiply( mat ); | ||
1098 | if (shouldLocalTransform) { | ||
1099 | glmat4.multiply( objMat, mat, mat ); | ||
1100 | } | ||
1101 | if(shouldProject) | ||
1102 | { | ||
1103 | //mat = projMat.multiply( mat ); | ||
1104 | glmat4.multiply( projMat, mat, mat ); | ||
1105 | } | ||
1106 | //mat = v2s.multiply( mat ); | ||
1107 | glmat4.multiply( v2s, mat, mat ); | ||
1108 | |||
1109 | // offset to the parent | ||
1110 | var offset = this.getElementOffset( elt ); | ||
1111 | var offMat = Matrix.Translation([offset[0], offset[1], 0]); | ||
1112 | //mat = offMat.multiply( mat ); | ||
1113 | glmat4.multiply( offMat, mat, mat ); | ||
1114 | |||
1115 | elt = elt.parentElement; | ||
1116 | } | ||
1117 | |||
1118 | return mat; | ||
1119 | } | ||
1120 | }, | ||
1121 | |||
1052 | getUpVectorFromMatrix: { | 1122 | getUpVectorFromMatrix: { |
1053 | value: function( mat ) { | 1123 | value: function( mat ) { |
1054 | //var inv = mat.inverse(); | 1124 | //var inv = mat.inverse(); |