// cam3D v.03 elout de kok | 23 september 2003 | http://www.xs4all.nl/~elout/ // this needs a 128*128px image in your data diretory called 'image128.gif' // processing - version.0060 // use your arrow keys to zoom in/out BImage tex1,mybackground; //texture width/height int texw=128; int texh=128; //------mouse & stuff int mx,my,sx=140,sy=120, middenx,middeny; float xangle,yangle,zangle; float zpos; // cube points int [] pointbuf= { -50 , 50 , -50 , //0 50 , 50 , -50 , //1 -50 , 50 , 50 , //2 50 , 50 , 50 , //3 -50 , -50 , -50 , //4 50 , -50 , -50 , //5 -50 , -50 , 50 , //6 50 , -50 , 50 //7 }; //cube faces int [] facebuf= { 0 ,2 ,3 ,1, 4 ,5 ,7 ,6, 0 ,1 ,5 ,4, 1 ,3 ,7 ,5, 3 ,2 ,6 ,7, 2 ,0 ,4 ,6 }; void setup() { size(600,400); noStroke(); //load an 'empty' texture image - in your data folder //now 128*128 pixels - needed for texturing! tex1 = loadImage("image128.gif"); middenx=width/2; middeny=height/2; zpos=0; beginVideo(texw,texh, 6); } void loop() { //draw the cam on the screen image(video, 0, 0); //copy the screen to your texture image for (int i=0;i middenx){sx=0-((middenx-mx)/2);} else{sx=((mx-middenx)/2);} if ( my > middeny){sy=0-((middeny-my)/2);} else{sy=((my-middeny)/2);} xangle= xangle+(sy/4000.0f); yangle= yangle+((sx-sy)/4000.0f); zangle= zangle+(sx/4000.0f); rotateX(xangle); rotateY(yangle); rotateZ(zangle); //draw a cube alpha is 160 fill(255,255,255,160); drawtexcube(tex1,1.0f); //draw a cube alpha is 80 fill(255,255,255,80); drawtexcube(tex1,2.0f); //put in a small delay, so the system can handle other tasks as well delay(25); } void drawtexcube(BImage mytexture,float size) { int step=0; beginShape(QUADS); texture(mytexture); for (int i=0;i<6;i++) { vertex(pointbuf[facebuf[step]*3]*size,pointbuf[(facebuf[step]*3)+1]*size,pointbuf[(facebuf[step]*3)+2]*size,0,0); vertex(pointbuf[facebuf[step+1]*3]*size,pointbuf[(facebuf[step+1]*3)+1]*size,pointbuf[(facebuf[step+1]*3)+2]*size,texw,0); vertex(pointbuf[facebuf[step+2]*3]*size,pointbuf[(facebuf[step+2]*3)+1]*size,pointbuf[(facebuf[step+2]*3)+2]*size,texw,texh); vertex(pointbuf[facebuf[step+3]*3]*size,pointbuf[(facebuf[step+3]*3)+1]*size,pointbuf[(facebuf[step+3]*3)+2]*size,0,texh); step=step+4; } endShape(); }