aboutsummaryrefslogtreecommitdiff
path: root/js/lib
diff options
context:
space:
mode:
authorAnanya Sen2012-04-04 13:20:15 -0700
committerAnanya Sen2012-04-04 13:20:15 -0700
commit22ade57a30b45774882028eef4ab5a5bffe1a624 (patch)
tree52e589450eeb8adf7e11b66bd222fec5fa66c963 /js/lib
parentbec4cde986975d1cc5f1d2791fdb18548fc2d72a (diff)
parent8482e23cd9b8c4700b5130f2588e5eb24d376536 (diff)
downloadninja-22ade57a30b45774882028eef4ab5a5bffe1a624.tar.gz
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into Codeview-improvements
Diffstat (limited to 'js/lib')
-rwxr-xr-xjs/lib/drawing/world.js19
-rwxr-xr-xjs/lib/geom/brush-stroke.js638
-rwxr-xr-xjs/lib/geom/geom-obj.js1
-rwxr-xr-xjs/lib/geom/sub-path.js18
-rwxr-xr-xjs/lib/nj-base.js13
5 files changed, 459 insertions, 230 deletions
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js
index fec6a478..e348f5e8 100755
--- a/js/lib/drawing/world.js
+++ b/js/lib/drawing/world.js
@@ -527,7 +527,7 @@ World.prototype.clearTree = function() {
527 if (this._useWebGL) { 527 if (this._useWebGL) {
528 var root = this._rootNode; 528 var root = this._rootNode;
529 root.children = new Array(); 529 root.children = new Array();
530 g_Engine.unregisterCanvas( this._canvas.rdgeid ) 530 g_Engine.unregisterCanvas( this._canvas.rdgeid );
531 531
532 this.update( 0 ); 532 this.update( 0 );
533 this.draw(); 533 this.draw();
@@ -540,8 +540,9 @@ World.prototype.updateMaterials = function( obj, time ) {
540 var matArray = obj.getMaterialArray(); 540 var matArray = obj.getMaterialArray();
541 if (matArray) { 541 if (matArray) {
542 var n = matArray.length; 542 var n = matArray.length;
543 for (var i=0; i<n; i++) 543 for (var i=0; i<n; i++) {
544 matArray[i].update( time ); 544 matArray[i].update( time );
545 }
545 } 546 }
546 547
547 this.updateMaterials( obj.getNext(), time ); 548 this.updateMaterials( obj.getNext(), time );
@@ -553,9 +554,8 @@ World.prototype.getNDCOrigin = function() {
553 var pt = MathUtils.transformPoint( [0,0,0], this.getCameraMatInverse() ); 554 var pt = MathUtils.transformPoint( [0,0,0], this.getCameraMatInverse() );
554 var projMat = Matrix.makePerspective( this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar()); 555 var projMat = Matrix.makePerspective( this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar());
555 var ndcPt = MathUtils.transformHomogeneousPoint( pt, projMat ); 556 var ndcPt = MathUtils.transformHomogeneousPoint( pt, projMat );
556 var ndcOrigin = MathUtils.applyHomogeneousCoordinate( ndcPt );
557 557
558 return ndcOrigin; 558 return MathUtils.applyHomogeneousCoordinate( ndcPt );
559}; 559};
560 560
561World.prototype.worldToScreen = function(v) { 561World.prototype.worldToScreen = function(v) {
@@ -570,9 +570,8 @@ World.prototype.worldToScreen = function(v) {
570 var x = v2[0], y = v2[1], z = v2[2]; 570 var x = v2[0], y = v2[1], z = v2[2];
571 571
572 var h = this.getGLContext().viewportHeight/2.0, w = this.getGLContext().viewportWidth/2.0; 572 var h = this.getGLContext().viewportHeight/2.0, w = this.getGLContext().viewportWidth/2.0;
573 var x2 = w*(1 + x), y2 = h*( 1 - y ), z2 = z; 573 var x2 = w * (1 + x), y2 = h * ( 1 - y );
574 574 return [x2, y2, z, 1];
575 return [x2, y2, z2, 1];
576}; 575};
577 576
578World.prototype.screenToView = function( x, y ) { 577World.prototype.screenToView = function( x, y ) {
@@ -942,6 +941,7 @@ World.prototype.importObjectsJSON = function( jObj, parentGeomObj )
942World.prototype.importObjectJSON = function( jObj, parentGeomObj ) 941World.prototype.importObjectJSON = function( jObj, parentGeomObj )
943{ 942{
944 var type = jObj.type; 943 var type = jObj.type;
944 var BrushStroke = require("js/lib/geom/brush-stroke").BrushStroke;
945 945
946 var obj; 946 var obj;
947 switch (type) 947 switch (type)
@@ -961,6 +961,11 @@ World.prototype.importObjectJSON = function( jObj, parentGeomObj )
961 obj.importJSON( jObj ); 961 obj.importJSON( jObj );
962 break; 962 break;
963 963
964 case 6: //brush stroke
965 obj = new BrushStroke();
966 obj.importJSON(jObj);
967 break;
968
964 default: 969 default:
965 throw new Error( "Unrecognized object type: " + type ); 970 throw new Error( "Unrecognized object type: " + type );
966 break; 971 break;
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js
index 4c42539a..22209815 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<