aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D/draw-utils.js
diff options
context:
space:
mode:
authorPushkar Joshi2012-05-22 13:22:26 -0700
committerPushkar Joshi2012-05-22 13:22:26 -0700
commit01dbc1f329a95bc7e3b93224543d88ad5bdbd315 (patch)
treeceb527713554f506c537168e36a10452cd09ad10 /js/helper-classes/3D/draw-utils.js
parentb9262c831952e77135b79c2de7c455d5e7ff0589 (diff)
parentc37a876b373ddc7cb19277aaeaa6bb2d2d5a50ac (diff)
downloadninja-01dbc1f329a95bc7e3b93224543d88ad5bdbd315.tar.gz
Merge branch 'master' into brushtool
Diffstat (limited to 'js/helper-classes/3D/draw-utils.js')
-rwxr-xr-xjs/helper-classes/3D/draw-utils.js61
1 files changed, 51 insertions, 10 deletions
diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js
index 7bd77c3a..88830964 100755
--- a/js/helper-classes/3D/draw-utils.js
+++ b/js/helper-classes/3D/draw-utils.js
@@ -583,17 +583,25 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
583 // get a point that lies on the plane 583 // get a point that lies on the plane
584 var ptOnPlane = MathUtils.getPointOnPlane(this._workingPlane); 584 var ptOnPlane = MathUtils.getPointOnPlane(this._workingPlane);
585 585
586 // define the grid parameters
587 var width,
588 height,
589 nLines = 10;
590
591// if(this.application.ninja.documentController.webTemplate) {
592 if(this.application.ninja.currentDocument.documentRoot.id !== "UserContent") {
593 width = this.application.ninja.currentDocument.documentRoot.scrollWidth;
594 height = this.application.ninja.currentDocument.documentRoot.scrollHeight;
595 } else {
596 width = this.snapManager.getStageWidth();
597 height = this.snapManager.getStageHeight();
598 }
586 // get a matrix from working plane space to the world 599 // get a matrix from working plane space to the world
587 var mat = this.getPlaneToWorldMatrix(zAxis, ptOnPlane); 600 var mat = this.getPlaneToWorldMatrix(zAxis, ptOnPlane);
588 var tMat = Matrix.Translation( [0.5*this.snapManager.getStageWidth(), 0.5*this.snapManager.getStageHeight(),0] ); 601 var tMat = Matrix.Translation( [0.5*width, 0.5*height, 0] );
589 //mat = tMat.multiply(mat); 602 //mat = tMat.multiply(mat);
590 glmat4.multiply( tMat, mat, mat); 603 glmat4.multiply( tMat, mat, mat);
591 604
592 // define the grid parameters
593 var width = this.snapManager.getStageWidth(),
594 height = this.snapManager.getStageHeight();
595 var nLines = 10;
596
597 // the positioning of the grid may depend on the view direction. 605 // the positioning of the grid may depend on the view direction.
598 var stage = this.snapManager.getStage(); 606 var stage = this.snapManager.getStage();
599 var viewMat = this.viewUtils.getMatrixFromElement(stage); 607 var viewMat = this.viewUtils.getMatrixFromElement(stage);
@@ -643,6 +651,21 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
643 this._lineColor = saveColor; 651 this._lineColor = saveColor;
644 this._drawingContext.lineWidth = saveLineWidth; 652 this._drawingContext.lineWidth = saveLineWidth;
645 653
654 if(this.application.ninja.currentDocument.documentRoot.id !== "UserContent") {
655 // draw an outline around the body
656 var stagePt = MathUtils.getPointOnPlane([0,0,1,0]);
657 var stageMat = this.getPlaneToWorldMatrix([0,0,1], stagePt);
658 // glmat4.multiply( tMat, stageMat, stageMat);
659 pt0 = [0, 0, 0];
660 pt1 = [0, height, 0];
661 delta = [width, 0, 0];
662 this.drawGridLines(pt0, pt1, delta, stageMat, 2);
663 pt0 = [0, 0, 0];
664 pt1 = [width, 0, 0];
665 delta = [0, height, 0];
666 this.drawGridLines(pt0, pt1, delta, stageMat, 2);
667 }
668
646 // draw the lines 669 // draw the lines
647 this.redrawGridLines(); 670 this.redrawGridLines();
648 671
@@ -662,6 +685,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
662 var offset = this.viewUtils.getElementOffset(this._sourceSpaceElt); 685 var offset = this.viewUtils.getElementOffset(this._sourceSpaceElt);
663 offset[2] = 0; 686 offset[2] = 0;
664 this.viewUtils.setViewportObj(this._sourceSpaceElt); 687 this.viewUtils.setViewportObj(this._sourceSpaceElt);
688 var sourceSpaceMat = this.viewUtils.getLocalToGlobalMatrix( this._sourceSpaceElt );
665 for (var i = 0; i < nLines; i++) { 689 for (var i = 0; i < nLines; i++) {
666 // transform the points from working plane space to world space 690 // transform the points from working plane space to world space
667 //var t0 = mat.multiply(p0), 691 //var t0 = mat.multiply(p0),
@@ -671,8 +695,10 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
671 695
672 // transform from world space to global screen space 696 // transform from world space to global screen space
673 if (this._sourceSpaceElt) { 697 if (this._sourceSpaceElt) {
674 t0 = this.viewUtils.localToGlobal(t0, this._sourceSpaceElt); 698// t0 = this.viewUtils.localToGlobal(t0, this._sourceSpaceElt);
675 t1 = this.viewUtils.localToGlobal(t1, this._sourceSpaceElt); 699// t1 = this.viewUtils.localToGlobal(t1, this._sourceSpaceElt);
700 t0 = this.viewUtils.localToGlobal2(t0, sourceSpaceMat);
701 t1 = this.viewUtils.localToGlobal2(t1, sourceSpaceMat);
676 } 702 }
677 703
678 // create a line from the endpoints 704 // create a line from the endpoints
@@ -741,12 +767,27 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
741 this._drawingContext.lineWidth = 0.25; 767 this._drawingContext.lineWidth = 0.25;
742 768
743 // draw the lines 769 // draw the lines
744 var nLines = this._gridLineArray.length; 770 var line,
771 nLines = this._gridLineArray.length;
772 if(this.application.ninja.currentDocument.documentRoot.id !== "UserContent") {
773 nLines = this._gridLineArray.length-4;
774 }
775
745 for (var i = 0; i < nLines; i++) { 776 for (var i = 0; i < nLines; i++) {
746 var line = this._gridLineArray[i]; 777 line = this._gridLineArray[i];
747 this.drawIntersectedLine(line, this._drawingContext); 778 this.drawIntersectedLine(line, this._drawingContext);
748 } 779 }
749 780
781 if(this.application.ninja.currentDocument.documentRoot.id !== "UserContent") {
782 this._lineColor = "red";
783 i = nLines;
784 nLines += 4;
785 for (; i < nLines; i++) {
786 line = this._gridLineArray[i];
787 this.drawIntersectedLine(line, this._drawingContext);
788 }
789 }
790
750 this.popState(); 791 this.popState();
751 } 792 }
752 }, 793 },