aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom
diff options
context:
space:
mode:
authorhwc4872012-04-19 13:01:43 -0700
committerhwc4872012-04-19 13:01:43 -0700
commite6a20fe64574763483dc602bd759278ccf5e5e68 (patch)
tree69defe7200206f0257fe90697136fadef59d521e /js/lib/geom
parentae7eb87564632ce7c676bd728b8ff2710ff0bb83 (diff)
parent9284c19f076dec3b47ece7dc7bcd22d74e4246c3 (diff)
downloadninja-e6a20fe64574763483dc602bd759278ccf5e5e68.tar.gz
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into Textures
Conflicts: js/lib/drawing/world.js js/lib/geom/geom-obj.js js/lib/rdge/materials/cloud-material.js js/lib/rdge/materials/deform-material.js js/lib/rdge/materials/flat-material.js js/lib/rdge/materials/material.js js/lib/rdge/materials/pulse-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
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-xjs/lib/geom/brush-stroke.js637
-rwxr-xr-xjs/lib/geom/circle.js113
-rwxr-xr-xjs/lib/geom/geom-obj.js538
-rwxr-xr-xjs/lib/geom/line.js82
-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, 744 insertions, 773 deletions
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js
index 4c42539a..743dab85 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,10 @@ 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;
45 this._strokeAmountSmoothing = 0;
42 46
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 47 // currently, brush does not support a fill region
44 //smaller value means more samples for the path 48 this.canFill = false;
45 this._WETNESS_FACTOR = 0.25;
46 49
47 //threshold that tells us whether two samples are too far apart 50 //threshold that tells us whether two samples are too far apart
48 this._MAX_SAMPLE_DISTANCE_THRESHOLD = 5; 51 this._MAX_SAMPLE_DISTANCE_THRESHOLD = 5;
@@ -51,7 +54,7 @@ var BrushStroke = function GLBrushStroke() {
51 this._MIN_SAMPLE_DISTANCE_THRESHOLD = 2; 54 this._MIN_SAMPLE_DISTANCE_THRESHOLD = 2;
52 55
53 //prevent extremely long paths that can take a long time to render 56 //prevent extremely long paths that can take a long time to render
54 this._MAX_ALLOWED_SAMPLES = 500; 57 this._MAX_ALLOWED_SAMPLES = 5000;
55 58
56 //drawing context 59 //drawing context
57 this._world = null; 60 this._world = null;
@@ -61,10 +64,15 @@ var BrushStroke = function GLBrushStroke() {
61 this._planeMat = null; 64 this._planeMat = null;
62 this._planeMatInv = null; 65 this._planeMatInv = null;
63 this._planeCenter = null; 66 this._planeCenter = null;
67 this._dragPlane = null;
64 68
65 ///////////////////////////////////////////////////////// 69 /////////////////////////////////////////////////////////
66 // Property Accessors/Setters 70 // Property Accessors/Setters
67 ///////////////////////////////////////////////////////// 71 /////////////////////////////////////////////////////////
72 this.setCanvas = function(c) {
73 this._canvas = c;
74 }
75
68 this.setWorld = function (world) { 76 this.setWorld = function (world) {
69 this._world = world; 77 this._world = world;
70 }; 78 };
@@ -74,7 +82,7 @@ var BrushStroke = function GLBrushStroke() {
74 }; 82 };
75 83
76 this.geomType = function () { 84 this.geomType = function () {
77 return this.GEOM_TYPE_CUBIC_BEZIER; 85 return this.GEOM_TYPE_BRUSH_STROKE;
78 }; 86 };
79 87
80 this.setDrawingTool = function (tool) { 88 this.setDrawingTool = function (tool) {
@@ -97,24 +105,15 @@ var BrushStroke = function GLBrushStroke() {
97 this._planeCenter = pc; 105 this._planeCenter = pc;
98 }; 106 };
99 107
100 this.getCanvasX = function(){ 108 this.setDragPlane = function(p){
101 return this._canvasX; 109 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 }; 110 };
115 111
116 this.getNumPoints = function () { 112 this.getNumPoints = function () {
117 return this._Points.length; 113 if (this._LocalPoints.length)
114 return this._LocalPoints.length;
115 else
116 return this._Points.length;
118 }; 117 };
119 118
120 this.getPoint = function (index) { 119 this.getPoint = function (index) {
@@ -125,30 +124,38 @@ var BrushStroke = function GLBrushStroke() {
125 //add the point only if it is some epsilon away from the previous point 124 //add the point only if it is some epsilon away from the previous point
126 var numPoints = this._Points.length; 125 var numPoints = this._Points.length;
127 if (numPoints>0) { 126 if (numPoints>0) {
128 var threshold = this._MIN_SAMPLE_DISTANCE_THRESHOLD;//this._WETNESS_FACTOR*this._strokeWidth; 127 var threshold = this._MIN_SAMPLE_DISTANCE_THRESHOLD;
129 var prevPt = this._Points[numPoints-1]; 128 var prevPt = this._Points[numPoints-1];
130 var diffPt = [prevPt[0]-pt[0], prevPt[1]-pt[1]]; 129 var diffPt = [prevPt[0]-pt[0], prevPt[1]-pt[1]];
131 var diffPtMag = Math.sqrt(diffPt[0]*diffPt[0] + diffPt[1]*diffPt[1]); 130 var diffPtMag = Math.sqrt(diffPt[0]*diffPt[0] + diffPt[1]*diffPt[1]);
132 if (diffPtMag>threshold){ 131 if (diffPtMag>threshold){
133 this._Points.push(pt); 132 this._Points.push(pt);
134 this._dirty=true; 133 this._isDirty=true;
134 this._isInit = false;
135 } 135 }
136 } else { 136 } else {
137 this._Points.push(pt); 137 this._Points.push(pt);
138 this._dirty=true; 138 this._isDirty=true;
139 this._isInit = false;
139 } 140 }
140 }; 141 };
141 142
142 this.insertPoint = function(pt, index){ 143 this.insertPoint = function(pt, index){
143 this._Points.splice(index, 0, pt); this._dirty=true; 144 this._Points.splice(index, 0, pt);
145 this._isDirty=true;
146 this._isInit = false;
144 }; 147 };
145 148
146 this.isDirty = function(){ 149 this.isDirty = function(){
147 return this._dirty; 150 return this._isDirty;
148 }; 151 };
149 152
150 this.makeDirty = function(){ 153 this.makeDirty = function(){
151 this._dirty=true; 154 this._isDirty=true;
155 };
156
157 this.getStageWorldCenter = function() {
158 return this._stageWorldCenter;
152 }; 159 };
153 160
154 this.getBBoxMin = function () { 161 this.getBBoxMin = function () {
@@ -165,7 +172,10 @@ var BrushStroke = function GLBrushStroke() {
165 172
166 this.setStrokeWidth = function (w) { 173 this.setStrokeWidth = function (w) {
167 this._strokeWidth = w; 174 this._strokeWidth = w;
168 this._dirty=true; 175 if (this._strokeWidth<1) {
176 this._strokeWidth = 1;
177 }
178 this._isDirty=true;
169 }; 179 };
170 180
171 this.getStrokeMaterial = function () { 181 this.getStrokeMaterial = function () {
@@ -173,7 +183,7 @@ var BrushStroke = function GLBrushStroke() {
173 }; 183 };
174 184
175 this.setStrokeMaterial = function (m) { 185 this.setStrokeMaterial = function (m) {
176 this._strokeMaterial = m; 186 this._strokeMaterial = m; this._isDirty = true;
177 }; 187 };
178 188
179 this.getStrokeColor = function () { 189 this.getStrokeColor = function () {
@@ -181,27 +191,69 @@ var BrushStroke = function GLBrushStroke() {