class Vector { float x,y,z; float nx,ny,nz; float mag; Vector(float _x, float _y, float _z) { x=_x; y=_y; z=_z; //calculate the normalised vector (vector of length 1) .. doesn't make sense for using vector for co-ords, but useful when an actual vector mag=sqrt(x*x+y*y+z*z); nx=x/mag; ny=y/mag; nz=z/mag; } Vector divide(float val) { return new Vector(x/val,y/val,z/val); } } // works out the distance between 2 points by their x,y,z co-ords. float dist(Vector a, Vector b) { float i=a.x-b.x; float j=a.y-b.y; float k=a.z-b.z; return sqrt(i*i+j*j+k*k); } float Dot(Vector a, Vector b) { return(a.nx*b.nx + a.ny*b.ny + a.nz * b.nz); } Vector cross(Vector a, Vector b) { return new Vector(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y-a.y*b.x); } class MyLight { float x,y,z; color c; MyLight(float _x, float _y, float _z, color _c) { x=_x; y=_y; z=_z; c=_c; } } class MyPoly { Vector[] points; Vector Normal; Vector Centre; BImage lightmap; //3 point polys only to begin with... MyPoly(Vector a, Vector b, Vector c) { points=new Vector[3]; points[0]=a; points[1]=b; points[2]=c; Vector ba=new Vector(a.x-b.x, a.y-b.y, a.z-b.z); Vector cb=new Vector(b.x-c.x, b.y-c.y, b.z-c.z); Normal=cross(ba,cb); Centre=new Vector((a.x+b.x+c.x)/3.0,(a.y+b.y+c.y)/3.0,(a.z+b.z+c.z)/3.0); lightmap=new BImage(20,20); } void draw(MyLight[] Lights, int NumLights) { Vector ToLight; float lightlevel; color lc; stroke(255,0,0); Vector ab=new Vector(points[1].x-points[0].x, points[1].y-points[0].y, points[1].z-points[0].z); Vector bc=new Vector(points[2].x-points[1].x, points[2].y-points[1].y, points[2].z-points[1].z); Vector ca=new Vector(points[0].x-points[2].x, points[0].y-points[2].y, points[0].z-points[2].z); Vector deltax=ab.divide(20); Vector deltay=bc.divide(20); for(int u=0;u<20;u++) { for(int v=0;v<=u;v++) { float a=points[0].x + u*deltax.x + v*deltay.x; float b=points[0].y + u*deltax.y + v*deltay.y; float c=points[0].z + u*deltax.z + v*deltay.z; color finalcolor=color(0,0,0); for(int w=0;w