aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes
diff options
context:
space:
mode:
authorhwc4872012-04-05 17:03:14 -0700
committerhwc4872012-04-05 17:03:14 -0700
commit96bfeee2e6b735b87e8482d6e2cf24d5224c6417 (patch)
treeb666f3658b437da96afbef9735643e2e3418c520 /js/helper-classes
parent6ee8b65742fbe61b4429dc8c7dc9ca33a3e43600 (diff)
downloadninja-96bfeee2e6b735b87e8482d6e2cf24d5224c6417.tar.gz
translate3DObject tool fixes.
Diffstat (limited to 'js/helper-classes')
-rwxr-xr-xjs/helper-classes/3D/hit-record.js46
-rwxr-xr-xjs/helper-classes/3D/snap-manager.js1
-rwxr-xr-xjs/helper-classes/3D/view-utils.js45
3 files changed, 69 insertions, 23 deletions
diff --git a/js/helper-classes/3D/hit-record.js b/js/helper-classes/3D/hit-record.js
index 2c60adc6..96f87c24 100755
--- a/js/helper-classes/3D/hit-record.js
+++ b/js/helper-classes/3D/hit-record.js
@@ -284,6 +284,50 @@ var HitRecord = exports.HitRecord = Object.create(Object.prototype,
284 284
285 return str; 285 return str;
286 } 286 }
287 } 287 },
288
289 test:
290 {
291 value: function()
292 {
293 var elt = this.getElement();
294 var stage = viewUtils.getStage();
295 if (elt === stage) return;
296
297 var localPt = this.calculateElementPreTransformScreenPoint();
298 var stageWorldPt = this.calculateStageWorldPoint();
299 var globalPt = this.getScreenPoint();
300 var err = false;
301
302 var test1 = viewUtils.localToGlobal( localPt, elt );
303 var dist = vecUtils.vecDist(3, test1, globalPt);
304 if (MathUtils.fpSign(dist) != 0)
305 {
306 err = true;
307 console.log( "**** transform error 1 ***** " + dist + ", localPt: " + localPt );
308 }
309
310 var stageWorldToGlobal = viewUtils.getStageWorldToGlobalMatrix();
311 var test2 = MathUtils.transformAndDivideHomogeneousPoint( stageWorldPt, stageWorldToGlobal );
312 dist = vecUtils.vecDist(3, test2, globalPt);
313 if (MathUtils.fpSign(dist) != 0)
314 {
315 err = true;
316 console.log( "**** transform error 2 ***** " + dist + ", localPt: " + localPt );
317 }
318
319 var localToGlobal = viewUtils.getLocalToGlobalMatrix( elt );
320 var globalToLocal = glmat4.inverse( localToGlobal, [] );
321 var test3 = MathUtils.transformAndDivideHomogeneousPoint( globalPt, globalToLocal );
322 dist = vecUtils.vecDist(3, test3, localPt);
323 if (MathUtils.fpSign( vecUtils.vecDist(3, test3, localPt)) != 0)
324 {
325 err = true;
326 console.log( "**** transform error 3 ***** " + dist + ", localPt: " + localPt );
327 }
328
329 if (!err) console.log( "no hitRecord error" );
330 }
331 }
288}); 332});
289 333
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js
index 9f6b9ed1..8eafa7e9 100755
--- a/js/helper-classes/3D/snap-manager.js
+++ b/js/helper-classes/3D/snap-manager.js
@@ -300,6 +300,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
300 this.deactivateDragPlane(); 300 this.deactivateDragPlane();
301 301
302 this.setLastHit( rtnHit ); 302 this.setLastHit( rtnHit );
303 //rtnHit.test(); // DEBUG CODE. REMOVE THIS
303 return rtnHit; 304 return rtnHit;
304 } 305 }
305 }, 306 },
diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js
index a72b7906..392de0be 100755
--- a/js/helper-classes/3D/view-utils.js
+++ b/js/helper-classes/3D/view-utils.js
@@ -112,6 +112,13 @@ exports.ViewUtils = Montage.create(Component, {
112 var mat = this.getMatrixFromElement(elt); 112 var mat = this.getMatrixFromElement(elt);
113 var plane = [mat[8], mat[9], mat[10], mat[11]]; 113 var plane = [mat[8], mat[9], mat[10], mat[11]];
114 114
115 var stage = this.application.ninja.currentDocument.documentRoot;
116 if (elt === stage)
117 {
118 xVec = [1,0,0];
119 yVec = [0,1,0];
120 }
121
115 // The translation value is a point on the plane 122 // The translation value is a point on the plane
116 this.pushViewportObj( elt ); 123 this.pushViewportObj( elt );
117 var ptOnPlane = this.getCenterOfProjection(); 124 var ptOnPlane = this.getCenterOfProjection();
@@ -137,6 +144,12 @@ exports.ViewUtils = Montage.create(Component, {
137 var stageMat = this.getMatrixFromElement(stage); 144 var stageMat = this.getMatrixFromElement(stage);
138 var stagePlane = [stageMat[8], stageMat[9], stageMat[10], stageMat[11]]; 145 var stagePlane = [stageMat[8], stageMat[9], stageMat[10], stageMat[11]];
139 146
147 if (elt === stage)
148 {
149 xVec = [1,0,0];
150 yVec = [0,1,0];
151 }
152
140 var xDot = Math.abs(vecUtils.vecDot(3, xVec, stagePlane)); 153 var xDot = Math.abs(vecUtils.vecDot(3, xVec, stagePlane));
141 var yDot = Math.abs(vecUtils.vecDot(3, yVec, stagePlane)); 154 var yDot = Math.abs(vecUtils.vecDot(3, yVec, stagePlane));
142 155
@@ -788,35 +801,23 @@ exports.ViewUtils = Montage.create(Component, {
788 } 801 }
789 }, 802 },
790 803
791 getStageWorldToGlobalMatrix: { 804 getStageWorldToGlobalMatrix:
792 value: function() { 805 {
806 value: function()
807 {
793 var stage = this.application.ninja.currentDocument.documentRoot; 808 var stage = this.application.ninja.currentDocument.documentRoot;
794 this.pushViewportObj( stage ); 809 this.pushViewportObj( stage );
795 810
796 // get the matrix to the parent 811 // put the point into screen space of the stage - requires
797 var mat = Matrix.I(4); 812 // a translation to the top/left only
798 //var projMat = Matrix.I(4).multiply( this.getPerspectiveDistFromElement(stage) );
799 var p = this.getPerspectiveDistFromElement(stage);
800 var projMat = glmat4.scale( Matrix.I(4), [p,p,p], [] );
801 projMat[11] = -1;
802 var cop = this.getCenterOfProjection(); 813 var cop = this.getCenterOfProjection();
803 var v2s = Matrix.Translation([cop[0], cop[1], 0]); 814 var v2s = Matrix.Translation([cop[0], cop[1], 0]);
804 815
805 //mat = v2s.multiply( projMat );
806 mat = glmat4.multiply( v2s, projMat, [] );
807
808 // offset to the parent
809 var offset = this.getElementOffset( stage );
810 var offMat = Matrix.Translation([offset[0], offset[1], 0]);
811 //mat = offMat.multiply( mat );
812 glmat4.multiply( offMat, mat, mat );
813
814 this.popViewportObj(); 816 this.popViewportObj();
815 817
816 // var mat2 = this.getLocalToGlobalMatrix( stage.parentElement ); 818 // append the localToGlobal matrix of the stage.
817 var mat2 = this.getLocalToGlobalMatrix( this._rootElement ); 819 var mat = this.getLocalToGlobalMatrix( stage );
818 //var mat = mat2.multiply( mat ); 820 glmat4.multiply( mat, v2s );
819 glmat4.multiply( mat2, mat, mat );
820 821
821 return mat; 822 return mat;
822 } 823 }