aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/backup-delete/GLSubpath.js
diff options
context:
space:
mode:
authorJonathan Duran2012-03-06 11:38:39 -0800
committerJonathan Duran2012-03-06 11:38:39 -0800
commit342fb451bd251358068a0dcb10e9dc218b79a176 (patch)
treeaa0195d581c3934fb6dc09981506b3c070002806 /js/helper-classes/backup-delete/GLSubpath.js
parent2815adfd7c19b3dff89dc3e1bda9af8d30dca8d6 (diff)
downloadninja-342fb451bd251358068a0dcb10e9dc218b79a176.tar.gz
Squashed commit of the following:
commit 1cd89d4d06e3a8f2c221628b19cf26a2c69f5d3f Author: Jose Antonio Marquez <kgq387@motorola.com> Date: Tue Mar 6 11:24:25 2012 -0800 Fixing WebGL not available bug commit 84332ab81c1b445195f1d9be8bbeae0725c8e758 Author: Valerio Virgillito <valerio@motorola.com> Date: Tue Mar 6 10:58:25 2012 -0800 Squashed commit of preload-fix into Master - Requiring all the previously pre-loaded files - RDGE, Codemirror and gl-matrix are not included via a script tag. Signed-off-by: Valerio Virgillito <valerio@motorola.com> commit 13f52cf0c74f53a919fa864f86669e8155f82961 Merge: dced508 abc04f3 Author: Valerio Virgillito <valerio@motorola.com> Date: Fri Mar 2 15:46:11 2012 -0800 Merge pull request #93 from imix23ways/Timeline Timeline: Critical bug fixes commit dced508bb19a7bcd467ff1b86b5df5bbec4be794 Merge: 0aeb400 cc772ef Author: Valerio Virgillito <valerio@motorola.com> Date: Fri Mar 2 15:45:35 2012 -0800 Merge pull request #92 from mqg734/WebGLFixes Selection Tool Fixes for elements flying off into space when they overlap commit 0aeb400070762cf01d83cf9f9ee25a5595098b7f Merge: ff0a956 aabb48a Author: Valerio Virgillito <valerio@motorola.com> Date: Fri Mar 2 14:05:21 2012 -0800 Merge pull request #94 from ericguzman/PresetsPanel Presets Panel - Fix single-click activation, and transition cut-off bug. commit cc772ef3333ed419d269a2bda7aea5b0150a7bd9 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Fri Mar 2 11:34:58 2012 -0800 Fixing flying off into space bug for translate tool too. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit abc04f3d50311ed1c21067344bc7e448686f8c5c Author: Jonathan Duran <jduran@motorola.com> Date: Fri Mar 2 11:26:25 2012 -0800 Timeline Fix timing function Signed-off-by: Jonathan Duran <jduran@motorola.com> commit aabb48a1c8d34bc968f4c6b0ffee4e31c1d5d286 Author: Eric Guzman <ericg@motorola.com> Date: Fri Mar 2 11:22:44 2012 -0800 Presets Panel - Fix single-click activation, and transition cut-off bug. Use double-click as the activation event for transition presets. Also fixed the bug when applying a style preset before the transition preset, which disabled transitions after the first one. commit f3207f39ea9d8c1c34246217a23d3a689671903d Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Fri Mar 2 11:21:29 2012 -0800 Don't draw transform handles if the stage is the target element. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 5425be91e7125c22955b4459a62412ff574e49a8 Author: Jonathan Duran <jduran@motorola.com> Date: Fri Mar 2 11:11:48 2012 -0800 Timeline: Fix for animation iteration count Add default webkit css properties to allow animations with integer iteration counts. Signed-off-by: Jonathan Duran <jduran@motorola.com> commit 1760bac1da9218315ad1bacdcf3a157495a049e8 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Fri Mar 2 10:48:41 2012 -0800 Fix for jumping issue when moving items that have any 3d on them. We can't translate 3d moves into 2d space due to perspective, so we must update the matrix3d values instead of the top-left values if items have 3d. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 2c04935f0ccb1cb7c98371fc10b43155f2d956c4 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 22:20:06 2012 -0800 Fix for elements flying off into space when moving elements that overlap. This was happening because our hit record's element and the browser's element from point did not match. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 50058746779f714ed9b0287f49e56c9f0d35593e Merge: 500426d ff0a956 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 21:49:44 2012 -0800 Merge branch 'refs/heads/ninja-internal' into WebGLFixes commit 500426dea0ca95a6b45be8ea8d132cfdb4d2c940 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 10:11:39 2012 -0800 Fixed logic error when resizing with the top-left transform handles. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 7980d9bde2b43aa5a494ddf6f1db5c4959a57b91 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 10:04:15 2012 -0800 Re-fixing IKNinja-940 - Can't select objects when in side/top view. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit f04cc0146d8f7573628678613a99c270116768e4 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Wed Feb 29 16:45:40 2012 -0800 Last-used material (instead of FlatMaterial) is applied to shape when turning on use WebGL checkbox in the PI. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> Signed-off-by: Jonathan Duran <jduran@motorola.com>
Diffstat (limited to 'js/helper-classes/backup-delete/GLSubpath.js')
-rwxr-xr-xjs/helper-classes/backup-delete/GLSubpath.js1185
1 files changed, 1185 insertions, 0 deletions
diff --git a/js/helper-classes/backup-delete/GLSubpath.js b/js/helper-classes/backup-delete/GLSubpath.js
new file mode 100755
index 00000000..f3d8ad36
--- /dev/null
+++ b/js/helper-classes/backup-delete/GLSubpath.js
@@ -0,0 +1,1185 @@
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;