diff options
author | hwc487 | 2012-03-06 16:03:26 -0800 |
---|---|---|
committer | hwc487 | 2012-03-06 16:03:26 -0800 |
commit | 855e8727b147771ff7b05e71bed481e65fe4b6b0 (patch) | |
tree | 60d7f091fcf0870495aeaa63748492dbd558619d /js/lib/geom | |
parent | 1207735f05f202b5bdc5f70c73445f8e0934a227 (diff) | |
parent | 4f498b43264327f5886e0370bd3536453d47570a (diff) | |
download | ninja-855e8727b147771ff7b05e71bed481e65fe4b6b0.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into integration
Conflicts:
js/preloader/Preloader.js
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-x | js/lib/geom/anchor-point.js | 242 | ||||
-rwxr-xr-x | js/lib/geom/brush-stroke.js | 482 | ||||
-rwxr-xr-x | js/lib/geom/circle.js | 751 | ||||
-rwxr-xr-x | js/lib/geom/geom-obj.js | 280 | ||||
-rwxr-xr-x | js/lib/geom/line.js | 488 | ||||
-rwxr-xr-x | js/lib/geom/rectangle.js | 1165 | ||||
-rw-r--r-- | js/lib/geom/shape-primitive.js | 54 | ||||
-rwxr-xr-x | js/lib/geom/sub-path.js | 1288 |
8 files changed, 4750 insertions, 0 deletions
diff --git a/js/lib/geom/anchor-point.js b/js/lib/geom/anchor-point.js new file mode 100755 index 00000000..0e9f65ea --- /dev/null +++ b/js/lib/geom/anchor-point.js | |||
@@ -0,0 +1,242 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No 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 | ///////////////////////////////////////////// | ||
8 | // Class GLAnchorPoint | ||
9 | // GL representation of a point clicked | ||
10 | // and dragged during pen tool | ||
11 | // | ||
12 | // | ||
13 | ///////////////////////////////////////////// | ||
14 | var GLAnchorPoint = function GLAnchorPoint() { | ||
15 | ///////////////////////////////////////// | ||
16 | // Instance variables | ||
17 | ///////////////////////////////////////// | ||
18 | this._x = 0.0; | ||
19 | this._y = 0.0; | ||
20 | this._z = 0.0; | ||
21 | |||
22 | this._prevX = 0.0; | ||
23 | this._prevY = 0.0; | ||
24 | this._prevZ = 0.0; | ||
25 | |||
26 | this._nextX = 0.0; | ||
27 | this._nextY = 0.0; | ||
28 | this._nextZ = 0.0; | ||
29 | }; | ||
30 | // *********** setters ************ | ||
31 | GLAnchorPoint.prototype.setPos = function (x, y, z) { | ||
32 | this._x = x; | ||
33 | this._y = y; | ||
34 | this._z = z; | ||
35 | }; | ||
36 | |||
37 | GLAnchorPoint.prototype.setPrevPos = function (x, y, z) { | ||
38 | this._prevX = x; | ||
39 | this._prevY = y; | ||
40 | this._prevZ = z; | ||
41 | }; | ||
42 | |||
43 | GLAnchorPoint.prototype.setNextPos = function (x, y, z) { | ||
44 | this._nextX = x; | ||
45 | this._nextY = y; | ||
46 | this._nextZ = z; | ||
47 | }; | ||
48 | |||
49 | GLAnchorPoint.prototype.setPrevFromNext = function () { | ||
50 | //set the previous control point by reflecting the next control point | ||
51 | var dispX = this._nextX - this._x; | ||
52 | var dispY = this._nextY - this._y; | ||
53 | var dispZ = this._nextZ - this._z; | ||
54 | |||
55 | this._prevX = this._x - dispX; | ||
56 | this._prevY = this._y - dispY; | ||
57 | this._prevZ = this._z - dispZ; | ||
58 | }; | ||
59 | |||
60 | GLAnchorPoint.prototype.setNextFromPrev = function () { | ||
61 | //set the previous control point by reflecting the next control point | ||
62 | var dispX = this._prevX - this._x; | ||
63 | var dispY = this._prevY - this._y; | ||
64 | var dispZ = this._prevZ - this._z; | ||
65 | |||
66 | this._nextX = this._x - dispX; | ||
67 | this._nextY = this._y - dispY; | ||
68 | this._nextZ = this._z - dispZ; | ||
69 | }; | ||
70 | |||
71 | //translate the next point from the translation that was applied to the prev. point | ||
72 | GLAnchorPoint.prototype.translateNextFromPrev = function (tx, ty, tz) { | ||
73 | //do nothing if the total translation is zero | ||
74 | var totalTransSq = (tx*tx) + (ty*ty) + (tz*tz); | ||
75 | if (totalTransSq < 0.0000001) { | ||
76 | return; | ||
77 | } | ||
78 | |||
79 | // *** compute the rotation of the prev vector *** | ||
80 | var oldP = [this._prevX + tx - this._x, this._prevY + ty - this._y, this._prevZ + tz - this._z]; | ||
81 | var newP = [this._prevX - this._x, this._prevY - this._y, this._prevZ - this._z]; | ||
82 | //compute angle between the two vectors | ||
83 | var axis = [0, 0, 0]; | ||
84 | var angle = MathUtils.getAxisAngleBetween3DVectors(oldP, newP, axis); | ||
85 | if (angle === 0) { | ||
86 | return; | ||
87 | } | ||
88 | |||
89 | // *** compute the vector from anchor to next | ||
90 | var oldN = [this._nextX - this._x, this._nextY - this._y, this._nextZ - this._z]; | ||
91 | var rotMat = Matrix.Rotation(-angle, axis); | ||
92 | var newN = MathUtils.transformVector(oldN, rotMat); | ||
93 | |||
94 | //TEMP for some situations the axis angle computation returns NaNs | ||
95 | if (isNaN(newN[0]) || isNaN(newN[1]) || isNaN(newN[2])) { | ||
96 | console.log("NaN in translateNextFromPrev"); | ||
97 | return; | ||
98 | } | ||
99 | //end TEMP | ||
100 | this._nextX = this._x + newN[0]; | ||
101 | this._nextY = this._y + newN[1]; | ||
102 | this._nextZ = this._z + newN[2]; | ||
103 | }; | ||
104 | |||
105 | //translate the next point from the translation that was applied to the prev. point | ||
106 | GLAnchorPoint.prototype.translatePrevFromNext = function (tx, ty, tz) { | ||
107 | //do nothing if the total translation is zero | ||
108 | var totalTransSq = (tx*tx) + (ty*ty) + (tz*tz); | ||
109 | if (totalTransSq < 0.0000001) { | ||
110 | return; | ||
111 | } | ||
112 | |||
113 | // *** compute the rotation of the next vector *** | ||
114 | var oldN = [this._nextX + tx - this._x, this._nextY + ty - this._y, this._nextZ + tz - this._z]; | ||
115 | var newN = [this._nextX - this._x, this._nextY - this._y, this._nextZ - this._z]; | ||
116 | //compute angle between the two vectors | ||
117 | var axis = [0, 0, 0]; | ||
118 | var angle = MathUtils.getAxisAngleBetween3DVectors(oldN, newN, axis); | ||
119 | if (angle === 0) { | ||
120 | return; | ||
121 | } | ||
122 | |||
123 | // *** compute the vector from anchor to prev | ||
124 | var oldP = [this._prevX - this._x, this._prevY - this._y, this._prevZ - this._z]; | ||
125 | var rotMat = Matrix.Rotation(-angle, axis); | ||
126 | var newP = MathUtils.transformVector(oldP, rotMat); | ||
127 | |||
128 | //TEMP for some situations the axis angle computation returns NaNs | ||
129 | if (isNaN(newP[0]) || isNaN(newP[1]) || isNaN(newP[2])) { | ||
130 | return; | ||
131 | } | ||
132 | //end TEMP | ||
133 | this._prevX = this._x + newP[0]; | ||
134 | this._prevY = this._y + newP[1]; | ||
135 | this._prevZ = this._z + newP[2]; | ||
136 | }; | ||
137 | |||
138 | // ******* modifiers ******* | ||
139 | GLAnchorPoint.prototype.translatePrev = function (x, y, z) { | ||
140 | this._prevX += x; | ||
141 | this._prevY += y; | ||
142 | this._prevZ += z; | ||
143 | }; | ||
144 | |||
145 | GLAnchorPoint.prototype.translateNext = function (x, y, z) { | ||
146 | this._nextX += x; | ||
147 | this._nextY += y; | ||
148 | this._nextZ += z; | ||
149 | }; | ||
150 | |||
151 | GLAnchorPoint.prototype.translate = function (x, y, z) { | ||
152 | this._x += x; | ||
153 | this._y += y; | ||
154 | this._z += z; | ||
155 | }; | ||
156 | |||
157 | GLAnchorPoint.prototype.translateAll = function (x, y, z) { | ||
158 | this.translate(x, y, z); | ||
159 | this.translatePrev(x, y, z); | ||
160 | this.translateNext(x, y, z); | ||
161 | }; | ||
162 | |||
163 | GLAnchorPoint.prototype.scaleAll = function(sx,sy,sz){ | ||
164 | this._x *= sx; | ||
165 | this._prevX *= sx; | ||
166 | this._nextX *= sx; | ||
167 | this._y *= sy; | ||
168 | this._prevY *= sy; | ||
169 | this._nextY *= sy; | ||
170 | this._z *= sz; | ||
171 | this._prevZ *= sz; | ||
172 | this._nextZ *= sz; | ||
173 | }; | ||
174 | |||
175 | // ********* getters ********** | ||
176 | GLAnchorPoint.prototype.getPosX = function () { | ||
177 | return this._x; | ||
178 | }; | ||
179 | |||
180 | GLAnchorPoint.prototype.getPosY = function () { | ||
181 | return this._y; | ||
182 | }; | ||
183 | |||
184 | GLAnchorPoint.prototype.getPosZ = function () { | ||
185 | return this._z; | ||
186 | }; | ||
187 | |||
188 | GLAnchorPoint.prototype.getPrevX = function () { | ||
189 | return this._prevX; | ||
190 | }; | ||
191 | |||
192 | GLAnchorPoint.prototype.getPrevY = function () { | ||
193 | return this._prevY; | ||
194 | }; | ||
195 | |||
196 | GLAnchorPoint.prototype.getPrevZ = function () { | ||
197 | return this._prevZ; | ||
198 | }; | ||
199 | |||
200 | GLAnchorPoint.prototype.getNextX = function () { | ||
201 | return this._nextX; | ||
202 | }; | ||
203 | |||
204 | GLAnchorPoint.prototype.getNextY = function () { | ||
205 | return this._nextY; | ||
206 | }; | ||
207 | |||
208 | GLAnchorPoint.prototype.getNextZ = function () { | ||
209 | return this._nextZ; | ||
210 | }; | ||
211 | |||
212 | GLAnchorPoint.prototype.getPos = function() { | ||
213 | return [this._x, this._y, this._z]; | ||
214 | }; | ||
215 | |||
216 | GLAnchorPoint.prototype.getPrev = function() { | ||
217 | return [this._prevX, this._prevY, this._prevZ]; | ||
218 | }; | ||
219 | |||
220 | GLAnchorPoint.prototype.getNext = function() { | ||
221 | return [this._nextX, this._nextY, this._nextZ]; | ||
222 | }; | ||
223 | |||
224 | //return the square of distance from passed in point to the anchor position | ||
225 | GLAnchorPoint.prototype.getDistanceSq = function (x, y, z) { | ||
226 | return (this._x - x) * (this._x - x) + (this._y - y) * (this._y - y) + (this._z - z) * (this._z - z); | ||
227 | }; | ||
228 | |||
229 | //return sq. of distance to prev. | ||
230 | GLAnchorPoint.prototype.getPrevDistanceSq = function (x, y, z) { |