aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-xjs/lib/geom/brush-stroke.js636
-rwxr-xr-xjs/lib/geom/circle.js113
-rwxr-xr-xjs/lib/geom/geom-obj.js189
-rwxr-xr-xjs/lib/geom/line.js80
-rwxr-xr-xjs/lib/geom/rectangle.js125
-rw-r--r--js/lib/geom/shape-primitive.js4
-rwxr-xr-xjs/lib/geom/sub-path.js18
7 files changed, 546 insertions, 619 deletions
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js
index 4c42539a..26ac42e9 100755
--- a/js/lib/geom/brush-stroke.js
+++ b/js/lib/geom/brush-stroke.js
@@ -4,9 +4,12 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */ 5</copyright> */
6 6
7// Todo: This entire class should be converted to a module
8var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; 7var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils;
9var GeomObj = require("js/lib/geom/geom-obj").GeomObj; 8var GeomObj = require("js/lib/geom/geom-obj").GeomObj;
9var CanvasController = require("js/controllers/elements/canvas-controller").CanvasController;
10var ViewUtils = require("js/helper-classes/3D/view-utils").ViewUtils;
11
12// Todo: This entire class should be converted to a module
10 13
11/////////////////////////////////////////////////////////////////////// 14///////////////////////////////////////////////////////////////////////
12// Class GLBrushStroke 15// Class GLBrushStroke
@@ -17,20 +20,20 @@ var BrushStroke = function GLBrushStroke() {
17 /////////////////////////////////////////////////// 20 ///////////////////////////////////////////////////
18 // Instance variables 21 // Instance variables
19 /////////////////////////////////////////////////// 22 ///////////////////////////////////////////////////
20 this._Points = []; 23 this._Points = []; //current state of points in stage-world space (may be different from input)
24 this._LocalPoints = []; //_Points in local coordinates...do this before rendering the points in the canvas
25 this._OrigLocalPoints = []; //copy of input points without any smoothing
26 this._stageWorldCenter = [0,0,0]; //coordinate for the canvas midPoint: a 3D vector in stage world space
21 this._BBoxMin = [0, 0, 0]; 27 this._BBoxMin = [0, 0, 0];
22 this._BBoxMax = [0, 0, 0]; 28 this._BBoxMax = [0, 0, 0];
23 this._dirty = true; 29 this._isDirty = true;
24 30 this._isInit = false;
25 //whether or not to use the canvas drawing to stroke/fill 31
26 this._useCanvasDrawing = true; 32 //the HTML5 canvas that holds this brush stroke
27 33 this._canvas = null;
28 //the X and Y location of this subpath's canvas in stage world space of Ninja
29 this._canvasX = 0;
30 this._canvasY = 0;
31 34
32 //stroke information 35 //stroke information
33 this._strokeWidth = 0.0; 36 this._strokeWidth = 1.0;
34 this._strokeColor = [0.4, 0.4, 0.4, 1.0]; 37 this._strokeColor = [0.4, 0.4, 0.4, 1.0];
35 this._secondStrokeColor = [1, 0.4, 0.4, 1.0]; 38 this._secondStrokeColor = [1, 0.4, 0.4, 1.0];
36 this._strokeHardness = 100; 39 this._strokeHardness = 100;
@@ -39,10 +42,7 @@ var BrushStroke = function GLBrushStroke() {
39 this._strokeDoSmoothing = false; 42 this._strokeDoSmoothing = false;
40 this._strokeUseCalligraphic = false; 43 this._strokeUseCalligraphic = false;
41 this._strokeAngle = 0; 44 this._strokeAngle = 0;
42 45 this._strokeAmountSmoothing = 0;
43 //the wetness of the brush (currently this is multiplied to the square of the stroke width, but todo should be changed to not depend on stroke width entirely
44 //smaller value means more samples for the path
45 this._WETNESS_FACTOR = 0.25;
46 46
47 //threshold that tells us whether two samples are too far apart 47 //threshold that tells us whether two samples are too far apart
48 this._MAX_SAMPLE_DISTANCE_THRESHOLD = 5; 48 this._MAX_SAMPLE_DISTANCE_THRESHOLD = 5;
@@ -51,7 +51,7 @@ var BrushStroke = function GLBrushStroke() {
51 this._MIN_SAMPLE_DISTANCE_THRESHOLD = 2; 51 this._MIN_SAMPLE_DISTANCE_THRESHOLD = 2;
52 52
53 //prevent extremely long paths that can take a long time to render 53 //prevent extremely long paths that can take a long time to render
54 this._MAX_ALLOWED_SAMPLES = 500; 54 this._MAX_ALLOWED_SAMPLES = 5000;
55 55
56 //drawing context 56 //drawing context
57 this._world = null; 57 this._world = null;
@@ -61,10 +61,15 @@ var BrushStroke = function GLBrushStroke() {
61 this._planeMat = null; 61 this._planeMat = null;
62 this._planeMatInv = null; 62 this._planeMatInv = null;
63 this._planeCenter = null; 63 this._planeCenter = null;
64 this._dragPlane = null;
64 65
65 ///////////////////////////////////////////////////////// 66 /////////////////////////////////////////////////////////
66 // Property Accessors/Setters 67 // Property Accessors/Setters
67 ///////////////////////////////////////////////////////// 68 /////////////////////////////////////////////////////////
69 this.setCanvas = function(c) {
70 this._canvas = c;
71 }
72
68 this.setWorld = function (world) { 73 this.setWorld = function (world) {
69 this._world = world; 74 this._world = world;
70 }; 75 };
@@ -74,7 +79,7 @@ var BrushStroke = function GLBrushStroke() {
74 }; 79 };
75 80
76 this.geomType = function () { 81 this.geomType = function () {
77 return this.GEOM_TYPE_CUBIC_BEZIER; 82 return this.GEOM_TYPE_BRUSH_STROKE;
78 }; 83 };
79 84
80 this.setDrawingTool = function (tool) { 85 this.setDrawingTool = function (tool) {
@@ -97,24 +102,15 @@ var BrushStroke = function GLBrushStroke() {
97 this._planeCenter = pc; 102 this._planeCenter = pc;
98 }; 103 };
99 104
100 this.getCanvasX = function(){ 105 this.setDragPlane = function(p){
101 return this._canvasX; 106 this._dragPlane = p;
102 };
103
104 this.getCanvasY = function(){
105 return this._canvasY;
106 };
107
108 this.setCanvasX = function(cx){
109 this._canvasX=cx;
110 };
111
112 this.setCanvasY = function(cy){
113 this._canvasY=cy;
114 }; 107 };
115 108
116 this.getNumPoints = function () { 109 this.getNumPoints = function () {
117 return this._Points.length; 110 if (this._LocalPoints.length)
111 return this._LocalPoints.length;
112 else
113 return this._Points.length;
118 }; 114 };
119 115
120 this.getPoint = function (index) { 116 this.getPoint = function (index) {
@@ -125,30 +121,38 @@ var BrushStroke = function GLBrushStroke() {
125 //add the point only if it is some epsilon away from the previous point 121 //add the point only if it is some epsilon away from the previous point
126 var numPoints = this._Points.length; 122 var numPoints = this._Points.length;
127 if (numPoints>0) { 123 if (numPoints>0) {
128 var threshold = this._MIN_SAMPLE_DISTANCE_THRESHOLD;//this._WETNESS_FACTOR*this._strokeWidth; 124 var threshold = this._MIN_SAMPLE_DISTANCE_THRESHOLD;
129 var prevPt = this._Points[numPoints-1]; 125 var prevPt = this._Points[numPoints-1];
130 var diffPt = [prevPt[0]-pt[0], prevPt[1]-pt[1]]; 126 var diffPt = [prevPt[0]-pt[0], prevPt[1]-pt[1]];
131 var diffPtMag = Math.sqrt(diffPt[0]*diffPt[0] + diffPt[1]*diffPt[1]); 127 var diffPtMag = Math.sqrt(diffPt[0]*diffPt[0] + diffPt[1]*diffPt[1]);
132 if (diffPtMag>threshold){ 128 if (diffPtMag>threshold){
133 this._Points.push(pt); 129 this._Points.push(pt);
134 this._dirty=true; 130 this._isDirty=true;
131 this._isInit = false;
135 } 132 }
136 } else { 133 } else {
137 this._Points.push(pt); 134 this._Points.push(pt);
138 this._dirty=true; 135 this._isDirty=true;
136 this._isInit = false;
139 } 137 }
140 }; 138 };
141 139
142 this.insertPoint = function(pt, index){ 140 this.insertPoint = function(pt, index){
143 this._Points.splice(index, 0, pt); this._dirty=true; 141 this._Points.splice(index, 0, pt);
142 this._isDirty=true;
143 this._isInit = false;
144 }; 144 };
145 145
146 this.isDirty = function(){ 146 this.isDirty = function(){
147 return this._dirty; 147 return this._isDirty;
148 }; 148 };
149 149
150 this.makeDirty = function(){ 150 this.makeDirty = function(){
151 this._dirty=true; 151 this._isDirty=true;
152 };
153
154 this.getStageWorldCenter = function() {
155 return this._stageWorldCenter;
152 }; 156 };
153 157
154 this.getBBoxMin = function () { 158 this.getBBoxMin = function () {
@@ -165,7 +169,10 @@ var BrushStroke = function GLBrushStroke() {
165 169
166 this.setStrokeWidth = function (w) { 170 this.setStrokeWidth = function (w) {
167 this._strokeWidth = w; 171 this._strokeWidth = w;
168 this._dirty=true; 172 if (this._strokeWidth<1) {
173 this._strokeWidth = 1;
174 }
175 this._isDirty=true;
169 }; 176 };
170 177
171 this.getStrokeMaterial = function () { 178 this.getStrokeMaterial = function () {
@@ -173,7 +180,7 @@ var BrushStroke = function GLBrushStroke() {
173 }; 180 };
174 181
175 this.setStrokeMaterial = function (m) { 182 this.setStrokeMaterial = function (m) {
176 this._strokeMaterial = m; 183 this._strokeMaterial = m; this._isDirty = true;
177 }; 184 };
178 185
179 this.getStrokeColor = function () { 186 this.getStrokeColor = function () {
@@ -181,27 +188,69 @@ var BrushStroke = function GLBrushStroke() {
181 }; 188 };
182 189
183 this.setStrokeColor = function (c) { 190 this.setStrokeColor = function (c) {
184 this._strokeColor = c; 191 this._strokeColor = c; this._isDirty = true;
185 }; 192 };
186 193
194 this.setFillColor = function(c){
195 return;
196 }; //NO-OP for now as we have no fill region
197