From ec620a172f7dc942e47677e52b88e5a87e83bd92 Mon Sep 17 00:00:00 2001 From: benfry Date: Mon, 28 Feb 2005 01:36:47 +0000 Subject: [PATCH] beginShape() and endShape() debugged for all three renderers --- core/PGraphics2.java | 50 ++++++++++++++++++++++++++------------ core/PGraphics3.java | 58 +++++++++++++++++++++++++++++++++++--------- core/todo.txt | 2 ++ 3 files changed, 84 insertions(+), 26 deletions(-) diff --git a/core/PGraphics2.java b/core/PGraphics2.java index da4489390..ef42c3c74 100644 --- a/core/PGraphics2.java +++ b/core/PGraphics2.java @@ -140,7 +140,7 @@ public class PGraphics2 extends PGraphics { // not everyone needs this, but just easier to store rather // than adding another moving part to the code... vertices[vertexCount][MX] = x; - vertices[vertexCount][MY] = x; + vertices[vertexCount][MY] = y; vertexCount++; switch (shape) { @@ -177,6 +177,14 @@ public class PGraphics2 extends PGraphics { break; case TRIANGLE_STRIP: + if (vertexCount >= 3) { + triangle(vertices[vertexCount - 2][MX], + vertices[vertexCount - 2][MY], + vertices[vertexCount - 1][MX], + vertices[vertexCount - 1][MY], + vertices[vertexCount - 3][MX], + vertices[vertexCount - 3][MY]); + /* if (vertexCount == 3) { triangle(vertices[0][MX], vertices[0][MY], vertices[1][MX], vertices[1][MY], @@ -192,6 +200,8 @@ public class PGraphics2 extends PGraphics { gpath.lineTo(vertices[vertexCount - 3][MX], vertices[vertexCount - 3][MY]); draw_shape(gpath); + } + */ } break; @@ -229,25 +239,35 @@ public class PGraphics2 extends PGraphics { // 0---2---4 // | | | // 1---3---5 - if (vertexCount == 4) { + if ((vertexCount >= 4) && ((vertexCount % 2) == 0)) { + //if (vertexCount == 4) {// // note difference in winding order: - quad(vertices[0][MX], vertices[0][MY], - vertices[2][MX], vertices[2][MY], + //quad(vertices[0][MX], vertices[0][MY], + // vertices[2][MX], vertices[2][MY], + // x, y, + // vertices[1][MX], vertices[1][MY]); + quad(vertices[vertexCount - 4][MX], + vertices[vertexCount - 4][MY], + vertices[vertexCount - 2][MX], + vertices[vertexCount - 2][MY], x, y, - vertices[1][MX], vertices[1][MY]); + vertices[vertexCount - 3][MX], + vertices[vertexCount - 3][MY]); - } else if (vertexCount > 4) { + /* + } else if ((vertexCount > 4) && ((vertexCount % 2) == 0)) { gpath = new GeneralPath(); - // when vertexCount == 5, draw an un-closed triangle + // when vertexCount == 6, draw an un-closed triangle // for indices 2, 4, 5, 3 - gpath.moveTo(vertices[vertexCount - 3][MX], - vertices[vertexCount - 3][MY]); - gpath.lineTo(vertices[vertexCount - 1][MX], - vertices[vertexCount - 1][MY]); - gpath.lineTo(x, y); + gpath.moveTo(vertices[vertexCount - 4][MX], + vertices[vertexCount - 4][MY]); gpath.lineTo(vertices[vertexCount - 2][MX], vertices[vertexCount - 2][MY]); + gpath.lineTo(x, y); + gpath.lineTo(vertices[vertexCount - 3][MX], + vertices[vertexCount - 3][MY]); draw_shape(gpath); + */ } break; @@ -644,17 +664,17 @@ public class PGraphics2 extends PGraphics { protected void calc_tint() { super.calc_tint(); // TODO actually implement tinted images - tintColorObject = new Color(tintColor); + tintColorObject = new Color(tintColor, true); } protected void calc_fill() { super.calc_fill(); - fillColorObject = new Color(fillColor); + fillColorObject = new Color(fillColor, true); } protected void calc_stroke() { super.calc_stroke(); - strokeColorObject = new Color(strokeColor); + strokeColorObject = new Color(strokeColor, true); } diff --git a/core/PGraphics3.java b/core/PGraphics3.java index 2b61b592d..f362e4b36 100644 --- a/core/PGraphics3.java +++ b/core/PGraphics3.java @@ -684,7 +684,7 @@ public class PGraphics3 extends PGraphics { case TRIANGLES: { - for (int i = vertex_start; i < vertex_end; i += 3) { + for (int i = vertex_start; i < vertex_end-2; i += 3) { add_path(); counter = i - vertex_start; add_line(i+0, i+1); @@ -748,6 +748,14 @@ public class PGraphics3 extends PGraphics { case QUAD_STRIP: { + for (int i = vertex_start; i < vertex_end - 3; i += 2) { + add_path(); + add_line(i+0, i+2); + add_line(i+2, i+3); + add_line(i+3, i+1); + add_line(i+1, i+0); + } + /* // first draw all vertices as a line strip stop = vertex_end - 1; @@ -765,6 +773,7 @@ public class PGraphics3 extends PGraphics { for (int i = vertex_start; i < stop; i += increment) { add_line(i, i+3); } + */ } break; @@ -814,12 +823,9 @@ public class PGraphics3 extends PGraphics { break; case QUADS: - case QUAD_STRIP: { stop = vertexCount-3; - increment = (shape == QUADS) ? 4 : 2; - - for (int i = vertex_start; i < stop; i += increment) { + for (int i = vertex_start; i < stop; i += 4) { // first triangle add_triangle(i, i+1, i+2); // second triangle @@ -828,6 +834,18 @@ public class PGraphics3 extends PGraphics { } break; + case QUAD_STRIP: + { + stop = vertexCount-3; + for (int i = vertex_start; i < stop; i += 2) { + // first triangle + add_triangle(i+0, i+2, i+1); + // second triangle + add_triangle(i+2, i+3, i+1); + } + } + break; + case POLYGON: case CONCAVE_POLYGON: case CONVEX_POLYGON: @@ -929,7 +947,7 @@ public class PGraphics3 extends PGraphics { protected final void add_triangle(int a, int b, int c) { - System.out.println("adding triangle " + triangleCount); + //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); @@ -957,7 +975,7 @@ 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"); + //System.out.println("rendering " + triangleCount + " triangles"); for (int i = 0; i < triangleCount; i ++) { float a[] = vertices[triangles[i][VERTEX1]]; @@ -1016,14 +1034,21 @@ public class PGraphics3 extends PGraphics { * from code by john w. ratcliff (jratcliff at verant.com) */ private void triangulate_polygon() { + /* System.out.println("triangulating polygon " + vertex_start + " " + vertex_end); + for (int i = vertex_start; i < vertex_end; i++) { + System.out.println(i + " " + vertices[i][X] + " " + vertices[i][Y]); + } + */ // first we check if the polygon goes clockwise or counterclockwise float area = 0.0f; for (int p = vertex_end - 1, q = vertex_start; q < vertex_end; p = q++) { - area += (vertices[q][X] * vertices[p][Y] - - vertices[p][X] * vertices[q][Y]); + area += (vertices[q][MX] * vertices[p][MY] - + vertices[p][MX] * vertices[q][MY]); + //area += (vertices[q][X] * vertices[p][Y] - + // vertices[p][X] * vertices[q][Y]); } // then sort the vertices so they are always in a counterclockwise order @@ -1061,12 +1086,21 @@ public class PGraphics3 extends PGraphics { // triangle A B C //float Ax, Ay, Bx, By, Cx, Cy, Px, Py; + float Ax = -vertices[vertex_order[u]][MX]; + float Ay = vertices[vertex_order[u]][MY]; + float Bx = -vertices[vertex_order[v]][MX]; + float By = vertices[vertex_order[v]][MY]; + float Cx = -vertices[vertex_order[w]][MX]; + float Cy = vertices[vertex_order[w]][MY]; + + /* float Ax = -vertices[vertex_order[u]][X]; float Ay = vertices[vertex_order[u]][Y]; float Bx = -vertices[vertex_order[v]][X]; float By = vertices[vertex_order[v]][Y]; float Cx = -vertices[vertex_order[w]][X]; float Cy = vertices[vertex_order[w]][Y]; + */ // first we check if continues going ccw if (EPSILON > (((Bx-Ax) * (Cy-Ay)) - ((By-Ay) * (Cx-Ax)))) { @@ -1081,8 +1115,10 @@ public class PGraphics3 extends PGraphics { continue; } - float Px = -vertices[vertex_order[p]][X]; - float Py = vertices[vertex_order[p]][Y]; + //float Px = -vertices[vertex_order[p]][X]; + //float Py = vertices[vertex_order[p]][Y]; + float Px = -vertices[vertex_order[p]][MX]; + float Py = vertices[vertex_order[p]][MY]; float ax = Cx - Bx; float ay = Cy - By; float bx = Ax - Cx; float by = Ay - Cy; diff --git a/core/todo.txt b/core/todo.txt index 91a22934d..86d8c4567 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -105,6 +105,8 @@ _ 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() +_ make sure applet is stopping in draw mode + _ get frame recording working _ also have a simple way to hook in triangle leeches to PGraphics3