// HyphaePOVDemo.pde
// (this is really more a demo of the POV export stuff than my Hyphae project)
// David Bollinger, Jan 2007
// http://www.davebollinger.com
// as of Processing 0123
/**
Press space to generate new scene.
Click and drag to rotate.
Arrow keys to dolly camera in x/y.
+/- keys to dolly camera in z.
and IFF you're running this locally, NOT from the web, then...
Press 'w' to write POV-Ray scene file.
Press 's' to save JPG frame.
*/
// POV-Ray SceneManager stuff:
POVSceneManager scene; // absolutely gotta keep a reference to this thingie
POVHeaders hdr; // this reference is only used when rebuilding the scene from scratch
POVBackplane bak; // this reference is only used when rebuilding the scene from scratch
POVCamera cam; // this reference is used interactively and when rebuilding the scene
POVLights lit; // this reference is only used when rebuilding the scene from scratch
POVRotator rot; // this reference is used interactively and when rebuilding the scene
POVScaler sca; // this reference is only used when rebuilding the scene from scratch
void setup() {
size(300,300,P3D);
frameRate(30);
// POV-Ray SceneManager stuff:
scene = new POVSceneManager();
hdr = new POVHeaders();
bak = new POVBackplane();
cam = new POVCamera();
lit = new POVLights();
sca = new POVScaler();
rot = new POVRotator();
// start it up
BuildScene();
}
void BuildScene() {
// wipe the entire scene
scene.clear();
// add the "non-geometry" stuff
scene.add(hdr);
scene.add(bak);
scene.add(cam); cam.defaults();
scene.add(lit);
scene.add(sca); sca.scale = 20f;
scene.add(rot); rot.defaults();
// add some geometry - using whatever means desired.
// here the pickover attractor is used, and why not?
float a = random(-PI,PI);
float b = random(-PI,PI);
float c = random(-PI,PI);
float d = random(-PI,PI);
float x = random(-1f,1f);
float y = random(-1f,1f);
float z = random(-1f,1f);
for (int i=-10; i<100; i++) {
float xp = sin(a*y) - z * cos(b*x);
float yp = z * sin(c*x) - cos(d*y);
float zp = sin(x);
if (i >= 0) {
float vx = xp - x;
float vy = yp - y;
float vz = zp - z;
color clr = color(x*x*255,y*y*255,z*z*255);
// "hyphae" -style triangles are based on velocity and/or acceleration,
// which doesn't work as well on the pickover attractor, but good enough:
scene.add( new POVTriangle( x,y,z, x+vx,y+vy,z+vz, x-vy,y-vz,z-vx, clr) );
}
x=xp; y=yp; z=zp;
}
}
void draw() {
scene.draw(g); // gosh, that was tough ;-)
}
void keyPressed() {
if (key=='s') {
saveFrame("frame.jpg");
println("JPG WRITTEN.");
}
if (key=='w') {
scene.write("scene.pov"); // gosh, that was tough ;-)
}
if (key==' ') {
BuildScene();
}
// CAMERA MOVEMENT
float dc = 1f;
if (key=='-') { cam.eyez+=dc; }
if (key=='+') { cam.eyez-=dc; }
if (keyCode==LEFT) { cam.eyex-=dc; cam.atx-=dc; }
if (keyCode==RIGHT){ cam.eyex+=dc; cam.atx+=dc; }
if (keyCode==UP) { cam.eyey-=dc; cam.aty-=dc; }
if (keyCode==DOWN) { cam.eyey+=dc; cam.aty+=dc; }
}
void mouseDragged() {
float dx = mouseX-pmouseX;
float dy = mouseY-pmouseY;
rot.rotx += -dy * 0.01;
rot.roty += dx * 0.01;
}