aboutsummaryrefslogtreecommitdiff
path: root/js/lib
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib')
-rwxr-xr-xjs/lib/geom/circle.js122
-rwxr-xr-xjs/lib/geom/rectangle.js190
-rw-r--r--js/lib/geom/shape-primitive.js27
-rwxr-xr-xjs/lib/rdge/materials/linear-gradient-material.js14
-rwxr-xr-xjs/lib/rdge/materials/material.js4
-rwxr-xr-xjs/lib/rdge/materials/radial-gradient-material.js70
6 files changed, 239 insertions, 188 deletions
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js
index 425b869a..2ca4c1f5 100755
--- a/js/lib/geom/circle.js
+++ b/js/lib/geom/circle.js
@@ -311,6 +311,7 @@ exports.Circle = Object.create(GeomObj, {
311 311
312 if (fillPrim) { 312 if (fillPrim) {
313 fillMaterial = this.makeFillMaterial(); 313 fillMaterial = this.makeFillMaterial();
314 fillMaterial.fitToPrimitive( fillPrim );
314 315
315 this._primArray.push( fillPrim ); 316 this._primArray.push( fillPrim );
316 this._materialNodeArray.push( fillMaterial.getMaterialNode() ); 317 this._materialNodeArray.push( fillMaterial.getMaterialNode() );
@@ -318,6 +319,7 @@ exports.Circle = Object.create(GeomObj, {
318 319
319 if (strokePrim0) { 320 if (strokePrim0) {
320 strokeMaterial0 = this.makeStrokeMaterial(); 321 strokeMaterial0 = this.makeStrokeMaterial();
322 strokeMaterial0.fitToPrimitive( strokePrim0 );
321 323
322 this._primArray.push( strokePrim0 ); 324 this._primArray.push( strokePrim0 );
323 this._materialNodeArray.push( strokeMaterial0.getMaterialNode() ); 325 this._materialNodeArray.push( strokeMaterial0.getMaterialNode() );
@@ -325,6 +327,7 @@ exports.Circle = Object.create(GeomObj, {
325 327
326 if (strokePrim1) { 328 if (strokePrim1) {
327 strokeMaterial2 = this.makeStrokeMaterial(); 329 strokeMaterial2 = this.makeStrokeMaterial();
330 strokeMaterial2.fitToPrimitive( strokePrim1 );
328 331
329 this._primArray.push( strokePrim1 ); 332 this._primArray.push( strokePrim1 );
330 this._materialNodeArray.push( strokeMaterial2.getMaterialNode() ); 333 this._materialNodeArray.push( strokeMaterial2.getMaterialNode() );
@@ -502,9 +505,9 @@ exports.Circle = Object.create(GeomObj, {
502 if(this._fillColor.gradientMode) { 505 if(this._fillColor.gradientMode) {
503 if(this._fillColor.gradientMode === "radial") { 506 if(this._fillColor.gradientMode === "radial") {
504 gradient = ctx.createRadialGradient(xCtr, yCtr, 0, 507 gradient = ctx.createRadialGradient(xCtr, yCtr, 0,
505 xCtr, yCtr, Math.max(this._width, this._height)/2); 508 xCtr, yCtr, Math.max(this._width, this._height)/2 - lineWidth);
506 } else { 509 } else {
507 gradient = ctx.createLinearGradient(lineWidth/2, this._height/2, this._width-lineWidth, this._height/2); 510 gradient = ctx.createLinearGradient(lineWidth, this._height/2, this._width-lineWidth, this._height/2);
508 } 511 }
509 colors = this._fillColor.color; 512 colors = this._fillColor.color;
510 513
@@ -801,79 +804,44 @@ exports.Circle = Object.create(GeomObj, {
801 } 804 }
802 }, 805 },
803 806
804 /* 807 recalcTexMapCoords: {
805 this.getNearPoint = function( pt, dir ) { 808 value: function(vrts, uvs) {
806 var world = this.getWorld(); 809 var n = vrts.length/3;
807 if (!world) throw( "null world in getNearPoint" ); 810 if (n === 0) return;
808 811 var ivrt = 0, iuv = 0;
809 // get a point on the plane of the circle 812 var uMin = 1.e8, uMax = -1.e8,
810 // the point is in NDC, as is the input parameters 813 vMin = 1.e8, vMax = -1.e8;
811 var mat = this.getMatrix(); 814
812 var plane = [0,0,1,0]; 815 var i, index = 3;
813 plane = MathUtils.transformPlane( plane, mat ); 816 var xMin = vrts[0], xMax = vrts[0],
814 var projPt = MathUtils.vecIntersectPlane ( pt, dir, plane ); 817 yMin = vrts[1], yMax = vrts[1];
815 818 for (i=1; i<n; i++)
816 // transform the projected point back to the XY plane 819 {
817 //var invMat = mat.inverse(); 820 if (vrts[index] < xMin) xMin = vrts[index];
818 var invMat = glmat4.inverse( mat, [] ); 821 else if (vrts[index] > xMax) xMax = vrts[index];
819 var planePt = MathUtils.transformPoint( projPt, invMat ); 822
820 823 if (vrts[index+1] < yMin) yMin = vrts[index+1];
821 // get the normalized device coordinates (NDC) for 824 else if (vrts[index+1] > yMax) yMax = vrts[index+1];
822 // the position and radii. 825
823 var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); 826 index += 3;
824 var xNDC = 2*this._xOffset/vpw, yNDC = -2*this._yOffset/vph, 827 }
825 xRadNDC = this._width/vpw, yRadNDC = this._height/vph; 828 var ovalWidth = xMax - xMin,
826 var projMat = world.makePerspectiveMatrix(); 829 ovalHeight = yMax - yMin;
827 var z = -world.getViewDistance(); 830 for (i=0; i<n; i++) {
828 var planePtNDC = planePt.slice(0); 831 uvs[iuv] = (vrts[ivrt]-xMin)/ovalWidth;
829 planePtNDC[2] = z; 832 if (uvs[iuv] < uMin) uMin = uvs[iuv];
830 planePtNDC = MathUtils.transformHomogeneousPoint( planePtNDC, projMat ); 833 if (uvs[iuv] > uMax) uMax = uvs[iuv];
831 planePtNDC = MathUtils.applyHomogeneousCoordinate( planePtNDC ); 834
832 835 iuv++; ivrt++;
833 // get the gl coordinates 836 uvs[iuv] = (vrts[ivrt]-yMin)/ovalHeight;
834 var aspect = world.getAspect(); 837 if (uvs[iuv] < vMin) vMin = uvs[iuv];
835 var zn = world.getZNear(), zf = world.getZFar(); 838 if (uvs[iuv] > vMax) vMax = uvs[iuv];
836 var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), 839 iuv++; ivrt += 2;
837 b = -t, 840 }
838 r = aspect*t, 841
839 l = -r; 842 //console.log( "remap" );
840 843 //console.log( "uRange: " + uMin + " => " + uMax );
841 var angle = Math.atan2( planePtNDC[1] - yNDC, planePtNDC[0] - xNDC ); 844 //console.log( "vRange: " + vMin + " => " + vMax );
842 var degrees = angle*180.0/Math.PI; 845 }
843 var objPt = [Math.cos(angle)*xRadNDC + xNDC, Math.sin(angle)*yRadNDC + yNDC, 0]; 846 }
844
845 // convert to GL coordinates
846 objPt[0] = -z*(r-l)/(2.0*zn)*objPt[0];
847 objPt[1] = -z*(t-b)/(2.0*zn)*objPt[1];
848
849 // re-apply the transform
850 objPt = MathUtils.transformPoint( objPt, mat );
851
852 return objPt;
853 };
854 */
855 recalcTexMapCoords: {
856 value: function(vrts, uvs) {
857 var n = vrts.length/3;
858 var ivrt = 0, iuv = 0;
859 var uMin = 1.e8, uMax = -1.e8,
860 vMin = 1.e8, vMax = -1.e8;
861
862 for (var i=0; i<n; i++) {
863 uvs[iuv] = 0.5*(vrts[ivrt]/this._ovalWidth + 1);
864 if (uvs[iuv] < uMin) uMin = uvs[iuv];
865 if (uvs[iuv] > uMax) uMax = uvs[iuv];
866
867 iuv++; ivrt++;
868 uvs[iuv] = 0.5*(vrts[ivrt]/this._ovalHeight + 1);
869 if (uvs[iuv] < vMin) vMin = uvs[iuv];
870 if (uvs[iuv] > vMax) vMax = uvs[iuv];
871 iuv++; ivrt += 2;
872 }
873
874 //console.log( "remap: " + uvs );
875 //console.log( "uRange: " + uMin + " => " + uMax );
876 //console.log( "vRange: " + vMin + " => " + vMax );
877 }
878 }
879}); \ No newline at end of file 847}); \ No newline at end of file
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js
index d75abb05..8fc80c60 100755
--- a/js/lib/geom/rectangle.js
+++ b/js/lib/geom/rectangle.js
@@ -56,8 +56,6 @@ exports.Rectangle = Object.create(GeomObj, {
56 this._strokeStyle = strokeStyle; 56 this._strokeStyle = strokeStyle;
57 57
58 this._matrix = Matrix.I(4); 58 this._matrix = Matrix.I(4);
59 //this._matrix[12] = xoffset;
60 //this._matrix[13] = yoffset;
61 } 59 }
62 60
63 // the overall radius includes the fill and the stroke. separate the two based on the stroke width 61 // the overall radius includes the fill and the stroke. separate the two based on the stroke width
@@ -124,7 +122,6 @@ exports.Rectangle = Object.create(GeomObj, {
124 this._fillMaterial = m; 122 this._fillMaterial = m;
125 } 123 }
126 }, 124 },
127
128 /////////////////////////////////////////////////////////////////////// 125 ///////////////////////////////////////////////////////////////////////
129 // update the "color of the material 126 // update the "color of the material
130 getFillColor: { 127 getFillColor: {
@@ -138,7 +135,6 @@ exports.Rectangle = Object.create(GeomObj, {
138// this._fillColor = c; 135// this._fillColor = c;
139// } 136// }
140// }, 137// },
141
142 getStrokeColor: { 138 getStrokeColor: {
143 value: function() { 139 value: function() {
144 return this._strokeColor; 140 return this._strokeColor;
@@ -379,6 +375,7 @@ exports.Rectangle = Object.create(GeomObj, {
379 // stroke 375 // stroke
380 var strokeMaterial = this.makeStrokeMaterial(); 376 var strokeMaterial = this.makeStrokeMaterial();
381 var strokePrim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial); 377 var strokePrim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial);
378 strokeMaterial.fitToPrimitive( strokePrim );
382 this._primArray.push( strokePrim ); 379 this._primArray.push( strokePrim );
383 this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); 380 this._materialNodeArray.push( strokeMaterial.getMaterialNode() );
384 381
@@ -392,6 +389,7 @@ exports.Rectangle = Object.create(GeomObj, {
392 var fillMaterial = this.makeFillMaterial(); 389 var fillMaterial = this.makeFillMaterial();
393 //console.log( "fillMaterial: " + fillMaterial.getName() ); 390 //console.log( "fillMaterial: " + fillMaterial.getName() );
394 var fillPrim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial); 391 var fillPrim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial);
392 fillMaterial.fitToPrimitive( fillPrim );
395 this._primArray.push( fillPrim ); 393 this._primArray.push( fillPrim );
396 this._materialNodeArray.push( fillMaterial.getMaterialNode() ); 394 this._materialNodeArray.push( fillMaterial.getMaterialNode() );
397 395
@@ -510,97 +508,99 @@ exports.Rectangle = Object.create(GeomObj, {
510 }, 508 },
511 509
512 render: { 510 render: {
513 value: function() { 511 value: function() {
514 // get the world 512 // get the world
515 var world = this.getWorld(); 513 var world = this.getWorld();
516 if (!world) throw( "null world in rectangle render" ); 514 if (!world) throw( "null world in rectangle render" );
517 515
518 // get the context 516 // get the context
519 var ctx = world.get2DContext(); 517 var ctx = world.get2DContext();
520 if (!ctx) return; 518 if (!ctx) return;
521 519