aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/GLSubpath.js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-03-06 14:09:44 -0800
committerNivesh Rajbhandari2012-03-06 14:09:44 -0800
commit792793cd3991032b4840ade67f98ae8eae2d30a0 (patch)
tree69d3df003d2bb58fa1ab562fbd1058ff91851f01 /js/helper-classes/RDGE/GLSubpath.js
parent2346d8ab9db06573d8672c64988c46b6c672e015 (diff)
parent1cd89d4d06e3a8f2c221628b19cf26a2c69f5d3f (diff)
downloadninja-792793cd3991032b4840ade67f98ae8eae2d30a0.tar.gz
Merge branch 'refs/heads/ninja-internal' into WebGLFixes
Diffstat (limited to 'js/helper-classes/RDGE/GLSubpath.js')
-rwxr-xr-xjs/helper-classes/RDGE/GLSubpath.js1185
1 files changed, 0 insertions, 1185 deletions
diff --git a/js/helper-classes/RDGE/GLSubpath.js b/js/helper-classes/RDGE/GLSubpath.js
deleted file mode 100755
index f3d8ad36..00000000
--- a/js/helper-classes/RDGE/GLSubpath.js
+++ /dev/null
@@ -1,1185 +0,0 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7// Todo: This entire class should be converted to a module
8var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils;
9
10
11function SubpathOffsetPoint(pos, mapPos) {
12 this.Pos = Vector.create([pos[0],pos[1],pos[2]]);
13 this.CurveMapPos = Vector.create([mapPos[0], mapPos[1], mapPos[2]]);
14}
15
16function SubpathOffsetTriangle(v0, v1, v2) {
17 this.v0 = v0;
18 this.v1 = v1;
19 this.v2 = v2;
20 this.n = Vector.create([0,0,1]); //replace with the actual cross product later
21}
22
23function sortNumberAscending(a,b){
24 return a-b;
25}
26function sortNumberDescending(a,b){
27 return b-a;
28}
29function SegmentIntersections(){
30 this.paramArray = [];
31}
32
33///////////////////////////////////////////////////////////////////////
34// Class GLSubpath
35// representation a sequence of cubic bezier curves.
36// Derived from class GLGeomObj
37///////////////////////////////////////////////////////////////////////
38
39function GLSubpath() {
40 ///////////////////////////////////////////////////
41 // Instance variables
42 ///////////////////////////////////////////////////
43 this._Anchors = [];
44 this._BBoxMin = [0, 0, 0];
45 this._BBoxMax = [0, 0, 0];
46 this._isClosed = false;
47
48 this._samples = []; //polyline representation of this curve
49 this._sampleParam = []; //parametric distance of samples, within [0, N], where N is # of Bezier curves (=# of anchor points if closed, =#anchor pts -1 if open)
50 this._anchorSampleIndex = []; //index within _samples corresponding to anchor points
51
52 this._UnprojectedAnchors = [];
53
54 //initially set the _dirty bit so we will construct samples
55 this._dirty = true;
56
57 //whether or not to use the canvas drawing to stroke/fill
58 this._useCanvasDrawing = true;
59
60 //the X and Y location of this subpath's canvas in stage world space of Ninja
61 this._canvasX = 0;
62 this._canvasY = 0;
63
64 //stroke information
65 this._strokeWidth = 0.0;
66 this._strokeColor = [0.4, 0.4, 0.4, 1.0];
67 this._strokeMaterial;
68 this._strokeStyle = "Solid";
69 this._materialAmbient = [0.2, 0.2, 0.2, 1.0];
70 this._materialDiffuse = [0.4, 0.4, 0.4, 1.0];
71 this._materialSpecular = [0.4, 0.4, 0.4, 1.0];
72 this._fillColor = [0.4, 0.4, 0.4, 1.0];
73 this._fillMaterial;
74 this._DISPLAY_ANCHOR_RADIUS = 5;
75 //drawing context
76 this._world = null;
77
78 //tool that owns this subpath
79 this._drawingTool = null;
80 this._planeMat = null;
81 this._planeMatInv = null;
82 this._planeCenter = null;
83
84 this.inheritedFrom = GLGeomObj;
85 this.inheritedFrom();
86
87 //used to query what the user selected, OR-able for future extensions
88 this.SEL_NONE = 0; //nothing was selected
89 this.SEL_ANCHOR = 1; //anchor point was selected
90 this.SEL_PREV = 2; //previous handle of anchor point was selected
91 this.SEL_NEXT = 4; //next handle of anchor point was selected
92 this.SEL_PATH = 8; //the path itself was selected
93 this._selectMode = this.SEL_NONE;
94 this._selectedAnchorIndex = -1;
95
96 this._SAMPLING_EPSILON = 0.5; //epsilon used for sampling the curve
97 this._DEFAULT_STROKE_WIDTH = 20; //use only if stroke width not specified
98 this._MAX_OFFSET_ANGLE = 10; //max angle (in degrees) between consecutive vectors from curve to offset path
99
100 // (current GLGeomObj complains if buildBuffers/render is added to GLSubpath prototype)
101 //buildBuffers
102 // Build the stroke vertices, normals, textures and colors
103 // Add that array data to the GPU using OpenGL data binding
104 this.buildBuffers = function () {
105 return; //no need to do anything for now
106 }//buildBuffers()
107
108 //render
109 // specify how to render the subpath in Canvas2D
110 this.render = function () {
111 // get the world
112 var world = this.getWorld();
113 if (!world) throw( "null world in subpath render" );
114
115 // get the context
116 var ctx = world.get2DContext();
117 if (!ctx) throw ("null context in subpath render")
118
119 var numAnchors = this.getNumAnchors();
120 if (numAnchors === 0)
121 return; //nothing to do for empty paths
122
123 ctx.save();
124
125 this.createSamples(); //dirty bit checked in this function...will generate a polyline representation
126 var bboxMin = this.getBBoxMin();
127 var bboxMax = this.getBBoxMax();
128 var bboxWidth = bboxMax[0] - bboxMin[0];
129 var bboxHeight = bboxMax[1] - bboxMin[1];
130 var bboxMid = Vector.create([0.5 * (bboxMax[0] + bboxMin[0]), 0.5 * (bboxMax[1] + bboxMin[1]), 0.5 * (bboxMax[2] + bboxMin[2])]);
131
132 ctx.clearRect(0, 0, bboxWidth, bboxHeight);
133
134
135 ctx.lineWidth = this._strokeWidth;
136 ctx.strokeStyle = "black";
137 if (this._strokeColor)
138 ctx.strokeStyle = MathUtils.colorToHex( this._strokeColor );
139 ctx.fillStyle = "white";
140 if (this._fillColor){
141 //ctx.fillStyle = MathUtils.colorToHex( this._fillColor );
142 var fillColorStr = "rgba("+parseInt(255*this._fillColor[0])+","+parseInt(255*this._fillColor[1])+","+parseInt(255*this._fillColor[2])+","+this._fillColor[3]+")";
143 ctx.fillStyle = fillColorStr;
144 }
145 var lineCap = ['butt','round','square'];
146 ctx.lineCap = lineCap[1];
147 ctx.beginPath();
148
149 /*
150 commenting this out for now because of Chrome bug where coincident endpoints of bezier curve cause the curve to not be rendered
151 var prevAnchor = this.getAnchor(0);
152 ctx.moveTo(prevAnchor.getPosX()-bboxMin[0],prevAnchor.getPosY()-bboxMin[1]);
153 for (var i = 1; i < numAnchors; i++) {
154 var currAnchor = this.getAnchor(i);
155 ctx.bezierCurveTo(prevAnchor.getNextX()-bboxMin[0],prevAnchor.getNextY()-bboxMin[1], currAnchor.getPrevX()-bboxMin[0], currAnchor.getPrevY()-bboxMin[1], currAnchor.getPosX()-bboxMin[0], currAnchor.getPosY()-bboxMin[1]);
156 prevAnchor = currAnchor;
157 }
158 if (this._isClosed === true) {
159 var currAnchor = this.getAnchor(0);
160 ctx.bezierCurveTo(prevAnchor.getNextX()-bboxMin[0],prevAnchor.getNextY()-bboxMin[1], currAnchor.getPrevX()-bboxMin[0], currAnchor.getPrevY()-bboxMin[1], currAnchor.getPosX()-bboxMin[0], currAnchor.getPosY()-bboxMin[1]);
161 prevAnchor = currAnchor;
162 ctx.fill();
163 }
164 */
165
166
167 var numPoints = this._samples.length/3;
168 ctx.moveTo(this._samples[0]-bboxMin[0],this._samples[1]-bboxMin[1]);
169 for (var i=0;i<numPoints;i++){
170 ctx.lineTo(this._samples[3*i]-bboxMin[0],this._samples[3*i + 1]-bboxMin[1]);
171 }
172 if (this._isClosed === true) {
173 ctx.lineTo(this._samples[0]-bboxMin[0],this._samples[1]-bboxMin[1]);
174 }
175 ctx.fill();
176 ctx.stroke();
177 ctx.restore();
178 } //render()
179
180 this.geomType = function () { return this.GEOM_TYPE_CUBIC_BEZIER; }
181
182
183 this.setWidth = function (newW) {
184 if (newW<1)
185 newW=1; //clamp minimum width to 1
186 //scale the contents of this subpath to lie within this width
187 //determine the scale factor by comparing with the old width
188 var oldWidth = this._BBoxMax[0]-this._BBoxMin[0];
189 if (oldWidth<1){
190 oldWidth=1;
191 }
192 var scaleX = newW/oldWidth;
193 if (scaleX===1){
194 return; //no need to do anything
195 }
196
197 //scale the anchor point positions such that the width of the bbox is the newW
198 var origX = this._BBoxMin[0];
199 var numAnchors = this._Anchors.length;
200 for (var i=0;i<numAnchors;i++){
201 //compute the distance from the bboxMin
202 var oldW = this._Anchors[i].getPosX() - origX;
203 var prevW = this._Anchors[i].getPrevX() - origX;
204 var nextW = this._Anchors[i].getNextX() - origX;
205
206 this._Anchors[i].setPos(origX + oldW*scaleX,this._Anchors[i].getPosY(),this._Anchors[i].getPosZ());
207 this._Anchors[i].setPrevPos(origX + prevW*scaleX,this._Anchors[i].getPrevY(),this._Anchors[i].getPrevZ());
208 this._Anchors[i].setNextPos(origX + nextW*scaleX,this._Anchors[i].getNextY(),this._Anchors[i].getNextZ());
209 }
210 this.makeDirty();
211 }
212 this.setHeight = function (newH) {
213 if (newH<1)
214 newH=1; //clamp minimum width to 1
215 //scale the contents of this subpath to lie within this height
216 //determine the scale factor by comparing with the old height
217 var oldHeight = this._BBoxMax[1]-this._BBoxMin[1];
218 if (oldHeight<1){
219 oldHeight=1;
220 }
221 var scaleY = newH/oldHeight;
222 if (scaleY===1){