From 79de00474285af53fc9f0525933de335ed30fd2d Mon Sep 17 00:00:00 2001 From: benfry Date: Mon, 28 Feb 2005 00:32:38 +0000 Subject: [PATCH] getting polygons to work properly.. but not quite yet --- core/PGraphics2.java | 9 +++++-- core/PGraphics3.java | 58 ++++++++++++++++++++++---------------------- core/todo.txt | 6 ++--- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/core/PGraphics2.java b/core/PGraphics2.java index 026263d4b..da4489390 100644 --- a/core/PGraphics2.java +++ b/core/PGraphics2.java @@ -255,9 +255,11 @@ public class PGraphics2 extends PGraphics { case CONCAVE_POLYGON: case CONVEX_POLYGON: if (vertexCount == 1) { + //System.out.println("starting poly path " + x + " " + y); gpath = new GeneralPath(); gpath.moveTo(x, y); } else { + //System.out.println("continuing poly path " + x + " " + y); gpath.lineTo(x, y); } break; @@ -313,8 +315,6 @@ public class PGraphics2 extends PGraphics { public void endShape() { //System.out.println("endShape"); - shape = 0; - switch (shape) { case LINE_STRIP: stroke_shape(gpath); @@ -328,10 +328,13 @@ public class PGraphics2 extends PGraphics { case POLYGON: case CONCAVE_POLYGON: case CONVEX_POLYGON: + //System.out.println("finishing polygon"); gpath.closePath(); draw_shape(gpath); break; } + + shape = 0; } @@ -358,10 +361,12 @@ public class PGraphics2 extends PGraphics { protected void draw_shape(Shape s) { if (fill) { + //System.out.println("filling shape"); graphics.setColor(fillColorObject); graphics.fill(s); } if (stroke) { + //System.out.println("stroking shape"); graphics.setColor(strokeColorObject); graphics.draw(s); } diff --git a/core/PGraphics3.java b/core/PGraphics3.java index 7efaec8f5..2b61b592d 100644 --- a/core/PGraphics3.java +++ b/core/PGraphics3.java @@ -855,21 +855,40 @@ public class PGraphics3 extends PGraphics { // ------------------------------------------------------------------ // TRANSFORM / LIGHT / CLIP - light_and_transform(); + handle_lighting(); + + + + // ------------------------------------------------------------------ + // POINTS FROM VIEW SPACE (VX, VY, VZ) TO SCREEN SPACE (X, Y, Z) + + for (int i = vertex_start; i < vertex_end; i++) { + float vx[] = vertices[i]; + + float ox = p00*vx[VX] + p01*vx[VY] + p02*vx[VZ] + p03*vx[VW]; + float oy = p10*vx[VX] + p11*vx[VY] + p12*vx[VZ] + p13*vx[VW]; + float oz = p20*vx[VX] + p21*vx[VY] + p22*vx[VZ] + p23*vx[VW]; + float ow = p30*vx[VX] + p31*vx[VY] + p32*vx[VZ] + p33*vx[VW]; + + if (ow != 0) { + ox /= ow; oy /= ow; oz /= ow; + } + + vx[X] = width * (ONE + ox) / 2.0f; + vx[Y] = height * (ONE + oy) / 2.0f; + vx[Z] = (oz + ONE) / 2.0f; + } // ------------------------------------------------------------------ // RENDER SHAPES FILLS HERE WHEN NOT DEPTH SORTING // if true, the shapes will be rendered on endFrame - if (hints[DEPTH_SORT]) { - shape = 0; - return; + if (!hints[DEPTH_SORT]) { + if (fill) render_triangles(); + if (stroke) render_lines(); } - if (fill) render_triangles(); - if (stroke) render_lines(); - shape = 0; } @@ -997,6 +1016,8 @@ 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); // first we check if the polygon goes clockwise or counterclockwise float area = 0.0f; @@ -1103,7 +1124,7 @@ public class PGraphics3 extends PGraphics { * so that other renderers can override. For instance, with OpenGL, * this section is all handled on the graphics card. */ - protected void light_and_transform() { + protected void handle_lighting() { // ------------------------------------------------------------------ // CULLING @@ -1203,27 +1224,6 @@ public class PGraphics3 extends PGraphics { //for (int i = 0; i < triangleCount; i ++) { //} //} - - - // ------------------------------------------------------------------ - // POINTS FROM VIEW SPACE (VX, VY, VZ) TO SCREEN SPACE (X, Y, Z) - - for (int i = vertex_start; i < vertex_end; i++) { - float vx[] = vertices[i]; - - float ox = p00*vx[VX] + p01*vx[VY] + p02*vx[VZ] + p03*vx[VW]; - float oy = p10*vx[VX] + p11*vx[VY] + p12*vx[VZ] + p13*vx[VW]; - float oz = p20*vx[VX] + p21*vx[VY] + p22*vx[VZ] + p23*vx[VW]; - float ow = p30*vx[VX] + p31*vx[VY] + p32*vx[VZ] + p33*vx[VW]; - - if (ow != 0) { - ox /= ow; oy /= ow; oz /= ow; - } - - vx[X] = width * (ONE + ox) / 2.0f; - vx[Y] = height * (ONE + oy) / 2.0f; - vx[Z] = (oz + ONE) / 2.0f; - } } diff --git a/core/todo.txt b/core/todo.txt index 861ffd2de..91a22934d 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -105,6 +105,9 @@ _ 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() +_ get frame recording working +_ also have a simple way to hook in triangle leeches to PGraphics3 + _ implement PGraphics2.curveVertex() _ move textMode and textSpace back out of PFont @@ -115,9 +118,6 @@ _ get regular graphics engine working again _ smooth is no longer working _ ellipses aren't handled -_ get frame recording working -_ also have a simple way to hook in triangle leeches to PGraphics3 - _ default to single byte input from serial port _ and add serial.setBuffer() for message length as alternative _ or serial.setDelimiter() to fire message on delim