working on massive breakup

This commit is contained in:
benfry
2005-02-14 00:18:17 +00:00
parent a42c658e12
commit 5ea8aebf82
3 changed files with 303 additions and 198 deletions

View File

@@ -23,56 +23,6 @@
Boston, MA 02111-1307 USA
*/
/*
if depth buffer sorting turned on?
no anti-aliasing enabled with depth()
with depth(), stroke() *or* fill() but not both
-> bad policy, just allow them to look shitty
circles/ellipses can use a general conic algorithm
single pixel lines can use PLine
thick lines and filled polygon shapes (triangle, rect, etc)
can do some kind of general polygon fill.
images and text should be based on an affine image compositing algorithm
that handles the affine transform and keeps things smooth
point
depth
strokeWeight < 2
rough single pixel dot with a z value
rgb
rgba
strokeWeight >= 2
round endcap
rough filled circle with a z value
rgb
rgba
square endcap
rough filled square with a z value
rgb
rgba
noDepth
strokeWeight < 2
rough single pixel dot (no z value)
strokeWeight >= 2
quad
depth
strokeWeight < 2
series of single pixel lines that surround
strokeWeight >= 2
*/
package processing.core;
import java.applet.*;
@@ -211,32 +161,17 @@ public class PGraphics extends PImage implements PConstants {
// ........................................................
// NEW_GRAPHICS
/**
* Type of shape passed to beginShape(),
* zero if no shape is currently being drawn.
*/
int shape;
protected int shape;
//int shape_index;
// vertices
static final int DEFAULT_VERTICES = 512;
public float vertices[][] = new float[DEFAULT_VERTICES][VERTEX_FIELD_COUNT];
int vertex_count; // total number of vertices
// pos of first vertex of current shape in vertices array
protected int vertex_start;
// i think vertex_end is actually the last vertex in the current shape
// and is separate from vertex_count for occasions where drawing happens
// on endFrame with all the triangles being depth sorted
protected int vertex_end; // total number of vertex in current shape
// used for sorting points when triangulating a polygon
// warning - maximum number of vertices for a polygon is DEFAULT_VERTICES
int vertex_order[] = new int[DEFAULT_VERTICES];
int vertexCount; // total number of vertices
// ........................................................
@@ -244,8 +179,8 @@ public class PGraphics extends PImage implements PConstants {
// spline vertices
static final int SPLINE_VERTEX_ALLOC = 128;
float spline_vertex[][];
int spline_vertex_index;
protected float spline_vertex[][];
protected int spline_vertex_index;
//boolean spline_vertices_flat;
@@ -259,7 +194,8 @@ public class PGraphics extends PImage implements PConstants {
// [toxi 031031]
// changed table's precision to 0.5 degree steps
// introduced new vars for more flexible code
static final float sinLUT[], cosLUT[];
static final float sinLUT[];
static final float cosLUT[];
static final float SINCOS_PRECISION = 0.5f;
static final int SINCOS_LENGTH = (int) (360f / SINCOS_PRECISION);
static {
@@ -279,17 +215,10 @@ public class PGraphics extends PImage implements PConstants {
public int ellipseMode;
public int arcMode;
// [toxi031031] new & faster sphere code w/ support flexibile resolutions
// will be set by sphereDetail() or 1st call to sphere()
public int sphereDetail = 0;
float sphereX[], sphereY[], sphereZ[];
//int text_mode;
//int text_space;
public PFont textFont;
// used by PFont/PGraphics.. forces higher quality texture rendering
//boolean drawing_text = false; // used by PFont
//////////////////////////////////////////////////////////////
@@ -408,9 +337,7 @@ public class PGraphics extends PImage implements PConstants {
resetMatrix(); // reset model matrix
// reset vertices
vertex_count = 0;
vertex_start = 0;
vertex_end = 0;
vertexCount = 0;
}
@@ -451,7 +378,7 @@ public class PGraphics extends PImage implements PConstants {
// reset vertex, line and triangle information
// every shape is rendered at endShape();
vertex_count = 0;
vertexCount = 0;
spline_vertex_index = 0;
//spline_vertices_flat = true;
@@ -463,11 +390,11 @@ public class PGraphics extends PImage implements PConstants {
public void endShape() {
vertex_end = vertex_count;
int vertex_end = vertexCount;
// don't try to draw if there are no vertices
// (fixes a bug in LINE_LOOP that re-adds a nonexistent vertex)
if (vertex_count == 0) {
if (vertexCount == 0) {
shape = 0;
return;
}
@@ -643,7 +570,7 @@ public class PGraphics extends PImage implements PConstants {
case QUADS:
case QUAD_STRIP:
{
stop = vertex_count-3;
stop = vertexCount-3;
increment = (shape == QUADS) ? 4 : 2;
for (int i = vertex_start; i < stop; i += increment) {
@@ -699,13 +626,13 @@ public class PGraphics extends PImage implements PConstants {
public void vertex(float x, float y) {
if (vertex_count == vertices.length) {
float temp[][] = new float[vertex_count<<1][VERTEX_FIELD_COUNT];
System.arraycopy(vertices, 0, temp, 0, vertex_count);
if (vertexCount == vertices.length) {
float temp[][] = new float[vertexCount<<1][VERTEX_FIELD_COUNT];
System.arraycopy(vertices, 0, temp, 0, vertexCount);
vertices = temp;
message(CHATTER, "allocating more vertices " + vertices.length);
}
float vertex[] = vertices[vertex_count++];
float vertex[] = vertices[vertexCount++];
//if (polygon.redundantVertex(x, y, z)) return;
@@ -2204,8 +2131,7 @@ public class PGraphics extends PImage implements PConstants {
* }
* endShape();</code>
*/
public float bezierPoint(float a, float b, float c, float d,
float t) {
public float bezierPoint(float a, float b, float c, float d, float t) {
float t1 = 1.0f - t;
// quadratic bezier
@@ -2221,8 +2147,7 @@ public class PGraphics extends PImage implements PConstants {
* Provide the tangent at the given point on the bezier curve.
* Based on code from v3ga's wordstree sketch.
*/
public float bezierTangent(float a, float b, float c, float d,
float t) {
public float bezierTangent(float a, float b, float c, float d, float t) {
float t1 = 1.0f - t;
return (a * 3 * t*t +
@@ -2394,8 +2319,7 @@ public class PGraphics extends PImage implements PConstants {
*
* @param t Value between zero and one for how far along the segment
*/
public float curvePoint(float a, float b, float c, float d,
float t) {
public float curvePoint(float a, float b, float c, float d, float t) {
if (!curve_inited) curve_init();
float tt = t * t;

View File

@@ -24,16 +24,23 @@
package processing.core;
import java.applet.*;
//import java.applet.*;
import java.awt.*;
import java.awt.event.*;
//import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.io.*;
//import java.io.*;
public class PGraphics2 extends PGraphics {
protected Graphics2D graphics;
Graphics2D graphics;
GeneralPath path;
int transformCount;
AffineTransform transformStack[] =
new AffineTransform[MATRIX_STACK_DEPTH];
double transform[] = new double[6];
//////////////////////////////////////////////////////////////
@@ -90,22 +97,15 @@ public class PGraphics2 extends PGraphics {
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = (Graphics2D) image.getGraphics();
line = new PLine(this);
triangle = new PTriangle(this);
}
//public void defaults() {
//////////////////////////////////////////////////////////////
// FRAME
//public void beginFrame()
// turn off mis.newPixels
public void endFrame() {
// moving this back here (post-68) because of macosx thread problem
@@ -113,12 +113,16 @@ public class PGraphics2 extends PGraphics {
}
public void endShape() {
vertex_end = vertex_count;
//////////////////////////////////////////////////////////////
// SHAPES
public void endShape() {
// don't try to draw if there are no vertices
// (fixes a bug in LINE_LOOP that re-adds a nonexistent vertex)
if (vertex_count == 0) {
if (vertexCount == 0) {
shape = 0;
return;
}
@@ -366,56 +370,214 @@ public class PGraphics2 extends PGraphics {
}
protected void render_triangles() {
for (int i = 0; i < triangleCount; i ++) {
float a[] = vertices[triangles[i][VERTEX1]];
float b[] = vertices[triangles[i][VERTEX2]];
float c[] = vertices[triangles[i][VERTEX3]];
int tex = triangles[i][TEXTURE_INDEX];
int index = triangles[i][INDEX];
//System.out.println("A " + a[X] + " " + a[Y] + " " + a[Z]);
//System.out.println("B " + b[X] + " " + b[Y] + " " + b[Z]);
//System.out.println("C " + c[X] + " " + c[Y] + " " + c[Z]);
//////////////////////////////////////////////////////////////
triangle.reset();
// POINT
if (tex > -1 && textures[tex] != null) {
triangle.setTexture(textures[tex]);
triangle.setUV(a[U], a[V], b[U], b[V], c[U], c[V]);
}
triangle.setIntensities(a[R], a[G], a[B], a[A],
b[R], b[G], b[B], b[A],
c[R], c[G], c[B], c[A]);
public void point(float x, float y) {
}
triangle.setVertices(a[X], a[Y], a[Z],
b[X], b[Y], b[Z],
c[X], c[Y], c[Z]);
public void line(float x1, float y1, float x2, float y2) {
}
triangle.setIndex(index);
triangle.render();
}
public void triangle(float x1, float y1, float x2, float y2,
float x3, float y3) {
}
public void rect(float x1, float y1, float x2, float y2) {
}
public void quad(float x1, float y1, float x2, float y2,
float x3, float y3, float x4, float y4) {
}
public void image(PImage image, float x1, float y1) {
}
public void image(PImage image,
float x1, float y1, float x2, float y2) {
}
public void image(PImage image,
float x1, float y1, float x2, float y2,
float u1, float v1, float u2, float v2) {
}
//public void cache(PImage image) {
//}
//public void cache(PImage images[]) {
//}
//public void arcMode(int mode) {
//}
public void arc(float start, float stop,
float x, float y, float radius) {
}
public void arc(float start, float stop,
float x, float y, float hr, float vr) {
}
//public void ellipseMode(int mode) {
//}
public void ellipse(float x, float y, float hradius, float vradius) {
}
public void circle(float x, float y, float radius) {
}
//public float bezierPoint(float a, float b, float c, float d,
// float t);
//public float bezierTangent(float a, float b, float c, float d,
// float t);
public void bezier(float x1, float y1,
float x2, float y2,
float x3, float y3,
float x4, float y4) {
}
public void bezierDetail(int detail) {
// ignored in java2d
}
public void curveDetail(int detail) {
// ignored in java2d
}
public void curveTightness(float tightness) {
// TODO
}
//public float curvePoint(float a, float b, float c, float d, float t);
//public float curveTangent(float a, float b, float c, float d, float t);
public void curve(float x1, float y1,
float x2, float y2,
float x3, float y3,
float x4, float y4) {
// TODO
}
/*
public void textFont(PFont which);
public void textSize(float size);
public void textFont(PFont which, float size);
public void textLeading(float leading);
public void textMode(int mode);
public void textSpace(int space);
public void text(char c, float x, float y);
public void text(char c, float x, float y, float z);
public void text(String s, float x, float y);
public void text(String s, float x, float y, float z);
public void text(String s, float x, float y, float w, float h);
public void text(String s, float x1, float y1, float z, float x2, float y2);
public void text(int num, float x, float y);
public void text(int num, float x, float y, float z);
public void text(float num, float x, float y);
public void text(float num, float x, float y, float z);
*/
public void translate(float tx, float ty) {
graphics.translate(tx, ty);
}
public void render_lines() {
for (int i = 0; i < lineCount; i ++) {
float a[] = vertices[lines[i][VERTEX1]];
float b[] = vertices[lines[i][VERTEX2]];
int index = lines[i][INDEX];
line.reset();
line.setIntensities(a[SR], a[SG], a[SB], a[SA],
b[SR], b[SG], b[SB], b[SA]);
line.setVertices(a[X], a[Y], a[Z],
b[X], b[Y], b[Z]);
line.setIndex(index);
line.draw();
}
public void rotate(float angle) {
graphics.rotate(angle);
}
}
public void scale(float s) {
graphics.scale(s, s);
}
public void scale(float sx, float sy) {
graphics.scale(sx, sy);
}
public void push() {
if (transformCount == transformStack.length) {
die("push() cannot use push more than " +
transformStack.length + " times");
}
transformStack[transformCount] = graphics.getTransform();
transformCount++;
}
public void pop() {
if (transformCount == 0) {
die("missing a pop() to go with that push()");
}
transformCount--;
graphics.setTransform(transformStack[transformCount]);
}
public void resetMatrix() {
graphics.setTransform(new AffineTransform());
}
public void applyMatrix(float n00, float n01, float n02,
float n10, float n11, float n12) {
graphics.transform(new AffineTransform(n00, n10, n01, n11, n02, n22));
}
public void printMatrix() {
// TODO maybe format this the same way as the superclass
//AffineTransform t = graphics.getTransform();
//System.out.println(t); // not sure what this does
graphics.getTransform().getMatrix(transform);
m00 = (float) transform[0];
m01 = (float) transform[2];
m02 = (float) transform[4];
m10 = (float) transform[1];
m11 = (float) transform[3];
m12 = (float) transform[5];
super.printMatrix();
}
public float screenX(float x, float y) {
graphics.getTransform().getMatrix(transform);
//return m00*x + m01*y + m02;
return (float)transform[0]*x + (float)transform[2]*y + (float)transform[4];
}
public float screenY(float x, float y) {
graphics.getTransform().getMatrix(transform);
return (float)transform[1]*x + (float)transform[3]*y + (float)transform[5];
}
}

View File

@@ -40,6 +40,21 @@ public class PGraphics3 extends PGraphics {
// ........................................................
public int cameraMode;
// perspective setup
public float cameraFOV;
public float cameraX, cameraY, cameraZ;
public float cameraNear, cameraFar;
public float cameraAspect;
public float p00, p01, p02, p03; // projection matrix
public float p10, p11, p12, p13;
public float p20, p21, p22, p23;
public float p30, p31, p32, p33;
// ........................................................
/// the stencil buffer (only for NEW_GRAPHICS)
public int stencil[];
@@ -75,18 +90,23 @@ public class PGraphics3 extends PGraphics {
// ........................................................
public int cameraMode;
// pos of first vertex of current shape in vertices array
protected int vertex_start;
// perspective setup
public float cameraFOV;
public float cameraX, cameraY, cameraZ;
public float cameraNear, cameraFar;
public float cameraAspect;
// i think vertex_end is actually the last vertex in the current shape
// and is separate from vertex_count for occasions where drawing happens
// on endFrame with all the triangles being depth sorted
protected int vertex_end;
public float p00, p01, p02, p03; // projection matrix
public float p10, p11, p12, p13;
public float p20, p21, p22, p23;
public float p30, p31, p32, p33;
// used for sorting points when triangulating a polygon
// warning - maximum number of vertices for a polygon is DEFAULT_VERTICES
int vertex_order[] = new int[DEFAULT_VERTICES];
// ........................................................
public int pathCount;
public int pathOffset[] = new int[64];
public int pathLength[] = new int[64];
// ........................................................
@@ -96,9 +116,7 @@ public class PGraphics3 extends PGraphics {
public int lines[][] = new int[DEFAULT_LINES][LINE_FIELD_COUNT];
public int lineCount;
public int pathCount;
public int pathOffset[] = new int[64];
public int pathLength[] = new int[64];
// ........................................................
// triangles
static final int DEFAULT_TRIANGLES = 256;
@@ -136,7 +154,14 @@ public class PGraphics3 extends PGraphics {
* Normals
*/
public float normalX, normalY, normalZ;
protected boolean normalChanged;
//protected boolean normalChanged;
// ........................................................
// [toxi031031] new & faster sphere code w/ support flexibile resolutions
// will be set by sphereDetail() or 1st call to sphere()
public int sphereDetail = 0;
float sphereX[], sphereY[], sphereZ[];
// ........................................................
@@ -249,6 +274,9 @@ public class PGraphics3 extends PGraphics {
triangleCount = 0;
if (triangle != null) triangle.reset(); // necessary?
vertex_start = 0;
//vertex_end = 0;
// reset textures
texture_index = 0;
@@ -302,7 +330,7 @@ public class PGraphics3 extends PGraphics {
//strokeChanged = false;
//fillChanged = false;
normalChanged = false;
//normalChanged = false;
}
@@ -369,11 +397,11 @@ public class PGraphics3 extends PGraphics {
vertex[V] = textureV;
}
if (normalChanged) {
vertex[NX] = normalX;
vertex[NY] = normalY;
vertex[NZ] = normalZ;
}
//if (normalChanged) {
vertex[NX] = normalX;
vertex[NY] = normalY;
vertex[NZ] = normalZ;
//}
}
@@ -460,11 +488,11 @@ public class PGraphics3 extends PGraphics {
vertex[V] = textureV;
}
if (normalChanged) {
vertex[NX] = normalX;
vertex[NY] = normalY;
vertex[NZ] = normalZ;
}
//if (normalChanged) {
vertex[NX] = normalX;
vertex[NY] = normalY;
vertex[NZ] = normalZ;
//}
spline_vertex_index++;
@@ -525,6 +553,7 @@ public class PGraphics3 extends PGraphics {
public void normal(float nx, float ny, float nz) {
// if drawing a shape and the normal hasn't changed yet,
// then need to set all the normal for each vertex so far
/*
if ((shape != 0) && !normalChanged) {
for (int i = vertex_start; i < vertex_end; i++) {
vertices[i][NX] = normalX;
@@ -533,6 +562,7 @@ public class PGraphics3 extends PGraphics {
}
normalChanged = true;
}
*/
normalX = nx;
normalY = ny;
normalZ = nz;
@@ -1079,6 +1109,7 @@ public class PGraphics3 extends PGraphics {
// ------------------------------------------------------------------
// NORMALS
/*
if (!normalChanged) {
// fill first vertext w/ the normal
vertices[vertex_start][NX] = normalX;
@@ -1086,8 +1117,9 @@ public class PGraphics3 extends PGraphics {
vertices[vertex_start][NZ] = normalZ;
// homogenousNormals saves time from below, which is expensive
}
*/
for (int i = vertex_start; i < (normalChanged ? vertex_end : 1); i++) {
for (int i = vertex_start; i < vertex_end; i++) {
float v[] = vertices[i];
float nx = m00*v[NX] + m01*v[NY] + m02*v[NZ] + m03;
float ny = m10*v[NX] + m11*v[NY] + m12*v[NZ] + m13;
@@ -1120,28 +1152,15 @@ public class PGraphics3 extends PGraphics {
for (int i = vertex_start; i < vertex_end; i++) {
float v[] = vertices[i];
if (normalChanged) {
if (fill) {
calc_lighting(v[R], v[G], v[B],
v[MX], v[MY], v[MZ],
v[NX], v[NY], v[NZ], v, R);
}
if (stroke) {
calc_lighting(v[SR], v[SG], v[SB],
v[MX], v[MY], v[MZ],
v[NX], v[NY], v[NZ], v, SR);
}
} else {
if (fill) {
calc_lighting(v[R], v[G], v[B],
v[MX], v[MY], v[MZ],
f[NX], f[NY], f[NZ], v, R);
}
if (stroke) {
calc_lighting(v[SR], v[SG], v[SB],
v[MX], v[MY], v[MZ],
f[NX], f[NY], f[NZ], v, SR);
}
if (fill) {
calc_lighting(v[R], v[G], v[B],
v[MX], v[MY], v[MZ],
v[NX], v[NY], v[NZ], v, R);
}
if (stroke) {
calc_lighting(v[SR], v[SG], v[SB],
v[MX], v[MY], v[MZ],
v[NX], v[NY], v[NZ], v, SR);
}
}
}