diff options
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-x | js/lib/geom/brush-stroke.js | 52 | ||||
-rwxr-xr-x | js/lib/geom/circle.js | 1388 | ||||
-rwxr-xr-x | js/lib/geom/geom-obj.js | 789 | ||||
-rwxr-xr-x | js/lib/geom/line.js | 914 | ||||
-rwxr-xr-x | js/lib/geom/rectangle.js | 1449 | ||||
-rwxr-xr-x | js/lib/geom/sub-path.js | 2 |
6 files changed, 2459 insertions, 2135 deletions
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js index efd21c4a..6facdd5d 100755 --- a/js/lib/geom/brush-stroke.js +++ b/js/lib/geom/brush-stroke.js | |||
@@ -117,7 +117,7 @@ var BrushStroke = function GLBrushStroke() { | |||
117 | }; | 117 | }; |
118 | 118 | ||
119 | this.getPoint = function (index) { | 119 | this.getPoint = function (index) { |
120 | return this._Points[index]; | 120 | return this._Points[index].slice(0); |
121 | }; | 121 | }; |
122 | 122 | ||
123 | this.addPoint = function (pt) { | 123 | this.addPoint = function (pt) { |
@@ -399,7 +399,7 @@ var BrushStroke = function GLBrushStroke() { | |||
399 | 399 | ||
400 | // ***** unproject all the centered points and convert them to 2D (plane space)***** | 400 | // ***** unproject all the centered points and convert them to 2D (plane space)***** |
401 | // (undo the projection step performed by the browser) | 401 | // (undo the projection step performed by the browser) |
402 | localPoint = this._unprojectPt(localPoint, 1400); //todo get the perspective distance from the canvas | 402 | //localPoint = this._unprojectPt(localPoint, 1400); //todo get the perspective distance from the canvas |
403 | localPoint = MathUtils.transformPoint(localPoint, this._planeMatInv); | 403 | localPoint = MathUtils.transformPoint(localPoint, this._planeMatInv); |
404 | 404 | ||
405 | //add to the list of local points | 405 | //add to the list of local points |
@@ -568,17 +568,17 @@ var BrushStroke = function GLBrushStroke() { | |||
568 | } | 568 | } |
569 | ctx.save(); | 569 | ctx.save(); |
570 | ctx.clearRect(0, 0, bboxWidth, bboxHeight); | 570 | ctx.clearRect(0, 0, bboxWidth, bboxHeight); |
571 | this.drawToContext(ctx, 0, 0, false); | 571 | this.drawToContext(ctx, false); |
572 | ctx.restore(); | 572 | ctx.restore(); |
573 | } //this.render() | 573 | } //this.render() |
574 | 574 | ||
575 | this.drawToContext = function(ctx, origX, origY, drawStageWorldPts){ | 575 | this.drawToContext = function(ctx, drawStageWorldPts, stageWorldDeltaX, stageWorldDeltaY, stageWorldToScreenMat){ |
576 | var points = this._LocalPoints; | 576 | var points = this._LocalPoints; |
577 | if (drawStageWorldPts){ | 577 | if (drawStageWorldPts){ //this is usually true when we're drawing the brush stroke on the stage (no canvas yet) |
578 | points = this._Points; | 578 | points = this._Points; |
579 | } | 579 | } |
580 | var numPoints = points.length; | 580 | var numPoints = points.length; |
581 | 581 | var tempP, p; | |
582 | if (this._strokeUseCalligraphic) { | 582 | if (this._strokeUseCalligraphic) { |
583 | //build the stamp for the brush stroke | 583 | //build the stamp for the brush stroke |
584 | var t=0; | 584 | var t=0; |
@@ -623,9 +623,23 @@ var BrushStroke = function GLBrushStroke() { | |||
623 | //ctx.strokeStyle="rgba("+parseInt(255*currStrokeColor[0])+","+parseInt(255*currStrokeColor[1])+","+parseInt(255*currStrokeColor[2])+","+alphaVal+")"; | 623 | //ctx.strokeStyle="rgba("+parseInt(255*currStrokeColor[0])+","+parseInt(255*currStrokeColor[1])+","+parseInt(255*currStrokeColor[2])+","+alphaVal+")"; |
624 | ctx.translate(disp[0],disp[1]); | 624 | ctx.translate(disp[0],disp[1]); |
625 | ctx.beginPath(); | 625 | ctx.beginPath(); |
626 | ctx.moveTo(points[0][0]-origX, points[0][1]-origY); | 626 | if (drawStageWorldPts) { |
627 | tempP = points[0].slice(0); | ||
628 | tempP[0]+=stageWorldDeltaX; tempP[1]+=stageWorldDeltaY; | ||
629 | p = MathUtils.transformAndDivideHomogeneousPoint(tempP, stageWorldToScreenMat); | ||
630 | } else { | ||
631 | p = points[0]; | ||
632 | } | ||
633 | ctx.moveTo(p[0],p[1]); | ||
627 | for (var i=0;i<numPoints;i++){ | 634 | for (var i=0;i<numPoints;i++){ |
628 | ctx.lineTo(points[i][0]-origX, points[i][1]-origY); | 635 | if (drawStageWorldPts) { |
636 | tempP = points[i].slice(0); | ||
637 | tempP[0]+=stageWorldDeltaX; tempP[1]+=stageWorldDeltaY; | ||
638 | p = MathUtils.transformAndDivideHomogeneousPoint(tempP, stageWorldToScreenMat); | ||
639 | } else { | ||
640 | p = points[i]; | ||
641 | } | ||
642 | ctx.lineTo(p[0],p[1]); | ||
629 | } | 643 | } |
630 | ctx.stroke(); | 644 | ctx.stroke(); |
631 | ctx.restore(); | 645 | ctx.restore(); |
@@ -641,13 +655,27 @@ var BrushStroke = function GLBrushStroke() { | |||
641 | ctx.strokeStyle="rgba("+parseInt(255*this._strokeColor[0])+","+parseInt(255*this._strokeColor[1])+","+parseInt(255*this._strokeColor[2])+","+alphaVal+")"; | 655 | ctx.strokeStyle="rgba("+parseInt(255*this._strokeColor[0])+","+parseInt(255*this._strokeColor[1])+","+parseInt(255*this._strokeColor[2])+","+alphaVal+")"; |
642 | for (var l=0;l<numlayers;l++){ | 656 | for (var l=0;l<numlayers;l++){ |
643 | ctx.beginPath(); | 657 | ctx.beginPath(); |
644 | ctx.moveTo(points[0][0]-origX, points[0][1]-origY); | 658 | if (drawStageWorldPts) { |
659 | tempP = points[0].slice(0); | ||
660 | tempP[0]+=stageWorldDeltaX; tempP[1]+=stageWorldDeltaY; | ||
661 | p = MathUtils.transformAndDivideHomogeneousPoint(tempP, stageWorldToScreenMat); | ||
662 | } else { | ||
663 | p = points[0]; | ||
664 | } | ||
665 | ctx.moveTo(p[0],p[1]); | ||
645 | if (numPoints===1){ | 666 | if (numPoints===1){ |
646 | //display a tiny segment as a single point | 667 | //display a tiny segment as a single point |
647 | ctx.lineTo(points[0][0]-origX, points[0][1]-origY+0.01); | 668 | ctx.lineTo(p[0],p[1]+0.01); |
648 | } | 669 | } |
649 | for (var i=1;i<numPoints;i++){ | 670 | for (var i=1;i<numPoints;i++){ |
650 | ctx.lineTo(points[i][0]-origX, points[i][1]-origY); | 671 | if (drawStageWorldPts) { |
672 | tempP = points[i].slice(0); | ||
673 | tempP[0]+=stageWorldDeltaX; tempP[1]+=stageWorldDeltaY; | ||
674 | p = MathUtils.transformAndDivideHomogeneousPoint(tempP, stageWorldToScreenMat); | ||
675 | } else { | ||
676 | p = points[i]; | ||
677 | } | ||
678 | ctx.lineTo(p[0],p[1]); | ||
651 | } | 679 | } |
652 | ctx.lineWidth=2*l+minStrokeWidth; | 680 | ctx.lineWidth=2*l+minStrokeWidth; |
653 | ctx.stroke(); | 681 | ctx.stroke(); |
@@ -740,7 +768,7 @@ var BrushStroke = function GLBrushStroke() { | |||
740 | 768 | ||
741 | }; //function BrushStroke ...class definition | 769 | }; //function BrushStroke ...class definition |
742 | 770 | ||
743 | BrushStroke.prototype = new GeomObj(); | 771 | BrushStroke.prototype = Object.create(GeomObj, {}); |
744 | 772 | ||
745 | BrushStroke.prototype._CatmullRomSplineInterpolate = function(ctrlPts, t) | 773 | BrushStroke.prototype._CatmullRomSplineInterpolate = function(ctrlPts, t) |
746 | { | 774 | { |
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index 218dcfa6..425b869a 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js | |||
@@ -7,705 +7,801 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
7 | var GeomObj = require("js/lib/geom/geom-obj").GeomObj; | 7 | var GeomObj = require("js/lib/geom/geom-obj").GeomObj; |
8 | var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; | 8 | var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; |
9 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; | 9 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; |
10 | var drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils; | ||
11 | var vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; | ||
12 | |||
10 | /////////////////////////////////////////////////////////////////////// | 13 | /////////////////////////////////////////////////////////////////////// |
11 | // Class GLCircle | 14 | // Class GLCircle |
12 | // GL representation of a circle. | 15 | // GL representation of a circle. |
13 | // Derived from class GLGeomObj | 16 | // Derived from class GLGeomObj |
14 | // The position and dimensions of the stroke, fill, and inner Radius should be in pixels | 17 | // The position and dimensions of the stroke, fill, and inner Radius should be in pixels |
15 | /////////////////////////////////////////////////////////////////////// | 18 | /////////////////////////////////////////////////////////////////////// |
16 | var Circle = function GLCircle() { | 19 | exports.Circle = Object.create(GeomObj, { |
17 | 20 | ||
18 | this.init = function( world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor, innerRadius, strokeMaterial, fillMaterial, strokeStyle) { | 21 | /////////////////////////////////////////////////////////////////////// |
19 | /////////////////////////////////////////////////////////////////////// | 22 | // Instance variables |
20 | // Instance variables | 23 | /////////////////////////////////////////////////////////////////////// |
21 | /////////////////////////////////////////////////////////////////////// | 24 | _width: { value : 2.0, writable: true }, |
22 | this._width = 2.0; | 25 | _height: { value : 2.0, writable: true }, |
23 | this._height = 2.0; | 26 | _xOffset: { value : 0, writable: true }, |
24 | this._xOffset = 0; | 27 | _yOffset: { value : 0, writable: true }, |
25 | this._yOffset = 0; | 28 | |
26 | 29 | _radius: { value : 2.0, writable: true }, | |
27 | this._radius = 2.0; | 30 | _strokeWidth: { value : 0.25, writable: true }, |
28 | this._strokeWidth = 0.25; | 31 | _innerRadius: { value : 0, writable: true }, |
29 | this._innerRadius = 0; | 32 | _ovalHeight: { value : 4.0, writable: true }, |
30 | 33 | _strokeStyle: { value : "Solid", writable: true }, | |
31 | this._ovalHeight = this._ovalHeight = 2.0 * this._radius; | 34 | _aspectRatio: { value : 1.0, writable: true }, |
32 | 35 | ||
33 | this._strokeStyle = "Solid"; | 36 | init: { |
34 | 37 | value: function(world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor, innerRadius, strokeMaterial, fillMaterial, strokeStyle) { | |
35 | this._aspectRatio = 1.0; | 38 | if(arguments.length > 0) { |
36 | 39 | this._width = width; | |
37 | if (arguments.length > 0) { | 40 | this._height = height; |
38 | this._width = width; | 41 | this._xOffset = xOffset; |
39 | this._height = height; | 42 | this._yOffset = yOffset; |
40 | this._xOffset = xOffset; | 43 | this._ovalHeight = 2.0 * this._radius; |
41 | this._yOffset = yOffset; | 44 | |
42 | 45 | this._strokeWidth = strokeSize; | |
43 | this._strokeWidth = strokeSize; | 46 | this._innerRadius = innerRadius; |
44 | this._innerRadius = innerRadius; | 47 | this._strokeColor = strokeColor; |
45 | this._strokeColor = strokeColor; | 48 | this._fillColor = fillColor; |
46 | this._fillColor = fillColor; | 49 | |
47 | 50 | this._strokeStyle = strokeStyle; | |
48 | this._strokeStyle = strokeStyle; | 51 | |
49 | } | 52 | this._matrix = Matrix.I(4); |
50 | 53 | //this._matrix[12] = xOffset; | |
51 | this.m_world = world; | 54 | //this._matrix[13] = yOffset; |
52 | 55 | } | |
53 | if(strokeMaterial){ | 56 | |
54 | this._strokeMaterial = strokeMaterial; | 57 | this.m_world = world; |
55 | } else { | ||
56 | this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | ||
57 | } | ||
58 | 58 | ||
59 | if(fillMaterial) { | 59 | if(strokeMaterial) { |
60 | this._fillMaterial = fillMaterial; | 60 | this._strokeMaterial = strokeMaterial; |
61 | } else { | 61 | } else { |
62 | this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | 62 | this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); |
63 | } | ||
64 | |||
65 | if(fillMaterial) { | ||
66 | this._fillMaterial = fillMaterial; | ||
67 | } else { | ||
68 | this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.g |