aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom
diff options
context:
space:
mode:
authorJohn Mayhew2012-04-02 16:28:39 -0700
committerJohn Mayhew2012-04-02 16:28:39 -0700
commitb4155fb4c33675a8a7cd37473513718043fdf0ba (patch)
tree3d8c802473f2395d53d599ec9d8b70b60a4db50c /js/lib/geom
parent5ba9aeac94c86049423fd5d4b37b277263939c13 (diff)
parentc6de22bf42be90b403491b5f87b1818d9020310c (diff)
downloadninja-b4155fb4c33675a8a7cd37473513718043fdf0ba.tar.gz
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into WorkingBranch
Conflicts: js/helper-classes/RDGE/rdge-compiled.js js/helper-classes/RDGE/runtime/GLRuntime.js js/helper-classes/RDGE/src/core/script/MeshManager.js js/helper-classes/RDGE/src/core/script/engine.js js/helper-classes/RDGE/src/core/script/fx/ssao.js js/helper-classes/RDGE/src/core/script/init_state.js js/helper-classes/RDGE/src/core/script/run_state.js js/helper-classes/RDGE/src/core/script/scenegraphNodes.js js/helper-classes/RDGE/src/core/script/utilities.js js/helper-classes/RDGE/src/tools/compile-rdge-core.bat js/helper-classes/RDGE/src/tools/compile-rdge-core.sh js/helper-classes/RDGE/src/tools/rdge-compiled.js js/lib/drawing/world.js js/lib/rdge/materials/bump-metal-material.js js/lib/rdge/materials/deform-material.js js/lib/rdge/materials/flat-material.js js/lib/rdge/materials/fly-material.js js/lib/rdge/materials/julia-material.js js/lib/rdge/materials/keleidoscope-material.js js/lib/rdge/materials/linear-gradient-material.js js/lib/rdge/materials/mandel-material.js js/lib/rdge/materials/plasma-material.js js/lib/rdge/materials/pulse-material.js js/lib/rdge/materials/radial-blur-material.js js/lib/rdge/materials/radial-gradient-material.js js/lib/rdge/materials/relief-tunnel-material.js js/lib/rdge/materials/square-tunnel-material.js js/lib/rdge/materials/star-material.js js/lib/rdge/materials/taper-material.js js/lib/rdge/materials/tunnel-material.js js/lib/rdge/materials/twist-material.js js/lib/rdge/materials/twist-vert-material.js js/lib/rdge/materials/uber-material.js js/lib/rdge/materials/water-material.js js/lib/rdge/materials/z-invert-material.js js/preloader/Preloader.js
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-xjs/lib/geom/brush-stroke.js783
-rwxr-xr-xjs/lib/geom/circle.js157
-rwxr-xr-xjs/lib/geom/geom-obj.js289
-rwxr-xr-xjs/lib/geom/line.js101
-rwxr-xr-xjs/lib/geom/rectangle.js174
-rwxr-xr-xjs/lib/geom/sub-path.js104
6 files changed, 1283 insertions, 325 deletions
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js
index 9a934928..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,30 +20,38 @@ 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];
38 this._secondStrokeColor = [1, 0.4, 0.4, 1.0];
39 this._strokeHardness = 100;
35 this._strokeMaterial = null; 40 this._strokeMaterial = null;
36 this._strokeStyle = "Solid"; 41 this._strokeStyle = "Solid";
42 this._strokeDoSmoothing = false;
43 this._strokeUseCalligraphic = false;
44 this._strokeAngle = 0;
45 this._strokeAmountSmoothing = 0;
46
47 //threshold that tells us whether two samples are too far apart
48 this._MAX_SAMPLE_DISTANCE_THRESHOLD = 5;
37 49
38 //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 50 //threshold that tells us whether two samples are too close
39 //smaller value means more samples for the path 51 this._MIN_SAMPLE_DISTANCE_THRESHOLD = 2;
40 this._WETNESS_FACTOR = 0.25;
41 52
42 //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
43 this._MAX_ALLOWED_SAMPLES = 500; 54 this._MAX_ALLOWED_SAMPLES = 5000;
44 55
45 //drawing context 56 //drawing context
46 this._world = null; 57 this._world = null;
@@ -50,10 +61,15 @@ var BrushStroke = function GLBrushStroke() {
50 this._planeMat = null; 61 this._planeMat = null;
51 this._planeMatInv = null; 62 this._planeMatInv = null;
52 this._planeCenter = null; 63 this._planeCenter = null;
64 this._dragPlane = null;
53 65
54 ///////////////////////////////////////////////////////// 66 /////////////////////////////////////////////////////////
55 // Property Accessors/Setters 67 // Property Accessors/Setters
56 ///////////////////////////////////////////////////////// 68 /////////////////////////////////////////////////////////
69 this.setCanvas = function(c) {
70 this._canvas = c;
71 }
72
57 this.setWorld = function (world) { 73 this.setWorld = function (world) {
58 this._world = world; 74 this._world = world;
59 }; 75 };
@@ -63,7 +79,7 @@ var BrushStroke = function GLBrushStroke() {
63 }; 79 };
64 80
65 this.geomType = function () { 81 this.geomType = function () {
66 return this.GEOM_TYPE_CUBIC_BEZIER; 82 return this.GEOM_TYPE_BRUSH_STROKE;
67 }; 83 };
68 84
69 this.setDrawingTool = function (tool) { 85 this.setDrawingTool = function (tool) {
@@ -86,24 +102,15 @@ var BrushStroke = function GLBrushStroke() {
86 this._planeCenter = pc; 102 this._planeCenter = pc;
87 }; 103 };
88 104
89 this.getCanvasX = function(){ 105 this.setDragPlane = function(p){
90 return this._canvasX; 106 this._dragPlane = p;
91 };
92
93 this.getCanvasY = function(){
94 return this._canvasY;
95 };
96
97 this.setCanvasX = function(cx){
98 this._canvasX=cx;
99 };
100
101 this.setCanvasY = function(cy){
102 this._canvasY=cy;
103 }; 107 };
104 108
105 this.getNumPoints = function () { 109 this.getNumPoints = function () {
106 return this._Points.length; 110 if (this._LocalPoints.length)
111 return this._LocalPoints.length;
112 else
113 return this._Points.length;
107 }; 114 };
108 115
109 this.getPoint = function (index) { 116 this.getPoint = function (index) {
@@ -114,30 +121,38 @@ var BrushStroke = function GLBrushStroke() {
114 //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
115 var numPoints = this._Points.length; 122 var numPoints = this._Points.length;
116 if (numPoints>0) { 123 if (numPoints>0) {
117 var threshold = this._WETNESS_FACTOR*this._strokeWidth; 124 var threshold = this._MIN_SAMPLE_DISTANCE_THRESHOLD;
118 var prevPt = this._Points[numPoints-1]; 125 var prevPt = this._Points[numPoints-1];
119 var diffPt = [prevPt[0]-pt[0], prevPt[1]-pt[1]]; 126 var diffPt = [prevPt[0]-pt[0], prevPt[1]-pt[1]];
120 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]);
121 if (diffPtMag>threshold){ 128 if (diffPtMag>threshold){
122 this._Points.push(pt); 129 this._Points.push(pt);
123 this._dirty=true; 130 this._isDirty=true;
131 this._isInit = false;
124 } 132 }
125 } else { 133 } else {
126 this._Points.push(pt); 134 this._Points.push(pt);
127 this._dirty=true; 135 this._isDirty=true;
136 this._isInit = false;
128 } 137 }
129 }; 138 };
130 139
131 this.insertPoint = function(pt, index){ 140 this.insertPoint = function(pt, index){
132 this._Points.splice(index, 0, pt); this._dirty=true; 141 this._Points.splice(index, 0, pt);
142 this._isDirty=true;
143 this._isInit = false;
133 }; 144 };
134 145
135 this.isDirty = function(){ 146 this.isDirty = function(){
136 return this._dirty; 147 return this._isDirty;
137 }; 148 };
138 149
139 this.makeDirty = function(){ 150 this.makeDirty = function(){
140 this._dirty=true; 151 this._isDirty=true;
152 };
153
154 this.getStageWorldCenter = function() {
155 return this._stageWorldCenter;
141 }; 156 };
142 157
143 this.getBBoxMin = function () { 158 this.getBBoxMin = function () {
@@ -154,7 +169,10 @@ var BrushStroke = function GLBrushStroke() {
154 169
155 this.setStrokeWidth = function (w) { 170 this.setStrokeWidth = function (w) {
156 this._strokeWidth = w; 171 this._strokeWidth = w;
157 this._dirty=true; 172 if (this._strokeWidth<1) {
173 this._strokeWidth = 1;
174 }
175 this._isDirty=true;
158 }; 176 };
159 177
160 this.getStrokeMaterial = function () { 178 this.getStrokeMaterial = function () {
@@ -162,7 +180,7 @@ var BrushStroke = function GLBrushStroke() {
162 }; 180 };
163 181
164 this.setStrokeMaterial = function (m) { 182 this.setStrokeMaterial = function (m) {
165 this._strokeMaterial = m; 183 this._strokeMaterial = m; this._isDirty = true;
166 }; 184 };
167 185
168 this.getStrokeColor = function () { 186 this.getStrokeColor = function () {
@@ -170,9 +188,71 @@ var BrushStroke = function GLBrushStroke() {
170 }; 188 };
171 189