From f5ff10c4d6778eecb872a8a3a2c68d247f8e8d33 Mon Sep 17 00:00:00 2001 From: benfry Date: Sun, 27 Feb 2005 23:12:18 +0000 Subject: [PATCH] fixing PGraphics3.ellipse() and others --- processing/core/PFont.java | 6 +++ processing/core/PGraphics2.java | 4 ++ processing/core/PGraphics3.java | 84 ++++++++++++++++++++++++++++----- processing/core/todo.txt | 3 ++ 4 files changed, 84 insertions(+), 13 deletions(-) diff --git a/processing/core/PFont.java b/processing/core/PFont.java index 4533b4b64..90900e490 100644 --- a/processing/core/PFont.java +++ b/processing/core/PFont.java @@ -455,6 +455,12 @@ public class PFont implements PConstants { parent.vertex(x1, y2, z, 0, height[glyph]); parent.vertex(x2, y2, z, width[glyph], height[glyph]); parent.vertex(x2, y1, z, width[glyph], 0); + /* + parent.vertex(x1, y1, z); + parent.vertex(x1, y2, z); + parent.vertex(x2, y2, z); + parent.vertex(x2, y1, z); + */ parent.endShape(); //parent.textureMode = savedTextureMode; diff --git a/processing/core/PGraphics2.java b/processing/core/PGraphics2.java index 34ed81aee..026263d4b 100644 --- a/processing/core/PGraphics2.java +++ b/processing/core/PGraphics2.java @@ -306,10 +306,13 @@ public class PGraphics2 extends PGraphics { public void curveVertex(float x, float y) { // TODO handle inverse matrix action + throw new RuntimeException("curveVertex() not yet implemented"); } public void endShape() { + //System.out.println("endShape"); + shape = 0; switch (shape) { @@ -347,6 +350,7 @@ public class PGraphics2 extends PGraphics { protected void stroke_shape(Shape s) { if (stroke) { + //System.out.println("stroking shape"); graphics.setColor(strokeColorObject); graphics.draw(s); } diff --git a/processing/core/PGraphics3.java b/processing/core/PGraphics3.java index 05f3e775a..7efaec8f5 100644 --- a/processing/core/PGraphics3.java +++ b/processing/core/PGraphics3.java @@ -793,6 +793,15 @@ public class PGraphics3 extends PGraphics { if (fill) { switch (shape) { + case TRIANGLE_FAN: + { + stop = vertex_end - 1; + for (int i = vertex_start + 1; i < stop; i++) { + add_triangle(vertex_start, i, i+1); + } + } + break; + case TRIANGLES: case TRIANGLE_STRIP: { @@ -901,6 +910,7 @@ public class PGraphics3 extends PGraphics { protected final void add_triangle(int a, int b, int c) { + System.out.println("adding triangle " + triangleCount); if (triangleCount == triangles.length) { int temp[][] = new int[triangleCount<<1][TRIANGLE_FIELD_COUNT]; System.arraycopy(triangles, 0, temp, 0, triangleCount); @@ -928,6 +938,8 @@ public class PGraphics3 extends PGraphics { protected void render_triangles() { //public void render_triangles() { //System.out.println("PGraphics3 render triangles"); + System.out.println("rendering " + triangleCount + " triangles"); + for (int i = 0; i < triangleCount; i ++) { float a[] = vertices[triangles[i][VERTEX1]]; float b[] = vertices[triangles[i][VERTEX2]]; @@ -1482,7 +1494,13 @@ public class PGraphics3 extends PGraphics { } - protected void ellipseImpl(float x, float y, float hradius, float vradius) { + protected void ellipseImpl(float x1, float y1, float w, float h) { + float hradius = w / 2f; + float vradius = h / 2f; + + float centerX = x1 + hradius; + float centerY = y1 + vradius; + // adapt accuracy to radii used w/ a minimum of 4 segments [toxi] // now uses current scale factors to determine "real" transformed radius @@ -1501,13 +1519,50 @@ public class PGraphics3 extends PGraphics { float inc = (float)SINCOS_LENGTH / cAccuracy; float val = 0; + /* beginShape(POLYGON); for (int i = 0; i < cAccuracy; i++) { - vertex(x + cosLUT[(int) val] * hradius, - y + sinLUT[(int) val] * vradius); + vertex(centerX + cosLUT[(int) val] * hradius, + centerY + sinLUT[(int) val] * vradius); val += inc; } endShape(); + */ + + if (fill) { + boolean savedStroke = stroke; + stroke = false; + + beginShape(TRIANGLE_FAN); + vertex(centerX, centerY); + for (int i = 0; i < cAccuracy; i++) { + vertex(centerX + cosLUT[(int) val] * hradius, + centerY + sinLUT[(int) val] * vradius); + val += inc; + } + // back to the beginning + vertex(centerX + cosLUT[0] * hradius, + centerY + sinLUT[0] * vradius); + endShape(); + + stroke = savedStroke; + } + + if (stroke) { + boolean savedFill = fill; + fill = false; + + val = 0; + beginShape(LINE_LOOP); + for (int i = 0; i < cAccuracy; i++) { + vertex(centerX + cosLUT[(int) val] * hradius, + centerY + sinLUT[(int) val] * vradius); + val += inc; + } + endShape(); + + fill = savedFill; + } } @@ -1517,11 +1572,14 @@ public class PGraphics3 extends PGraphics { * This is so that an arc can be drawn that crosses zero mark, * and the user will still collect $200. */ - protected void arcImpl(float x, float y, float w, float h, + protected void arcImpl(float x1, float y1, float w, float h, float start, float stop) { float hr = w / 2f; float vr = h / 2f; + float centerX = x1 + hr; + float centerY = y1 + vr; + if (fill) { // shut off stroke for a minute boolean savedStroke = stroke; @@ -1531,16 +1589,16 @@ public class PGraphics3 extends PGraphics { int stopLUT = (int) (0.5f + (stop / TWO_PI) * SINCOS_LENGTH); beginShape(TRIANGLE_FAN); - vertex(x, y); + vertex(centerX, centerY); int increment = 1; // what's a good algorithm? stopLUT - startLUT; for (int i = startLUT; i < stopLUT; i += increment) { int ii = i % SINCOS_LENGTH; - vertex(x + cosLUT[ii] * hr, - y + sinLUT[ii] * vr); + vertex(centerX + cosLUT[ii] * hr, + centerY + sinLUT[ii] * vr); } // draw last point explicitly for accuracy - vertex(x + cosLUT[stopLUT % SINCOS_LENGTH] * hr, - y + sinLUT[stopLUT % SINCOS_LENGTH] * vr); + vertex(centerX + cosLUT[stopLUT % SINCOS_LENGTH] * hr, + centerY + sinLUT[stopLUT % SINCOS_LENGTH] * vr); endShape(); stroke = savedStroke; @@ -1560,12 +1618,12 @@ public class PGraphics3 extends PGraphics { int increment = 1; // what's a good algorithm? stopLUT - startLUT; for (int i = startLUT; i < stopLUT; i += increment) { int ii = i % SINCOS_LENGTH; - vertex(x + cosLUT[ii] * hr, - y + sinLUT[ii] * vr); + vertex(centerX + cosLUT[ii] * hr, + centerY + sinLUT[ii] * vr); } // draw last point explicitly for accuracy - vertex(x + cosLUT[stopLUT % SINCOS_LENGTH] * hr, - y + sinLUT[stopLUT % SINCOS_LENGTH] * vr); + vertex(centerX + cosLUT[stopLUT % SINCOS_LENGTH] * hr, + centerY + sinLUT[stopLUT % SINCOS_LENGTH] * vr); endShape(); fill = savedFill; diff --git a/processing/core/todo.txt b/processing/core/todo.txt index a8d0e8fd9..861ffd2de 100644 --- a/processing/core/todo.txt +++ b/processing/core/todo.txt @@ -103,6 +103,9 @@ _ sphere x,y,z,r or box w,h,d.. need to make them consistent _ look at curve functions more closely _ should we switch to curveVertex(1,2,3) (ala curveto) _ because some confusion with mixing types of curves +_ how to force PGraphics() instead of PGraphics2() + +_ implement PGraphics2.curveVertex() _ move textMode and textSpace back out of PFont _ use die() to fail in font situations