Not so easy, since it relies on the new renderer I'm writing to make it work properly, so it'll be hard to test, but the basic part is:
Code:void setup()
{
// size(800,600,"hardcorepawn.opengl.PGraphicsGL");
size(800,600,P3D);
camera(0,0,0,0,0,-1,0,-1,0);
perspective(PI/3.0,4.0/3.0,0.001,1000);
noStroke();
var=0;
verticies=new float[484][3];
}
void draw()
{
float mx=((mouseX-(width/2))/(float)width)*TWO_PI;
float my=((mouseY)/(float)height);
var-=0.04;
background(40);
camera(200*sin(mx),100*my,200*cos(mx),0,0,0,0,-1,0);
lightSpecular(255,200,100);
directionalLight(255,255,255,0,1,0);
fill(30,60,120);
ambient(30,30,30);
specular(200,180,100);
shininess(128.0);
for(int i=0;i<22;i++)
for(int j=0;j<22;j++)
verticies[j+i*22]=new float[]{(i-10)*10,10*sin(var+(sqrt(pow(i-10,2)+pow(j-10,2)))),(j-10)*10};
for(int i=1;i<20;i++)
{
beginShape(QUAD_STRIP);
for(int j=1;j<20;j++)
{
Vector norm=getNormal(i,j);
normal(norm.nx,norm.ny,norm.nz);
float[] f=verticies[(i)*22+j];
vertex(f[0],f[1],f[2]);
norm=getNormal(i+1,j);
normal(norm.nx,norm.ny,norm.nz);
f=verticies[(i+1)*22+j];
vertex(f[0],f[1],f[2]);
}
endShape();
}
if(frameCount%90==89)
println(framerate);
}
Vector getNormal(int x, int y)
{
Vector v1=new Vector(verticies[(x-1)*22+y][0],verticies[(x-1)*22+y][1],verticies[(x-1)*22+y][2]);
Vector v2=new Vector(verticies[(x+1)*22+y][0],verticies[(x+1)*22+y][1],verticies[(x+1)*22+y][2]);
Vector v3=new Vector(verticies[x*22+y-1][0],verticies[x*22+y-1][1],verticies[x*22+y-1][2]);
Vector v4=new Vector(verticies[x*22+y+1][0],verticies[x*22+y+1][1],verticies[x*22+y+1][2]);
return cross(dir(v3,v4),dir(v1,v2));
}
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 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);
}
Vector dir(Vector a, Vector b)
{
return new Vector(a.x-b.x,a.y-b.y,a.z-b.z);
}