here's the entire processing file -
float camX = 0;
float camY = 0;
float camZ = 0;
float camS = 1;
float camA = 0;
float dist(float x,float y){
return sqrt(pow(x,2)+pow(y,2));
}
float angle(float x,float y){
if(x<0){
return (3*PI/2)-atan(y/x);
} else {
return (PI/2)-atan(y/x);
}
}
class Vert{
float x;
float z;
Vert(float x, float z){
this.x=x;
this.z=z;
}
float getX(){
return x;
}
float getZ(){
return z;
}
}
class Shape{
float x;
float y;
float z;
ArrayList<Vert> verts;
float h;
Shape(float x,float y,float z,ArrayList<Vert> verts,float h){
this.x=x;
this.y=y;
this.z=z;
this.verts = verts;
this.h = h;
}
float getX(){
return x;
}
float getY(){
return y;
}
float getZ(){
return z;
}
ArrayList<Vert> getVerts(){
return verts;
}
float getHeight(){
return h;
}
ArrayList<Vert> getSlice(float sy){
if(sy>=y&&sy<=y+height){
return verts;
} else {
return null;
}
}
}
ArrayList<Shape> shapes;
Vert transVert(float vx,float vy,float vz,float cx,float cy,float cz,float cs,float ca){
float a = angle(cx-vx,cz-vz);
float d = dist(cx-vx,cz-vz);
println(a+" , "+d);
return new Vert((width/2)+(cx+sin((a+ca))*d*cs),(height/2)-(cz+cy+vy+cos((a+ca))*d*cs));
}
void drawSlice(float sy,float cx,float cy,float cz,float cs,float ca){
for(int si = 0;si < shapes.size();si ++){
Shape shape = shapes.get(si);
ArrayList<Vert> slice = shape.getSlice(sy);
beginShape();
for(int i = 0;i < slice.size();i ++){
Vert vi = transVert(slice.get(i).getX()+shape.getX(),sy+shape.getY(),slice.get(i).getZ()+shape.getZ(),cx,cy,cz,cs,ca);
vertex(vi.getX(),vi.getZ());
}
endShape(CLOSE);
}
}
void drawSpace(float y1,float y2,float res,float cx,float cy,float cz,float cs,float ca){
for(float sy = y1;sy < y2;sy += res){
drawSlice(sy,cx,cy,cz,cs,ca);
}
}
void setup(){
size(400,400);
ArrayList<Vert> vs = new ArrayList<Vert>();
vs.add(new Vert(-50,0));
vs.add(new Vert(0,-50));
vs.add(new Vert(50,0));
vs.add(new Vert(0,50));
shapes.add(new Shape(0,0,0,vs,20));
shapes.add(new Shape(100,0,50,vs,20));
}
void draw(){
background(255);
drawSpace(-10,30,5,camX,camY,camZ,camS,camA);
}
i'm getting nullpoint exceptions at the shapes.add lines, but not the vs.add lines? is the spaes array somehow out of range? i need it to be a public arraylist
i've been having lots of trouble with arraylists that i've never had before, hence why i'm using such a messy method of adding individual elements instead of doing it in one line- so i guess any advice would be useful - thanks