class Projector { private PImage img, outImage; private Sequence controlSequence; private float x=0, y=0, z=0; private float w=1, h=1; private float px=0, py=0, pz=0; private float pw=1, ph=1, pd=1; private float bright = 1.0; Projector() { img = loadImage("couch2.jpg"); // 372,253 outImage = new PImage(img.width,img.height); } public void setProjectorPos(float _x, float _y, float _z) { px = _x; py = _y; pz = -_z; } public void setProjectorBox(float _w, float _d, float _h) { pw = _w; pd = _d; ph = _h; } public void setScreenPos(float _x, float _y, float _z) { x = _x; y = _y; z = -_z; } public void setScreenSize(float _w, float _h) { w = _w; h = _h; } public void controlledBy(Sequence s) { controlSequence = s; } public void update() { float p = controlSequence.get(); for (int x=0;x>16&0xFF)*p); int g = int((c>>8&0xFF)*p); int b = int((c&0xFF)*p); outImage.set(x,y,color(r,g,b)); } } } public PImage getOutImage() { return outImage; } public void updateBoxBrightness(float p) { bright = p; } public void draw() { //projector: stroke(0,0,0); fill(225*bright,206*bright,166*bright); pushMatrix(); translate(px+pw/2.0,pz-ph/2.0,py+pd/2.0); box(pw,ph,pd); popMatrix(); // draw lines to projected image: float xx1=px+pw/2.0-3; float xx2=px+pw/2.0+3; float yy1 = py+pd; float zz1=pz; float zz2=pz-ph; float xx3=x; float xx4=x+w; float yy3 = y; float zz3=z; float zz4=z-h; float p = controlSequence.get(); fill(255,255,255,64*p); stroke(200,200,200,32*p); beginShape(QUADS); vertex(xx1,zz1,yy1); vertex(xx1,zz2,yy1); vertex(xx3,zz4,yy3); vertex(xx3,zz3,yy3); vertex(xx2,zz1,yy1); vertex(xx2,zz2,yy1); vertex(xx4,zz4,yy3); vertex(xx4,zz3,yy3); vertex(xx1,zz1,yy1); vertex(xx2,zz1,yy1); vertex(xx4,zz3,yy3); vertex(xx3,zz3,yy3); vertex(xx1,zz2,yy1); vertex(xx2,zz2,yy1); vertex(xx4,zz4,yy3); vertex(xx3,zz4,yy3); endShape(); if (p>0) p+=random(-0.03,0.03); if (p<0) p=0; if (p>1) p=1; // screen: float sp = 1.0 - p; noStroke(); fill(255,255,255,80*sp); beginShape(QUADS); vertex(x,z,y-1); vertex(x+w,z,y-1); vertex(x+w,z-h,y-1); vertex(x,z-h,y-1); endShape(); // projected image: fill(0,0,0,255*p); stroke(0,0,0); textureMode(NORMALIZED); beginShape(QUADS); texture(outImage); vertex(x, z, y, 0, 1); vertex(x+w, z, y, 1, 1); vertex(x+w, z-h,y, 1, 0); vertex(x, z-h,y, 0, 0); endShape(); } }