working on PGraphics/PGraphics3 api stuff

This commit is contained in:
benfry
2005-06-08 20:11:39 +00:00
parent d4b562ab7c
commit 6417c10e1f
6 changed files with 591 additions and 335 deletions
+2 -2
View File
@@ -50,8 +50,8 @@ import processing.core.*;
* files and images, etc) that comes from that.
*/
public class Base {
static final int VERSION = 91;
static final String VERSION_NAME = "0091 Beta";
static final int VERSION = 92;
static final String VERSION_NAME = "0092 Beta";
/**
* Path of filename opened on the command line,
+435 -215
View File
@@ -277,6 +277,201 @@ public class PGraphics extends PImage implements PConstants {
public float textLeading;
//////////////////////////////////////////////////////////////
// VARIABLES FOR 3D (used to prevent the need for a subclass)
/** The modelview matrix. */
public PMatrix modelview;
/** Inverse modelview matrix, used for lighting. */
public PMatrix modelviewInv;
/**
* The camera matrix, the modelview
* will be set to this on beginFrame.
*/
public PMatrix camera;
/** Inverse camera matrix */
public PMatrix cameraInv;
// ........................................................
// Material properties
public float ambientR, ambientG, ambientB;
public int ambientRi, ambientGi, ambientBi;
public float specularR, specularG, specularB, specularA;
public int specularRi, specularGi, specularBi, specularAi;
public float emissiveR, emissiveG, emissiveB;
public int emissiveRi, emissiveGi, emissiveBi;
public float shininess;
// Used to shuttle lighting calcs around
// (no need to re-allocate all the time)
public float[] tempLightingContribution = new float[LIGHT_COLOR_COUNT];
public float[] worldNormal = new float[4];
// ........................................................
/** Camera field of view (in radians, as of rev 86) */
public float cameraFOV;
/** Position of the camera */
public float cameraX, cameraY, cameraZ;
public float cameraNear, cameraFar;
public float cameraAspect;
// projection matrix
public PMatrix projection; // = new PMatrix();
// ........................................................
/// the stencil buffer
public int stencil[];
/// depth buffer
public float zbuffer[];
// ........................................................
/** Maximum lights by default is 8, which is arbitrary,
but is the minimum defined by OpenGL */
protected static final int MAX_LIGHTS = 8;
public int lightCount = 0;
/** Light types */
public int lights[];
/** Light positions */
public float lightsX[], lightsY[], lightsZ[];
/** Light direction (normalized vector) */
public float lightsNX[], lightsNY[], lightsNZ[];
/** Light falloff */
public float lightsFalloffConstant[];
public float lightsFalloffLinear[];
public float lightsFalloffQuadratic[];
/** Light spot angle */
public float lightsSpotAngle[];
/** Cosine of light spot angle */
public float lightsSpotAngleCos[];
/** Light spot concentration */
public float lightsSpotConcentration[];
/** Diffuse colors for lights.
* For an ambient light, this will hold the ambient color.
* Internally these are stored as numbers between 0 and 1. */
public float lightsDiffuseR[], lightsDiffuseG[], lightsDiffuseB[];
/** Specular colors for lights.
Internally these are stored as numbers between 0 and 1. */
public float lightsSpecularR[], lightsSpecularG[], lightsSpecularB[];
public float lightSpecularR;
public float lightSpecularG;
public float lightSpecularB;
public float lightFalloffConstant;
public float lightFalloffLinear;
public float lightFalloffQuadratic;
// ........................................................
// 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 vertexCount for occasions where drawing happens
// on endFrame with all the triangles being depth sorted
protected int vertex_end;
// vertices may be added during clipping against the near plane.
protected int vertex_end_including_clip_verts;
// 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];
// ........................................................
// lines
static final int DEFAULT_LINES = 512;
PLine line; // used for drawing
public int lines[][] = new int[DEFAULT_LINES][LINE_FIELD_COUNT];
public int lineCount;
// ........................................................
// triangles
static final int DEFAULT_TRIANGLES = 256;
PTriangle triangle;
public int triangles[][] =
new int[DEFAULT_TRIANGLES][TRIANGLE_FIELD_COUNT];
public float triangleColors[][][] =
new float[DEFAULT_TRIANGLES][3][TRIANGLE_COLOR_COUNT];
public int triangleCount; // total number of triangles
// cheap picking someday
int shape_index;
// ........................................................
/**
* Sets whether texture coordinates passed to
* vertex() calls will be based on coordinates that are
* based on the IMAGE or NORMALIZED.
*/
public int textureMode;
/**
* Current horizontal coordinate for texture, will always
* be between 0 and 1, even if using textureMode(IMAGE).
*/
public float textureU;
/** Current vertical coordinate for texture, see above. */
public float textureV;
public PImage textureImage;
static final int DEFAULT_TEXTURES = 3;
protected PImage textures[] = new PImage[DEFAULT_TEXTURES];
int texture_index;
// ........................................................
/**
* Normals
*/
public float normalX, normalY, normalZ;
public int normalMode;
public int normalCount;
// ........................................................
// [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[];
//////////////////////////////////////////////////////////////
@@ -958,9 +1153,11 @@ public class PGraphics extends PImage implements PConstants {
/**
* Identical parameters and placement to ellipse,
* but draws only an arc of that ellipse.
*
* angleMode() sets DEGREES or RADIANS for the start & stop
* <p/>
* start and stop are always radians because angleMode() was goofy.
* ellipseMode() sets the placement.
* <p/>
* also tries to be smart about start < stop.
*/
public void arc(float a, float b, float c, float d,
float start, float stop) {
@@ -1078,6 +1275,28 @@ public class PGraphics extends PImage implements PConstants {
}
protected void bezier_init() {
bezierDetail(bezier_detail);
}
public void bezierDetail(int detail) {
if (bezier_forward == null) {
bezier_forward = new float[4][4];
bezier_draw = new float[4][4];
}
bezier_detail = detail;
bezier_inited = true;
// setup matrix for forward differencing to speed up drawing
setup_spline_forward(detail, bezier_forward);
// multiply the basis and forward diff matrices together
// saves much time since this needn't be done for each curve
mult_spline_matrix(bezier_forward, bezier_basis, bezier_draw, 4);
}
/**
* Draw a quadratic bezier curve. The first and last points are
* the on-curve points. The middle two are the 'control' points,
@@ -1120,30 +1339,33 @@ public class PGraphics extends PImage implements PConstants {
}
protected void bezier_init() {
bezierDetail(bezier_detail);
//////////////////////////////////////////////////////////////
/**
* Get a location along a catmull-rom curve segment.
*
* @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) {
if (!curve_inited) curve_init();
float tt = t * t;
float ttt = t * tt;
float m[][] = curve_basis;
// not optimized (and probably need not be)
return (a * (ttt*m[0][0] + tt*m[1][0] + t*m[2][0] + m[3][0]) +
b * (ttt*m[0][1] + tt*m[1][1] + t*m[2][1] + m[3][1]) +
c * (ttt*m[0][2] + tt*m[1][2] + t*m[2][2] + m[3][2]) +
d * (ttt*m[0][3] + tt*m[1][3] + t*m[2][3] + m[3][3]));
}
public void bezierDetail(int detail) {
if (bezier_forward == null) {
bezier_forward = new float[4][4];
bezier_draw = new float[4][4];
}
bezier_detail = detail;
bezier_inited = true;
// setup matrix for forward differencing to speed up drawing
setup_spline_forward(detail, bezier_forward);
// multiply the basis and forward diff matrices together
// saves much time since this needn't be done for each curve
mult_spline_matrix(bezier_forward, bezier_basis, bezier_draw, 4);
}
protected void curve_init() {
curve_mode(curve_detail, curve_tightness);
public float curveTangent(float a, float b, float c, float d,
float t) {
System.err.println("curveTangent not yet implemented");
return 0;
}
@@ -1157,6 +1379,11 @@ public class PGraphics extends PImage implements PConstants {
}
protected void curve_init() {
curve_mode(curve_detail, curve_tightness);
}
/**
* Set the number of segments to use when drawing a Catmull-Rom
* curve, and setting the s parameter, which defines how tightly
@@ -1212,33 +1439,6 @@ public class PGraphics extends PImage implements PConstants {
}
/**
* Get a location along a catmull-rom curve segment.
*
* @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) {
if (!curve_inited) curve_init();
float tt = t * t;
float ttt = t * tt;
float m[][] = curve_basis;
// not optimized (and probably need not be)
return (a * (ttt*m[0][0] + tt*m[1][0] + t*m[2][0] + m[3][0]) +
b * (ttt*m[0][1] + tt*m[1][1] + t*m[2][1] + m[3][1]) +
c * (ttt*m[0][2] + tt*m[1][2] + t*m[2][2] + m[3][2]) +
d * (ttt*m[0][3] + tt*m[1][3] + t*m[2][3] + m[3][3]));
}
public float curveTangent(float a, float b, float c, float d,
float t) {
System.err.println("curveTangent not yet implemented");
return 0;
}
/**
* Draws a segment of Catmull-Rom curve.
* <P>
@@ -1276,6 +1476,9 @@ public class PGraphics extends PImage implements PConstants {
}
//////////////////////////////////////////////////////////////
/**
* Setup forward-differencing matrix to be used for speedy
* curve rendering. It's based on using a specific number
@@ -1483,11 +1686,30 @@ public class PGraphics extends PImage implements PConstants {
/**
* Useful function to set the font and size at the same time.
* Sets the alignment of the text to one of LEFT, CENTER, or RIGHT.
*/
public void textFont(PFont which, float size) {
textFont(which);
textSize(size);
public void textAlign(int align) {
textAlign = align;
}
public float textAscent() {
if (textFont != null) {
return textFont.ascent() * textSize;
} else {
throw new RuntimeException("use textFont() before textAscent()");
}
}
public float textDescent() {
if (textFont != null) {
return textFont.descent() * textSize;
} else {
throw new RuntimeException("use textFont() before textDescent()");
}
}
@@ -1508,22 +1730,11 @@ public class PGraphics extends PImage implements PConstants {
/**
* Sets the text size, also resets the value for the leading.
* Useful function to set the font and size at the same time.
*/
public void textSize(float size) {
if (textFont != null) {
if ((textMode == SCREEN) &&
(size != textFont.size)) {
throw new RuntimeException("can't use textSize() with " +
"textMode(SCREEN)");
}
textSize = size;
textLeading = textSize *
((textFont.ascent() + textFont.descent()) * 1.275f);
} else {
throw new RuntimeException("use textFont() before textSize()");
}
public void textFont(PFont which, float size) {
textFont(which);
textSize(size);
}
@@ -1535,14 +1746,6 @@ public class PGraphics extends PImage implements PConstants {
}
/**
* Sets the alignment of the text to one of LEFT, CENTER, or RIGHT.
*/
public void textAlign(int align) {
textAlign = align;
}
/**
* Sets the text rendering/placement to be either SCREEN (direct
* to the screen, exact coordinates) or MODEL (the default, where
@@ -1571,22 +1774,22 @@ public class PGraphics extends PImage implements PConstants {
}
public float textAscent() {
/**
* Sets the text size, also resets the value for the leading.
*/
public void textSize(float size) {
if (textFont != null) {
return textFont.ascent() * textSize;
if ((textMode == SCREEN) &&
(size != textFont.size)) {
throw new RuntimeException("can't use textSize() with " +
"textMode(SCREEN)");
}
textSize = size;
textLeading = textSize *
((textFont.ascent() + textFont.descent()) * 1.275f);
} else {
throw new RuntimeException("use textFont() before textAscent()");
}
}
public float textDescent() {
if (textFont != null) {
return textFont.descent() * textSize;
} else {
throw new RuntimeException("use textFont() before textDescent()");
throw new RuntimeException("use textFont() before textSize()");
}
}
@@ -2028,10 +2231,24 @@ public class PGraphics extends PImage implements PConstants {
}
/**
* Loads the current matrix into m00, m01 etc (or modelview and
* projection when using 3D) so that the values can be read.
* <P/>
* Note that there is no "updateMatrix" because that gets too
* complicated (unnecessary) when considering the 3D matrices.
*/
public void loadMatrix() {
// no-op on base PGraphics because they're used directly
}
/**
* Print the current model (or "transformation") matrix.
*/
public void printMatrix() {
loadMatrix(); // just to make sure
float big = Math.abs(m00);
if (Math.abs(m01) > big) big = Math.abs(m01);
if (Math.abs(m02) > big) big = Math.abs(m02);
@@ -2066,10 +2283,6 @@ public class PGraphics extends PImage implements PConstants {
// CAMERA (none are supported in 2D)
public void cameraMode(int mode) {
depthError("cameraMode");
}
public void beginCamera() {
depthError("beginCamera");
}
@@ -2088,6 +2301,17 @@ public class PGraphics extends PImage implements PConstants {
depthError("camera");
}
public void printCamera() {
depthError("printCamera");
}
//////////////////////////////////////////////////////////////
// PROJECTION (none are supported in 2D)
public void ortho() {
depthError("ortho");
}
@@ -2111,10 +2335,6 @@ public class PGraphics extends PImage implements PConstants {
depthError("frustum");
}
public void printCamera() {
depthError("printCamera");
}
public void printProjection() {
depthError("printCamera");
}
@@ -2375,7 +2595,7 @@ public class PGraphics extends PImage implements PConstants {
* <P>
* Note, no need for a bounds check since it's a 32 bit number.
*/
protected void colorFrom(int argb) {
protected void colorCalcARGB(int argb) {
calcColor = argb;
calcAi = (argb >> 24) & 0xff;
calcRi = (argb >> 16) & 0xff;
@@ -2389,38 +2609,69 @@ public class PGraphics extends PImage implements PConstants {
}
protected void colorTint() {
tint = true;
tintR = calcR;
tintG = calcG;
tintB = calcB;
tintA = calcA;
tintRi = calcRi;
tintGi = calcGi;
tintBi = calcBi;
tintAi = calcAi;
tintColor = calcColor;
tintAlpha = calcAlpha;
//////////////////////////////////////////////////////////////
public void strokeWeight(float weight) {
strokeWeight = weight;
}
protected void colorFill() {
fill = true;
//fillChanged = true;
fillR = calcR;
fillG = calcG;
fillB = calcB;
fillA = calcA;
fillRi = calcRi;
fillGi = calcGi;
fillBi = calcBi;
fillAi = calcAi;
fillColor = calcColor;
fillAlpha = calcAlpha;
public void strokeJoin(int join) {
strokeJoin = join;
}
protected void colorStroke() {
public void strokeCap(int cap) {
strokeCap = cap;
}
public void noStroke() {
stroke = false;
}
/**
* Set the tint to either a grayscale or ARGB value. See notes
* attached to the fill() function.
*/
public void stroke(int rgb) {
if (((rgb & 0xff000000) == 0) && (rgb <= colorModeX)) { // see above
stroke((float) rgb);
} else {
colorCalcARGB(rgb);
strokeFromCalc();
}
}
public void stroke(float gray) {
colorCalc(gray);
strokeFromCalc();
}
public void stroke(float gray, float alpha) {
colorCalc(gray, alpha);
strokeFromCalc();
}
public void stroke(float x, float y, float z) {
colorCalc(x, y, z);
strokeFromCalc();
}
public void stroke(float x, float y, float z, float a) {
colorCalc(x, y, z, a);
strokeFromCalc();
}
protected void strokeFromCalc() {
stroke = true;
//strokeChanged = true;
strokeR = calcR;
@@ -2436,17 +2687,6 @@ public class PGraphics extends PImage implements PConstants {
}
protected void colorBackground() {
backgroundR = calcR;
backgroundG = calcG;
backgroundB = calcB;
backgroundRi = calcRi;
backgroundGi = calcGi;
backgroundBi = calcBi;
backgroundColor = calcColor;
}
//////////////////////////////////////////////////////////////
@@ -2464,32 +2704,47 @@ public class PGraphics extends PImage implements PConstants {
tint((float) rgb);
} else {
colorFrom(rgb);
colorTint();
colorCalcARGB(rgb);
tintFromCalc();
}
}
public void tint(float gray) {
colorCalc(gray);
colorTint();
tintFromCalc();
}
public void tint(float gray, float alpha) {
colorCalc(gray, alpha);
colorTint();
tintFromCalc();
}
public void tint(float x, float y, float z) {
colorCalc(x, y, z);
colorTint();
tintFromCalc();
}
public void tint(float x, float y, float z, float a) {
colorCalc(x, y, z, a);
colorTint();
tintFromCalc();
}
protected void tintFromCalc() {
tint = true;
tintR = calcR;
tintG = calcG;
tintB = calcB;
tintA = calcA;
tintRi = calcRi;
tintGi = calcGi;
tintBi = calcBi;
tintAi = calcAi;
tintColor = calcColor;
tintAlpha = calcAlpha;
}
@@ -2526,32 +2781,47 @@ public class PGraphics extends PImage implements PConstants {
fill((float) rgb);
} else {
colorFrom(rgb);
colorFill();
colorCalcARGB(rgb);
fillFromCalc();
}
}
public void fill(float gray) {
colorCalc(gray);
colorFill();
fillFromCalc();
}
public void fill(float gray, float alpha) {
colorCalc(gray, alpha);
colorFill();
fillFromCalc();
}
public void fill(float x, float y, float z) {
colorCalc(x, y, z);
colorFill();
fillFromCalc();
}
public void fill(float x, float y, float z, float a) {
colorCalc(x, y, z, a);
colorFill();
fillFromCalc();
}
protected void fillFromCalc() {
fill = true;
fillR = calcR;
fillG = calcG;
fillB = calcB;
fillA = calcA;
fillRi = calcRi;
fillGi = calcGi;
fillBi = calcBi;
fillAi = calcAi;
fillColor = calcColor;
fillAlpha = calcAlpha;
}
@@ -2629,7 +2899,8 @@ public class PGraphics extends PImage implements PConstants {
depthError("ambientLight");
}
public void ambientLight(float red, float green, float blue, float x, float y, float z) {
public void ambientLight(float red, float green, float blue,
float x, float y, float z) {
depthError("ambientLight");
}
@@ -2660,68 +2931,6 @@ public class PGraphics extends PImage implements PConstants {
//////////////////////////////////////////////////////////////
public void strokeWeight(float weight) {
strokeWeight = weight;
}
public void strokeJoin(int join) {
strokeJoin = join;
}
public void strokeCap(int cap) {
strokeCap = cap;
}
public void noStroke() {
stroke = false;
}
/**
* Set the tint to either a grayscale or ARGB value. See notes
* attached to the fill() function.
*/
public void stroke(int rgb) {
if (((rgb & 0xff000000) == 0) && (rgb <= colorModeX)) { // see above
stroke((float) rgb);
} else {
colorFrom(rgb);
colorStroke();
}
}
public void stroke(float gray) {
colorCalc(gray);
colorStroke();
}
public void stroke(float gray, float alpha) {
colorCalc(gray, alpha);
colorStroke();
}
public void stroke(float x, float y, float z) {
colorCalc(x, y, z);
colorStroke();
}
public void stroke(float x, float y, float z, float a) {
colorCalc(x, y, z, a);
colorStroke();
}
//////////////////////////////////////////////////////////////
@@ -2738,8 +2947,8 @@ public class PGraphics extends PImage implements PConstants {
background((float) rgb);
} else {
colorFrom(rgb);
colorBackground();
colorCalcARGB(rgb);
backgroundFromCalc();
}
clear();
}
@@ -2751,7 +2960,7 @@ public class PGraphics extends PImage implements PConstants {
*/
public void background(float gray) {
colorCalc(gray);
colorBackground();
backgroundFromCalc();
clear();
}
@@ -2762,11 +2971,22 @@ public class PGraphics extends PImage implements PConstants {
*/
public void background(float x, float y, float z) {
colorCalc(x, y, z);
colorBackground();
backgroundFromCalc();
clear();
}
protected void backgroundFromCalc() {
backgroundR = calcR;
backgroundG = calcG;
backgroundB = calcB;
backgroundRi = calcRi;
backgroundGi = calcGi;
backgroundBi = calcBi;
backgroundColor = calcColor;
}
/**
* Takes an RGB or ARGB image and sets it as the background.
* <P>
+1 -3
View File
@@ -710,7 +710,7 @@ public class PGraphics2 extends PGraphics {
}
public void printMatrix() {
public void loadMatrix() {
g2.getTransform().getMatrix(transform);
m00 = (float) transform[0];
@@ -720,8 +720,6 @@ public class PGraphics2 extends PGraphics {
m10 = (float) transform[1];
m11 = (float) transform[3];
m12 = (float) transform[5];
super.printMatrix();
}
+114 -95
View File
@@ -53,18 +53,18 @@ public class PGraphics3 extends PGraphics {
// Lighting-related variables
// store the facing direction to speed rendering
boolean useBackfaceCulling = false;
protected boolean useBackfaceCulling = false; // is this in use?
// Material properties
public float ambientR, ambientG, ambientB;
public int ambientRi, ambientGi, ambientBi;
//public int ambientRi, ambientGi, ambientBi;
public float specularR, specularG, specularB, specularA;
public int specularRi, specularGi, specularBi, specularAi;
//public int specularRi, specularGi, specularBi, specularAi;
public float emissiveR, emissiveG, emissiveB;
public int emissiveRi, emissiveGi, emissiveBi;
//public int emissiveRi, emissiveGi, emissiveBi;
public float shininess;
@@ -85,8 +85,8 @@ public class PGraphics3 extends PGraphics {
// Used to shuttle lighting calcs around
// (no need to re-allocate all the time)
public float[] tempLightingContribution = new float[LIGHT_COLOR_COUNT];
public float[] worldNormal = new float[4];
protected float[] tempLightingContribution = new float[LIGHT_COLOR_COUNT];
protected float[] worldNormal = new float[4];
// ........................................................
@@ -2765,6 +2765,12 @@ public class PGraphics3 extends PGraphics {
}
public void applyMatrix(float n00, float n01, float n02,
float n10, float n11, float n12) {
throw new RuntimeException("Use applyMatrix() with a 4x4 matrix " +
"when using OPENGL or P3D");
}
/**
* Apply a 4x4 transformation matrix. Same as glMultMatrix().
* This call will be slow because it will try to calculate the
@@ -3268,68 +3274,13 @@ public class PGraphics3 extends PGraphics {
//////////////////////////////////////////////////////////////
// BACKGROUND
/**
* Takes an RGB or RGBA image and sets it as the background.
* <P>
* Note that even if the image is set as RGB, the high 8 bits of
* each pixel must be set (0xFF000000), because the image data will
* be copied directly to the screen.
* <P>
* Also clears out the zbuffer and stencil buffer if they exist.
*/
public void background(PImage image) {
super.background(image);
for (int i = 0; i < pixelCount; i++) {
zbuffer[i] = MAX_FLOAT;
stencil[i] = 0;
}
protected void fillFromCalc() {
super.fillFromCalc();
ambientFromCalc();
}
/**
* Clears pixel buffer.
* <P>
* With P3D and OPENGL, this also clears the stencil and zbuffer.
*/
public void clear() {
//System.out.println("PGraphics3.clear(" +
// PApplet.hex(backgroundColor) + ")");
for (int i = 0; i < pixelCount; i++) {
pixels[i] = backgroundColor;
zbuffer[i] = MAX_FLOAT;
stencil[i] = 0;
}
}
//////////////////////////////////////////////////////////////
// SMOOTH (not available, throws error)
// although should this bother throwing an error?
// could be a pain in the ass when trying to debug with opengl
public void smooth() {
String msg = "smooth() not available with P3D";
throw new RuntimeException(msg);
}
public void noSmooth() {
String msg = "noSmooth() not available with P3D";
throw new RuntimeException(msg);
}
//////////////////////////////////////////////////////////////
/*
public void fill(int rgb) {
super.fill(rgb);
colorAmbient();
@@ -3357,6 +3308,7 @@ public class PGraphics3 extends PGraphics {
super.fill(x, y, z, a);
colorAmbient();
}
*/
//////////////////////////////////////////////////////////////
@@ -3367,25 +3319,25 @@ public class PGraphics3 extends PGraphics {
ambient((float) rgb);
} else {
colorFrom(rgb);
colorAmbient();
colorCalcARGB(rgb);
ambientFromCalc();
}
}
public void ambient(float gray) {
colorCalc(gray);
colorAmbient();
ambientFromCalc();
}
public void ambient(float x, float y, float z) {
colorCalc(x, y, z);
colorAmbient();
ambientFromCalc();
}
private void colorAmbient() {
protected void ambientFromCalc() {
ambientR = calcR;
ambientG = calcG;
ambientB = calcB;
@@ -3403,37 +3355,37 @@ public class PGraphics3 extends PGraphics {
specular((float) rgb);
} else {
colorFrom(rgb);
colorSpecular();
colorCalcARGB(rgb);
specularFromCalc();
}
}
public void specular(float gray) {
colorCalc(gray);
colorSpecular();
specularFromCalc();
}
public void specular(float gray, float alpha) {
colorCalc(gray, alpha);
colorSpecular();
specularFromCalc();
}
public void specular(float x, float y, float z) {
colorCalc(x, y, z);
colorSpecular();
specularFromCalc();
}
public void specular(float x, float y, float z, float a) {
colorCalc(x, y, z, a);
colorSpecular();
specularFromCalc();
}
protected void colorSpecular() {
protected void specularFromCalc() {
specularR = calcR;
specularG = calcG;
specularB = calcB;
@@ -3445,6 +3397,11 @@ public class PGraphics3 extends PGraphics {
}
public void shininess(float shine) {
shininess = shine;
}
//////////////////////////////////////////////////////////////
@@ -3453,25 +3410,25 @@ public class PGraphics3 extends PGraphics {
emissive((float) rgb);
} else {
colorFrom(rgb);
colorEmissive();
colorCalcARGB(rgb);
emissiveFromCalc();
}
}
public void emissive(float gray) {
colorCalc(gray);
colorEmissive();
emissiveFromCalc();
}
public void emissive(float x, float y, float z) {
colorCalc(x, y, z);
colorEmissive();
emissiveFromCalc();
}
protected void colorEmissive() {
protected void emissiveFromCalc() {
emissiveR = calcR;
emissiveG = calcG;
emissiveB = calcB;
@@ -3484,14 +3441,6 @@ public class PGraphics3 extends PGraphics {
//////////////////////////////////////////////////////////////
public void shininess(float shine) {
shininess = shine;
}
//////////////////////////////////////////////////////////////
/**
* Sets up an ambient and directional light.
* <PRE>
@@ -3615,6 +3564,7 @@ public class PGraphics3 extends PGraphics {
* We should capitalize.
*
* Simon Greenwold, April 2005
* </PRE>
*/
public void lights() {
// need to make sure colorMode is RGB 255 here
@@ -3641,7 +3591,18 @@ public class PGraphics3 extends PGraphics {
/**
* Add an ambient light based on the current color mode.
*/
public void ambientLight(float r, float g, float b, float x, float y, float z) {
public void ambientLight(float r, float g, float b) {
ambientLight(r, g, b, 0, 0, 0);
}
/**
* Add an ambient light based on the current color mode.
* This version includes an (x, y, z) position for situations
* where the falloff distance is used.
*/
public void ambientLight(float r, float g, float b,
float x, float y, float z) {
if (lightCount == MAX_LIGHTS) {
throw new RuntimeException("can only create " + MAX_LIGHTS + " lights");
}
@@ -3659,10 +3620,6 @@ public class PGraphics3 extends PGraphics {
//return lightCount-1;
}
public void ambientLight(float r, float g, float b) {
ambientLight(r, g, b, 0, 0, 0);
}
public void directionalLight(float r, float g, float b,
float nx, float ny, float nz) {
@@ -3810,6 +3767,68 @@ public class PGraphics3 extends PGraphics {
//////////////////////////////////////////////////////////////
// BACKGROUND
/**
* Takes an RGB or RGBA image and sets it as the background.
* <P>
* Note that even if the image is set as RGB, the high 8 bits of
* each pixel must be set (0xFF000000), because the image data will
* be copied directly to the screen.
* <P>
* Also clears out the zbuffer and stencil buffer if they exist.
*/
public void background(PImage image) {
super.background(image);
for (int i = 0; i < pixelCount; i++) {
zbuffer[i] = MAX_FLOAT;
stencil[i] = 0;
}
}
/**
* Clears pixel buffer.
* <P>
* With P3D and OPENGL, this also clears the stencil and zbuffer.
*/
public void clear() {
//System.out.println("PGraphics3.clear(" +
// PApplet.hex(backgroundColor) + ")");
for (int i = 0; i < pixelCount; i++) {
pixels[i] = backgroundColor;
zbuffer[i] = MAX_FLOAT;
stencil[i] = 0;
}
}
//////////////////////////////////////////////////////////////
// SMOOTH (not available, throws error)
// although should this bother throwing an error?
// could be a pain in the ass when trying to debug with opengl
public void smooth() {
String msg = "smooth() not available with P3D";
throw new RuntimeException(msg);
}
public void noSmooth() {
String msg = "noSmooth() not available with P3D";
throw new RuntimeException(msg);
}
//////////////////////////////////////////////////////////////
// MATH (internal use only)
+1 -1
View File
@@ -1365,7 +1365,7 @@ public class PImage implements PConstants, Cloneable {
static public boolean saveHeaderTIFF(OutputStream output,
int width, int height) {
int width, int height) {
try {
byte tiff[] = new byte[768];
System.arraycopy(tiff_header, 0, tiff, 0, tiff_header.length);
+38 -19
View File
@@ -1,15 +1,48 @@
0092 core
X proper/consistent api to access matrices in PGraphics/PGraphics3
X first use loadMatrix(), then m00, m01 etc
_ find the post on the board and make a note of this
X proper api for access to Graphics2D object in PGraphics2
_ just add the current "g2" thing to the faq
_ and make a note of it on the suggestions board
_ proper api for access to Graphics2D in PGraphics2
_ proper/consistent api to access matrices in PGraphics, PGraphics3 et al
_ change PGraphics to PGraphics2
_ change PGraphics2 to PGraphicsJava or PGraphicsJava2D
_ maybe wait until the new shape stuff is done?
_ vars like cameraX etc need to be in PGraphics
_ otherwise g.xxxx won't work
_ how far should this go? vertices etc?
_ how to deal with triangles/lines and triangleCount and lineCount
_ maybe just need a triangleImpl and lineImpl
_ because it's too messy to retain the triangle objects and info
_ need to test/straighten out load/update pixels
loadPixels() and updatePixels() only need to be used when
touching pixels[]. All other functions including get(), set(),
filter(), etc shouldn't need them.
_ fjen says blend() doens't work in JAVA2D
_ the functions are fairly well separated now in PMethods
_ just go through all the stuff to make sure it's setting properly
_ don't do a loadPixels unless an updatePixels has completed
_ tho this won't affect anything, since either it's an image buffer
_ or it's the PGraphics object, which does an updatePixels() immediately
_ if (modified) don't loadPixels again, just ignore it
_ make a note that updatePixels() only sets a flag in PImage
_ (but not PGraphics, which does it immediately)
_ createGraphics(200, 200) to create same as source
_ createGraphics(200, 200, P2D) to create 2D from 3D
_ also, drawing a PGraphics2 doesn't seem to work
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1113919619;start=5
_ new PGraphics2 objects are set as RGB, but on loadPixels/updatePixels
_ they're drawn as transparent and don't have their high bits set
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1113933055;start=0
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1115087536;start=0
_ P3D not doing bilinear interpolation because smooth() has to be set
_ (and smooth throws an error in P3D)
_ how should this be handled? a hint? allowing smooth()?
@@ -156,26 +189,12 @@ _ and then does 5 step sizes for each curveto
CORE / PGraphics
_ createGraphics(200, 200) to create same as source
_ createGraphics(200, 200, P2D) to create 2D from 3D
_ also, drawing a PGraphics2 doesn't seem to work
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1113919619;start=5
_ new PGraphics2 objects are set as RGB, but on loadPixels/updatePixels
_ they're drawn as transparent and don't have their high bits set
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1113933055;start=0
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1115087536;start=0
_ alter bezier and curve matrices to use PMatrix
_ float array stuff is redundant with code that's in PMatrix
_ and PMatrix has to be included even w/o P3D so...
_ y2 position of rectangles not same as y2 position of lines
_ happens when the rectangle is flipped on the x or y axis
_ probably a hack that draws the "last" point differently
_ vars like cameraX etc need to be in PGraphics
_ otherwise g.xxxx won't work
_ how far should this go? vertices etc?
_ don't do a loadPixels unless an updatePixels has completed
_ tho this won't affect anything, since either it's an image buffer
_ or it's the PGraphics object, which does an updatePixels() immediately
_ if (modified) don't loadPixels again, just ignore it
_ make a note that updatePixels() only sets a flag in PImage
_ (but not PGraphics, which does it immediately)
_ beginShape()
_ don't allow you to draw stroked items unless stroke() is called
_ don't allow beginShape() if shape is already set