// Screw interpolation // Written by Jarek Rossignac November 2007 float svd=800; float fov=PI/3; pt Cbox = new pt(width/2,height/2,0); // mini-max box center float Rbox=50; PImage floorImage; pt Mouse = new pt(0,0,0); // current mouse position float xr, yr = 0; // mouse coordinates relative to center of window int px=0, py=0; // coordinats of mouse when it was last pressed int r=10; // radius of spheres for displaying vertices color red = color(30,255,255); color green = color(115,255,255); color blue = color(190,255,255); pose P = new pose(), P0 = new pose(), P1 = new pose(), S = new pose(); float s=0.5; int n=10; boolean printall = false; // ** SETUP ** void setup() { size(800, 800, P3D); colorMode(HSB, 256); initView(); C.D+=10; C.pullE(); } // ** DRAW ** void draw() { background(255); lights(); textureMode(NORMALIZED); sphereDetail(4); if ((!keyPressed)&&(mousePressed)) {C.pan(); C.pullE(); }; if ((keyPressed)&&(mousePressed)&&(key==' ')) {C.zoom(); C.pullE(); }; C1.track(C); C2.track(C1); C2.apply(); scale(1,-1,1); float dt=1./n; fill(100,10,100); noStroke(); pushMatrix(); scale(1,0,1); // floor shadows for (float i=0; i<=1; i+=dt) { P.setTo(P0); P.screw(P0,i,P1); P.showT();}; popMatrix(); fill(220,205,205); P0.show(); fill(40,255,205); for (float i=dt; i<1; i+=dt) { P.setTo(P0); P.screw(P0,i,P1); P.show();}; fill(110,205,205); P1.show(); fill(250,255,255); stroke(250,255,255); screwAxisDirection.show(screwAxisPoint); screwAxisPoint.show(0.1); stroke(180,255,55); renderFloor(); } void mousePressed() { C.anchor();}; void mouseReleased() { C.computePose();}; //*** KEY ACTIONS void keyPressed() { float a=PI/32; if (key=='h') {P1.reset();}; if (key=='x') {P1.Tx(1);}; if (key=='X') {P1.Tx(-1);}; if (key=='y') {P1.Ty(1);}; if (key=='Y') {P1.Ty(-1);}; if (key=='z') {P1.Tz(1);}; if (key=='Z') {P1.Tz(-1);}; if (key=='i') {P1.Rx(a);}; if (key=='I') {P1.Rx(-a);}; if (key=='j') {P1.Ry(a);}; if (key=='J') {P1.Ry(-a);}; if (key=='k') {P1.Rz(a);}; if (key=='K') {P1.Rz(-a);}; if (key=='<') {n--; if (n<1) n=1; println("n="+n); }; if (key=='>') {n++; println("n="+n); }; if (key==',') {s-=0.1; println("s="+s); }; if (key=='.') {s+=0.1; println("s="+s); }; if (key=='a') {float ang = angle(P0.I,P1.I)*6/PI; println("angle="+ang); }; if (key=='s') { P.screw(P0,s,P1);}; if (key=='p') { printall=true;}; }; void renderBox() {fill(20,200,200); box(3,2,1);}; void renderFloor() { fill(80,100,205, 150); beginShape(); vertex(-10,-0.1,-10); vertex(-10,-0.1,10); vertex(10,-0.1,10); vertex(10,-0.1,-10); endShape(); };