diff options
author | Ananya Sen | 2012-07-09 16:52:49 -0700 |
---|---|---|
committer | Ananya Sen | 2012-07-09 16:52:49 -0700 |
commit | 2eb84584f44b8c774479d1af2ee1d810597474cf (patch) | |
tree | 64cb3e09a8daeb340261dd7f3869c73f7b90b643 /js/lib/geom/circle.js | |
parent | bf9dba001ec84243e2f12cd13b0c0ae020fba4a2 (diff) | |
parent | cee0deca695359ab468bd06d0e05ed3b2010b338 (diff) | |
download | ninja-2eb84584f44b8c774479d1af2ee1d810597474cf.tar.gz |
Merge branch 'refs/heads/ninja-internal-master' into codemirror-custom-theme-removal
Conflicts:
js/code-editor/codemirror-ninja/theme/lesser-dark-ninja.css
js/code-editor/codemirror-ninja/theme/xq-dark-ninja.css
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js/lib/geom/circle.js')
-rwxr-xr-x | js/lib/geom/circle.js | 321 |
1 files changed, 193 insertions, 128 deletions
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index 39cde514..ba47603b 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js | |||
@@ -1,24 +1,25 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility LLC. |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | ||
5 | 4 | ||
6 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
8 | 7 | ||
9 | - Redistributions of source code must retain the above copyright notice, | 8 | * Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. | 9 | this list of conditions and the following disclaimer. |
11 | - Redistributions in binary form must reproduce the above copyright | 10 | |
12 | notice, this list of conditions and the following disclaimer in the | 11 | * Redistributions in binary form must reproduce the above copyright notice, |
13 | documentation and/or other materials provided with the distribution. | 12 | this list of conditions and the following disclaimer in the documentation |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 13 | and/or other materials provided with the distribution. |
15 | may be used to endorse or promote products derived from this software | 14 | |
16 | without specific prior written permission. | 15 | * Neither the name of Motorola Mobility LLC nor the names of its |
16 | contributors may be used to endorse or promote products derived from this | ||
17 | software without specific prior written permission. | ||
17 | 18 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
@@ -31,14 +32,14 @@ POSSIBILITY OF SUCH DAMAGE. | |||
31 | var GeomObj = require("js/lib/geom/geom-obj").GeomObj; | 32 | var GeomObj = require("js/lib/geom/geom-obj").GeomObj; |
32 | var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; | 33 | var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; |
33 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; | 34 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; |
34 | var drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils; | 35 | var drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils; |
35 | var vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; | 36 | var vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; |
36 | 37 | ||
37 | /////////////////////////////////////////////////////////////////////// | 38 | /////////////////////////////////////////////////////////////////////// |
38 | // Class GLCircle | 39 | // Class GLCircle |
39 | // GL representation of a circle. | 40 | // GL representation of a circle. |
40 | // Derived from class GLGeomObj | 41 | // Derived from class GLGeomObj |
41 | // The position and dimensions of the stroke, fill, and inner Radius should be in pixels | 42 | // The position and dimensions of the stroke, fill, and inner Radius should be in pixels |
42 | /////////////////////////////////////////////////////////////////////// | 43 | /////////////////////////////////////////////////////////////////////// |
43 | exports.Circle = Object.create(GeomObj, { | 44 | exports.Circle = Object.create(GeomObj, { |
44 | 45 | ||
@@ -57,7 +58,7 @@ exports.Circle = Object.create(GeomObj, { | |||
57 | _strokeStyle: { value : "Solid", writable: true }, | 58 | _strokeStyle: { value : "Solid", writable: true }, |
58 | _aspectRatio: { value : 1.0, writable: true }, | 59 | _aspectRatio: { value : 1.0, writable: true }, |
59 | 60 | ||
60 | init: { | 61 | init: { |
61 | value: function(world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor, innerRadius, strokeMaterial, fillMaterial, strokeStyle) { | 62 | value: function(world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor, innerRadius, strokeMaterial, fillMaterial, strokeStyle) { |
62 | if(arguments.length > 0) { | 63 | if(arguments.length > 0) { |
63 | this._width = width; | 64 | this._width = width; |
@@ -85,14 +86,28 @@ exports.Circle = Object.create(GeomObj, { | |||
85 | } else { | 86 | } else { |
86 | this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); | 87 | this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); |
87 | } | 88 | } |
88 | if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor ); | 89 | |
90 | if(strokeColor) { | ||
91 | if(this._strokeMaterial.hasProperty("color")) { | ||
92 | this._strokeMaterial.setProperty( "color", this._strokeColor ); | ||
93 | } else if (this._strokeMaterial && (this._strokeMaterial.gradientType === this._strokeColor.gradientMode)) { | ||
94 | this._strokeMaterial.setGradientData(this._strokeColor.color); | ||
95 | } | ||
96 | } | ||
89 | 97 | ||
90 | if(fillMaterial) { | 98 | if(fillMaterial) { |
91 | this._fillMaterial = fillMaterial.dup(); | 99 | this._fillMaterial = fillMaterial.dup(); |
92 | } else { | 100 | } else { |
93 | this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); | 101 | this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); |
94 | } | 102 | } |
95 | if (fillColor && this._fillMaterial.hasProperty( "color" )) this._fillMaterial.setProperty( "color", this._fillColor ); | 103 | |
104 | if(fillColor) { | ||
105 | if(this._fillMaterial.hasProperty("color")) { | ||
106 | this._fillMaterial.setProperty( "color", this._fillColor ); | ||
107 | } else if (this._fillMaterial && (this._fillMaterial.gradientType === this._fillColor.gradientMode)) { | ||
108 | this._fillMaterial.setGradientData(this._fillColor.color); | ||
109 | } | ||
110 | } | ||
96 | } | 111 | } |
97 | }, | 112 | }, |
98 | 113 | ||
@@ -203,7 +218,7 @@ exports.Circle = Object.create(GeomObj, { | |||
203 | }, | 218 | }, |
204 | 219 | ||
205 | /////////////////////////////////////////////////////////////////////// | 220 | /////////////////////////////////////////////////////////////////////// |
206 | // update the "color of the material | 221 | // update the "color of the material |
207 | getFillColor: { | 222 | getFillColor: { |
208 | value: function() { | 223 | value: function() { |
209 | return this._fillColor; | 224 | return this._fillColor; |
@@ -251,15 +266,15 @@ exports.Circle = Object.create(GeomObj, { | |||
251 | 266 | ||
252 | // get the normalized device coordinates (NDC) for | 267 | // get the normalized device coordinates (NDC) for |
253 | // all position and dimensions. | 268 | // all position and dimensions. |
254 | var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); | 269 | var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); |
255 | var xNDC = 2*this._xOffset/vpw, yNDC = -2*this._yOffset/vph, | 270 | var xNDC = 2*this._xOffset/vpw, yNDC = -2*this._yOffset/vph, |
256 | xRadNDC = this._width/vpw, yRadNDC = this._height/vph, | 271 | xRadNDC = this._width/vpw, yRadNDC = this._height/vph, |
257 | xStrokeNDC = 2*this._strokeWidth/vpw, yStrokeNDC = 2*this._strokeWidth/vph, | 272 | xStrokeNDC = 2*this._strokeWidth/vpw, yStrokeNDC = 2*this._strokeWidth/vph, |
258 | xInnRadNDC = this._innerRadius*xRadNDC, yInnRadNDC = this._innerRadius*yRadNDC; | 273 | xInnRadNDC = this._innerRadius*xRadNDC, yInnRadNDC = this._innerRadius*yRadNDC; |
259 | 274 | ||
260 | var aspect = world.getAspect(); | 275 | var aspect = world.getAspect(); |
261 | var zn = world.getZNear(), zf = world.getZFar(); | 276 | var zn = world.getZNear(), zf = world.getZFar(); |
262 | var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), | 277 | var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), |
263 | b = -t, | 278 | b = -t, |
264 | r = aspect*t, | 279 | r = aspect*t, |
265 | l = -r; | 280 | l = -r; |
@@ -308,7 +323,8 @@ exports.Circle = Object.create(GeomObj, { | |||
308 | innerStrokeScaleMat[0] = xInnRad - xStroke; | 323 | innerStrokeScaleMat[0] = xInnRad - xStroke; |
309 | innerStrokeScaleMat[5] = yInnRad - yStroke; | 324 | innerStrokeScaleMat[5] = yInnRad - yStroke; |
310 | 325 | ||
311 | var fillPrim, strokePrim0, strokePrim1; | 326 | var i; |
327 | var fillPrimArray, strokePrim0Array, strokePrim1Array; | ||
312 | var fillMaterial, strokeMaterial0, strokeMaterial2; | 328 | var fillMaterial, strokeMaterial0, strokeMaterial2; |
313 | 329 | ||
314 | this._primArray = []; | 330 | this._primArray = []; |
@@ -321,43 +337,49 @@ exports.Circle = Object.create(GeomObj, { | |||
321 | if(this._strokeWidth > 0) { | 337 | if(this._strokeWidth > 0) { |
322 | var numStrokes = 1; | 338 | var numStrokes = 1; |
323 | if(this._innerRadius !== 0) { | 339 | if(this._innerRadius !== 0) { |
324 | strokeMaterial0 = this.makeStrokeMaterial(); | 340 | strokeMaterial0 = this.makeStrokeMaterial(); |
325 | strokePrim0 = this.generateOvalRing(x, y, reverseRotMat, innerStrokeScaleMat, innerRadiusScaleMat, nTriangles, strokeMaterial0); | 341 | strokePrim0Array = this.generateOvalRing(x, y, reverseRotMat, innerStrokeScaleMat, innerRadiusScaleMat, nTriangles, strokeMaterial0); |
326 | } | 342 | } |
327 | 343 | ||
328 | strokeMaterial2 = this.makeStrokeMaterial(); | 344 | strokeMaterial2 = this.makeStrokeMaterial(); |
329 | strokePrim1 = this.generateOvalRing(x, y, reverseRotMat, fillScaleMat, strokeScaleMat, nTriangles, strokeMaterial2); | 345 | strokePrim1Array = this.generateOvalRing(x, y, reverseRotMat, fillScaleMat, strokeScaleMat, nTriangles, strokeMaterial2); |
330 | } | 346 | } |
331 | 347 | ||
332 | if (strokePrim0) { | 348 | if (strokePrim0Array) { |
333 | strokeMaterial0.fitToPrimitive( strokePrim0 ); | 349 | strokeMaterial0.fitToPrimitiveArray( strokePrim0Array ); |
334 | 350 | for (i=0; i<strokePrim0Array.length; i++) | |
335 | this._primArray.push( strokePrim0 ); | 351 | { |
352 | this._primArray.push( strokePrim0Array[i] ); | ||
336 | this._materialNodeArray.push( strokeMaterial0.getMaterialNode() ); | 353 | this._materialNodeArray.push( strokeMaterial0.getMaterialNode() ); |
337 | } | 354 | } |
355 | } | ||
338 | 356 | ||
339 | if (strokePrim1) { | 357 | if (strokePrim1Array) { |
340 | strokeMaterial2.fitToPrimitive( strokePrim1 ); | 358 | strokeMaterial2.fitToPrimitiveArray( strokePrim1Array ); |
341 | 359 | for (i=0; i<strokePrim1Array.length; i++) | |
342 | this._primArray.push( strokePrim1 ); | 360 | { |
361 | this._primArray.push( strokePrim1Array[i] ); | ||
343 | this._materialNodeArray.push( strokeMaterial2.getMaterialNode() ); | 362 | this._materialNodeArray.push( strokeMaterial2.getMaterialNode() ); |
344 | } | 363 | } |
364 | } | ||
345 | 365 | ||
346 | ///////////////////////////////////////////////////////////// | 366 | ///////////////////////////////////////////////////////////// |
347 | // Fill | 367 | // Fill |
348 | fillMaterial = this.makeFillMaterial(); | 368 | fillMaterial = this.makeFillMaterial(); |
349 | if(this._innerRadius === 0) { | 369 | if(this._innerRadius === 0) { |
350 | fillPrim = this.generateOval(x, y, mat, fillScaleMat, nTriangles, fillMaterial); | 370 | fillPrimArray = this.generateOval(x, y, mat, fillScaleMat, nTriangles, fillMaterial); |
351 | } else { | 371 | } else { |
352 | fillPrim = this.generateOvalRing(x, y, reverseRotMat, innerRadiusScaleMat, fillScaleMat, nTriangles, fillMaterial); | 372 | fillPrimArray = this.generateOvalRing(x, y, reverseRotMat, innerRadiusScaleMat, fillScaleMat, nTriangles, fillMaterial); |
353 | } | 373 | } |
354 | 374 | ||
355 | if (fillPrim) { | 375 | if (fillPrimArray) { |
356 | fillMaterial.fitToPrimitive( fillPrim ); | 376 | fillMaterial.fitToPrimitiveArray( fillPrimArray ); |
357 | 377 | for (i=0; i<fillPrimArray.length; i++) | |
358 | this._primArray.push( fillPrim ); | 378 | { |
379 | this._primArray.push( fillPrimArray[i] ); | ||
359 | this._materialNodeArray.push( fillMaterial.getMaterialNode() ); | 380 | this._materialNodeArray.push( fillMaterial.getMaterialNode() ); |
360 | } | 381 | } |