aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/circle.js
diff options
context:
space:
mode:
authorJonathan Duran2012-07-17 09:30:22 -0700
committerJonathan Duran2012-07-17 09:30:22 -0700
commit53051672a62208fbc96957719d8285fac6431ed6 (patch)
tree79d542ee811044e8af2ef84aa0d6662c6eb895c4 /js/lib/geom/circle.js
parent7e2c2dbd040ed79a3f0678f91bd4b6db9cf69231 (diff)
parent5146f224258929415adf4a8022e492454b4e2476 (diff)
downloadninja-53051672a62208fbc96957719d8285fac6431ed6.tar.gz
Merge branch 'refs/heads/NINJA-master' into TimelineUber
Conflicts: js/panels/Timeline/DragDrop.js js/panels/Timeline/Keyframe.reel/Keyframe.js js/panels/Timeline/Layer.reel/Layer.js js/panels/Timeline/PropertyTrack.reel/PropertyTrack.js js/panels/Timeline/Span.reel/Span.js js/panels/Timeline/Style.reel/Style.js js/panels/Timeline/TimelinePanel.reel/TimelinePanel.js js/panels/Timeline/TimelineTrack.reel/TimelineTrack.js js/panels/Timeline/Track.reel/Track.html js/panels/Timeline/Track.reel/Track.js js/panels/Timeline/Track.reel/css/Track.css js/panels/Timeline/TrackSpacer.reel/TrackSpacer.html js/panels/Timeline/TrackSpacer.reel/TrackSpacer.js js/panels/Timeline/TrackSpacer.reel/css/TrackSpacer.css js/panels/Timeline/Tween.reel/Tween.js Signed-off-by: Jonathan Duran <jduran@motorola.com>
Diffstat (limited to 'js/lib/geom/circle.js')
-rwxr-xr-xjs/lib/geom/circle.js321
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>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, 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
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -31,14 +32,14 @@ POSSIBILITY OF SUCH DAMAGE.
31var GeomObj = require("js/lib/geom/geom-obj").GeomObj; 32var GeomObj = require("js/lib/geom/geom-obj").GeomObj;
32var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; 33var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive;
33var MaterialsModel = require("js/models/materials-model").MaterialsModel; 34var MaterialsModel = require("js/models/materials-model").MaterialsModel;
34var drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils; 35var drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils;
35var vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; 36var 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///////////////////////////////////////////////////////////////////////
43exports.Circle = Object.create(GeomObj, { 44exports.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() );