aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom
diff options
context:
space:
mode:
authorPushkar Joshi2012-03-20 10:24:15 -0700
committerPushkar Joshi2012-03-20 10:24:15 -0700
commit92bc54df4acfec849568ab619150a5da49c087fa (patch)
tree0ecf92f98a29c10045b1e8e2e764793868cfcdef /js/lib/geom
parentc0bd8d8efcc501d4efa116a7cc0e802fd4e9f3e9 (diff)
downloadninja-92bc54df4acfec849568ab619150a5da49c087fa.tar.gz
revert to using the angle without flipping its sign...fixing some minor bugs and code cleanup
GOOD status before doing 3D unprojection step
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-xjs/lib/geom/brush-stroke.js52
1 files changed, 34 insertions, 18 deletions
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js
index 68b9110f..afeaf6e6 100755
--- a/js/lib/geom/brush-stroke.js
+++ b/js/lib/geom/brush-stroke.js
@@ -24,6 +24,7 @@ var BrushStroke = function GLBrushStroke() {
24 this._BBoxMin = [0, 0, 0]; 24 this._BBoxMin = [0, 0, 0];
25 this._BBoxMax = [0, 0, 0]; 25 this._BBoxMax = [0, 0, 0];
26 this._dirty = true; 26 this._dirty = true;
27 this._isInit = false;
27 this._addedSamples = false; 28 this._addedSamples = false;
28 this._storedOrigPoints = false; 29 this._storedOrigPoints = false;
29 30
@@ -286,7 +287,7 @@ var BrushStroke = function GLBrushStroke() {
286 287
287 this.computeMetaGeometry = function() { 288 this.computeMetaGeometry = function() {
288 var numPoints = this._Points.length; 289 var numPoints = this._Points.length;
289 if (this._addedSamples === false){ 290 if (this._isInit === false){
290 //**** add samples to the long sections of the path --- Catmull-Rom spline interpolation ***** 291 //**** add samples to the long sections of the path --- Catmull-Rom spline interpolation *****
291 // instead of the following, may use 4-point subdivision iterations over continuous regions of 'long' segments 292 // instead of the following, may use 4-point subdivision iterations over continuous regions of 'long' segments
292 // look at http://www.gvu.gatech.edu/~jarek/Split&Tweak/ for formula 293 // look at http://www.gvu.gatech.edu/~jarek/Split&Tweak/ for formula
@@ -325,16 +326,12 @@ var BrushStroke = function GLBrushStroke() {
325 } 326 }
326 this._Points = newSampledPoints.slice(0); 327 this._Points = newSampledPoints.slice(0);
327 newSampledPoints = []; 328 newSampledPoints = [];
328 console.log("Inserted "+numInsertedPoints+" additional CatmullRom points");
329 this._addedSamples = true;
330 this._dirty=true; 329 this._dirty=true;
331 } //if we need to add samples to this curve (done only once)
332 330
333 //build a copy of the original points...this should be done only once 331 //store the original points
334 if (this._storedOrigPoints === false) {
335 this._OrigPoints = this._Points.slice(0); 332 this._OrigPoints = this._Points.slice(0);
336 this._storedOrigPoints = true; 333 this._isInit = true;
337 } //if we need to store a copy of the original points (done only once) 334 } //if have not initialized this brush stroke yet
338 335
339 if (this._dirty) { 336 if (this._dirty) {
340 this._Points = this._OrigPoints.slice(0); 337 this._Points = this._OrigPoints.slice(0);
@@ -377,7 +374,9 @@ var BrushStroke = function GLBrushStroke() {
377 374
378 //increase the bbox given the stroke width and the angle (in case of calligraphic brush) 375 //increase the bbox given the stroke width and the angle (in case of calligraphic brush)
379 var bboxPadding = this._strokeWidth/2; 376 var bboxPadding = this._strokeWidth/2;
380 if (this.__strokeUseCalligraphic) { 377 //if (this._strokeUseCalligraphic) {
378 //todo re-enable this if check once we are able to change the left and top of the brush canvas
379 if (false){
381 this._BBoxMin[0]-= bboxPadding*Math.cos(this._strokeAngle); 380 this._BBoxMin[0]-= bboxPadding*Math.cos(this._strokeAngle);
382 this._BBoxMin[1]-= bboxPadding*Math.sin(this._strokeAngle); 381 this._BBoxMin[1]-= bboxPadding*Math.sin(this._strokeAngle);
383 this._BBoxMax[0]+= bboxPadding*Math.cos(this._strokeAngle); 382 this._BBoxMax[0]+= bboxPadding*Math.cos(this._strokeAngle);
@@ -388,9 +387,9 @@ var BrushStroke = function GLBrushStroke() {
388 this._BBoxMax[d]+= bboxPadding; 387 this._BBoxMax[d]+= bboxPadding;
389 }//for every dimension d from 0 to 2 388 }//for every dimension d from 0 to 2
390 } 389 }
391
392 } //if this was dirty 390 } //if this was dirty
393 this._dirty = false; 391 this._dirty = false;
392
394 }; 393 };
395 394
396 this.buildBuffers = function () { 395 this.buildBuffers = function () {
@@ -402,32 +401,47 @@ var BrushStroke = function GLBrushStroke() {
402 this.render = function () { 401 this.render = function () {
403 // get the world 402 // get the world
404 var world = this.getWorld(); 403 var world = this.getWorld();
405 if (!world) throw( "null world in brushstroke render" ); 404 if (!world){
406 405 throw( "null world in brushstroke render" );
407 // get the context 406 }
408 var ctx = world.get2DContext();
409 if (!ctx) throw ("null context in brushstroke render");
410 407
411 var numPoints = this.getNumPoints(); 408 var numPoints = this.getNumPoints();
412 if (numPoints === 0) { 409 if (numPoints === 0) {
413 return; //nothing to do for empty paths 410 return; //nothing to do for empty paths
414 } 411 }
415 412
416 ctx.save();
417
418 this.computeMetaGeometry(); 413 this.computeMetaGeometry();
419 var bboxMin = this.getBBoxMin(); 414 var bboxMin = this.getBBoxMin();
420 var bboxMax = this.getBBoxMax(); 415 var bboxMax = this.getBBoxMax();
421 var bboxWidth = bboxMax[0] - bboxMin[0]; 416 var bboxWidth = bboxMax[0] - bboxMin[0];
422 var bboxHeight = bboxMax[1] - bboxMin[1]; 417 var bboxHeight = bboxMax[1] - bboxMin[1];
423 418
424 //assign the new width and height as the canvas dimensions through the canvas controller 419
425 if (this._canvas) { 420 if (this._canvas) {
421 // this seems to produce drift as the stroke size is changed smoothly...bug due to floating point round off
422 //get the old left, top, width, and height
423// var oldLeft = parseInt(CanvasController.getProperty(this._canvas, "left"));
424// var oldTop = parseInt(CanvasController.getProperty(this._canvas, "top"));
425// var oldWidth = parseInt(CanvasController.getProperty(this._canvas, "width"));
426// var oldHeight = parseInt(CanvasController.getProperty(this._canvas, "height"));
427// var newLeft = oldLeft - parseInt((bboxWidth-oldWidth)*0.5);
428// var newTop = oldTop - parseInt((bboxHeight-oldHeight)*0.5);
429//
430// //assign the new width and height as the canvas dimensions through the canvas controller
431// CanvasController.setProperty(this._canvas, "left", newLeft+"px");
432// CanvasController.setProperty(this._canvas, "top", newTop+"px");*/
426 CanvasController.setProperty(this._canvas, "width", bboxWidth+"px"); 433 CanvasController.setProperty(this._canvas, "width", bboxWidth+"px");
427 CanvasController.setProperty(this._canvas, "height", bboxHeight+"px"); 434 CanvasController.setProperty(this._canvas, "height", bboxHeight+"px");
428 this._canvas.elementModel.shapeModel.GLWorld.setViewportFromCanvas(this._canvas); 435 this._canvas.elementModel.shapeModel.GLWorld.setViewportFromCanvas(this._canvas);
436
429 } 437 }
430 438
439 //get the context
440 var ctx = world.get2DContext();
441 if (!ctx) {
442 throw ("null context in brushstroke render");
443 }
444 ctx.save();
431 ctx.clearRect(0, 0, bboxWidth, bboxHeight); 445 ctx.clearRect(0, 0, bboxWidth, bboxHeight);
432 this.drawToContext(ctx, bboxMin[0], bboxMin[1]); 446 this.drawToContext(ctx, bboxMin[0], bboxMin[1]);
433 ctx.restore(); 447 ctx.restore();
@@ -529,6 +543,7 @@ var BrushStroke = function GLBrushStroke() {
529 retObject.strokeUseCalligraphic = this._strokeUseCalligraphic; 543 retObject.strokeUseCalligraphic = this._strokeUseCalligraphic;
530 retObject.strokeAngle = this._strokeAngle; 544 retObject.strokeAngle = this._strokeAngle;
531 retObject.strokeAmountSmoothing = this._strokeAmountSmoothing; 545 retObject.strokeAmountSmoothing = this._strokeAmountSmoothing;
546 retObject.addedSamples = this._addedSamples;
532 return retObject; 547 return retObject;
533 }; 548 };
534 549
@@ -548,6 +563,7 @@ var BrushStroke = function GLBrushStroke() {
548 this._strokeUseCalligraphic = jo.strokeUseCalligraphic; 563 this._strokeUseCalligraphic = jo.strokeUseCalligraphic;
549 this._strokeAngle = jo.strokeAngle; 564 this._strokeAngle = jo.strokeAngle;
550 this._strokeAmountSmoothing = jo.strokeAmountSmoothing; 565 this._strokeAmountSmoothing = jo.strokeAmountSmoothing;
566 this._addedSamples = jo.addedSamples;
551 567
552 //force a re-computation of meta-geometry before rendering 568 //force a re-computation of meta-geometry before rendering
553 this._isDirty = true; 569 this._isDirty = true;