/** a 3d stereo viewing demo by Guru */ PGraphics pg1, pg2; void setup() { size( 600,300); pg1 = createGraphics( 300,300,P3D); pg2 = createGraphics( 300,300,P3D); frameRate(25); smooth(); } float ang = 0; void draw() { pg1.beginDraw(); cam(pg1, 10 ); drawCube(pg1); pg1.endDraw(); pg2.beginDraw(); cam(pg2, -10 ); drawCube(pg2); pg2.endDraw(); image(pg1, 0, 0); image(pg2, width/2, 0); ang += 0.05; } void cam( PGraphics pg, float offset ) { pg.camera(pg.width/2 + offset, pg.height/2, (pg.height/2)/tan(PI*60/360), pg.width/2, pg.height/2, 0, 0, 1, 0 ); } void drawCube(PGraphics pg) { pg.lights(); pg.background(0); pg.pushMatrix(); pg.translate( pg.width/2, pg.height/2, map(mouseX,0,300,40,-200) ); pg.rotateX(ang); pg.rotateY(ang/4); pg.strokeWeight(2); pg.stroke(0,255,0); pg.noFill(); pg.box(100); pg.popMatrix(); }