JohnG,
Here's some working code. Just comment out the static keyword in Point3D to generate the error. Again, if you modify the sketch, making I_Shape a superclass, you don't need static.
Code:
Cube cube;
Engine engine;
void setup(){
size(600, 400);
background(255);
translate(width/2, height/2);
cube = new Cube (200, 200, 200);
engine = new Engine(cube);
engine.render();
}
// static keyword required
static class Point3D{
float x, y, z;
Point3D(float x, float y, float z){
this.x = x;
this.y = y;
this.z = z;
}
}
class Cube implements I_Shape {
Point3D[] vertices = new Point3D[24];
float w, h, d;
Cube(float w, float h, float d){
this.w = w;
this.h = h;
this.d = d;
vertices[0] = new Point3D(-w/2,-h/2,d/2);
vertices[1] = new Point3D(w/2,-h/2,d/2);
vertices[2] = new Point3D(w/2,h/2,d/2);
vertices[3] = new Point3D(-w/2,h/2,d/2);
vertices[4] = new Point3D(-w/2,-h/2,d/2);
vertices[5] = new Point3D(-w/2,-h/2,-d/2);
vertices[6] = new Point3D(-w/2,h/2,-d/2);
vertices[7] = new Point3D(-w/2,h/2,d/2);
vertices[8] = new Point3D(w/2,-h/2,d/2);
vertices[9] = new Point3D(w/2,-h/2,-d/2);
vertices[10] = new Point3D(w/2,h/2,-d/2);
vertices[11] = new Point3D(w/2,h/2,d/2);
vertices[12] = new Point3D(-w/2,-h/2,-d/2);
vertices[13] = new Point3D(w/2,-h/2,-d/2);
vertices[14] = new Point3D(w/2,h/2,-d/2);
vertices[15] = new Point3D(-w/2,h/2,-d/2);
vertices[16] = new Point3D(-w/2,-h/2,d/2);
vertices[17] = new Point3D(-w/2,-h/2,-d/2);
vertices[18] = new Point3D(w/2,-h/2,-d/2);
vertices[19] = new Point3D(w/2,-h/2,d/2);
vertices[20] = new Point3D(-w/2,h/2,d/2);
vertices[21] = new Point3D(-w/2,h/2,-d/2);
vertices[22] = new Point3D(w/2,h/2,-d/2);
vertices[23] = new Point3D(w/2,h/2,d/2);
}
Point3D[] getVertices(){
return vertices;
}
void create(float[]x, float[]y){
noFill();
for (int i=0; i<6; i++){
beginShape(QUADS);
for (int j=0; j<4; j++){
vertex(x[j+4*i], y[j+4*i]);
}
endShape();
}
}
}
interface I_Shape{
Point3D[] getVertices();
void create(float[]x, float[]y);
}
class Engine {
Point3D[]vertices;
float[]x;
float[]y;
I_Shape shape;
Engine (I_Shape shape){
this.shape = shape;
vertices = shape.getVertices();
x = new float[vertices.length];
y = new float[vertices.length];
}
void projectionMap(){
float theta = 45;
float[]pr = new float[24];
float d = width/2/tan(radians(theta));
for (int i=0; i<24; i++){
pr[i] = d / -(d + vertices[i].z);
x[i] = vertices[i].x * pr[i];
y[i] = vertices[i].y * pr[i];
}
}
void render(){
projectionMap();
shape.create(x, y);
}
}