// 3d Surface // David Montie // August 23, 2005 float x; float y; float noder = 10; // node radius float nodex; // node position x,y,z float nodey; float nodez; float rollx = 8; float rolly = 30; float rollz = 0; float slidex; float slidey = -100; float zoom; // slidez boolean xon = false; boolean yon = false; boolean zoomon = false; boolean rollxon = false; boolean rollyon = false; boolean rollzon = false; boolean slidexon = false; boolean slideyon = false; boolean slideon = false; boolean rotateon = false; boolean twiston = false; boolean allon = false; boolean nodegrab = false; void setup() { size (700, 700, P3D); framerate (30); stroke (0); fill (100); } void draw () { background (255); lights(); PFont myFont; myFont = loadFont("ArialMT-16.vlw"); x = mouseX - width/2; y = mouseY - height/2; // Menu Box ++++++++++++++++++++++++++++++++++++++ rect (0, 0, width, 64); if (zoomon) { yon = true; zoom = y * 2; // zoom fill (0,250,0); rect (502, 2, 98, 18); //rect (2, 2, 98, 18); fill (0); textFont(myFont); text ("Zoom: ON", 508, 17, 0); noFill(); } else { fill (100); rect (502, 2, 98, 18); //rect (2, 2, 98, 18); fill (0); textFont(myFont); text ("Zoom: OFF", 508, 17, 0); noFill(); } if (slidexon) { xon = true; slidex = x; // side to side fill (0,250,0); rect (2, 2, 98, 18); //rect (102, 2, 98, 18); fill (0); textFont(myFont); text ("Slide X: ON", 7, 17, 0); noFill(); } else { fill (100); rect (2, 2, 98, 18); //rect (102, 2, 98, 18); fill (0); textFont(myFont); text ("Slide X: OFF", 7, 17, 0); noFill(); } if (slideyon) { yon = true; slidey = y; // up and down fill (0,250,0); rect (102, 2, 98, 18); //rect (202, 2, 98, 18); fill (0); textFont(myFont); text ("Slide Y: ON", 108, 17, 0); noFill(); } else { fill (100); rect (102, 2, 98, 18); //rect (202, 2, 98, 18); fill (0); textFont(myFont); text ("Slide Y: OFF", 108, 17, 0); noFill(); } if (rollxon) { xon = true; rollx = (x/4); // side to side fill (0,250,0); rect (202, 2, 98, 18); //rect (302, 2, 98, 18); fill (0); textFont(myFont); text ("Roll X: ON", 212, 17, 0); noFill(); } else { fill (100); rect (202, 2, 98, 18); //rect (202, 2, 98, 18); fill (0); textFont(myFont); text ("Roll X: OFF", 212, 17, 0); noFill(); } if (rollyon) { yon = true; rolly = (y/4); // up and down fill (0,250,0); rect (302, 2, 98, 18); //rect (402, 2, 98, 18); fill (0); textFont(myFont); text ("Roll Y: ON", 312, 17, 0); noFill(); } else { fill (100); rect (302, 2, 98, 18); //rect (402, 2, 98, 18); fill (0); textFont(myFont); text ("Roll Y: OFF", 312, 17, 0); noFill(); } if (rollzon) { xon = true; rollz = (x/2); // spin around fill (0,250,0); rect (402, 2, 98, 18); //rect (502, 2, 98, 18); fill (0); textFont(myFont); text ("Twist: ON", 412, 17, 0); noFill(); } else { fill (100); rect (402, 2, 98, 18); //rect (502, 2, 98, 18); fill (0); textFont(myFont); text ("Twist: OFF", 412, 17, 0); noFill(); } if (xon) { fill (0, 250, 0); rect (602, 2, 47, 18); fill (0); textFont(myFont); text ("X", 620, 17, 0); noFill(); } else { fill (100); rect (602, 2, 47, 18); fill (0); textFont(myFont); text ("X", 620, 17, 0); noFill(); } if (yon) { fill (0, 250, 0); rect (651, 2, 47, 18); fill (0); textFont(myFont); text ("Y", 670, 17, 0); noFill(); } else { fill (100); rect (651, 2, 47, 18); fill (0); textFont(myFont); text ("Y", 670, 17, 0); noFill(); } // second menu row ++++++++++++++++++++ fill (150); rect (502, 23, 98, 18); //rect (2, 23, 98, 18); // Button 1 - Zoom fill (0); stroke (0); textFont(myFont); text (round (zoom), 535, 38); noFill(); fill (150); rect (2, 23, 98, 18); //rect (102, 23, 98, 18); // Button 2 - Slide X fill (0); stroke (0); textFont(myFont); text (round (slidex), 35, 38); noFill(); fill (150); rect (102, 23, 98, 18); //rect (202, 23, 98, 18); // Button 3 - Slide Y fill (0); stroke (0); textFont(myFont); text (round (slidey), 135, 38); noFill(); fill (150); rect (202, 23, 98, 18); //rect (302, 23, 98, 18); // Button 4 - Rotate X fill (0); stroke (0); textFont(myFont); text (round (rollx), 235, 38, 0); noFill(); fill (150); rect (302, 23, 98, 18); //rect (402, 23, 98, 18); // Button 5 - Rotate Y fill (0); stroke (0); textFont(myFont); text (round (rolly), 335, 38, 0); noFill(); fill (150); rect (402, 23, 98, 18); //rect (502, 23, 98, 18); // Button 6 - Rotate Z fill (0); stroke (0); textFont(myFont); text (round (rollz), 435, 38, 0); noFill(); fill (150); rect (602, 23, 47, 18); // Button 7 - X coordinate fill (0); stroke (0); textFont(myFont); text (round (x), 612, 38, 0); noFill(); fill (150); rect (651, 23, 47, 18);; // Button 8 - Y coordinate fill (0); stroke (0); textFont(myFont); text (round (y), 661, 38, 0); noFill(); // third menu row ++++++++++++++++++++ // Button 1 - Slide if (slideon) { fill (0, 150, 250); rect (2, 44, 198, 18); fill (0); stroke (0); textFont(myFont); text ("Slide", 82, 59); noFill(); } else { fill (250); rect (2, 44, 198, 18); fill (0); stroke (0); textFont(myFont); text ("Slide", 82, 59); noFill(); } // Button 2 - Rotate if (rotateon) { fill (0, 150, 250); rect (202, 44, 198, 18); fill (0); stroke (0); textFont(myFont); text ("Roll", 287, 59); noFill(); } else { fill (250); rect (202, 44, 198, 18); fill (0); stroke (0); textFont(myFont); text ("Roll", 287, 59); noFill(); } // Button 3 - Twist if (twiston) { fill (0, 150, 250); rect (402, 44, 198, 18); fill (0); stroke (0); textFont(myFont); text ("Twist", 482, 59); noFill(); } else { fill (250); rect (402, 44, 198, 18); fill (0); stroke (0); textFont(myFont); text ("Twist", 482, 59); noFill(); } // Button 4 - All if (allon) { fill (0, 150, 250); rect (602, 44, 96, 18); fill (0); stroke (0); textFont(myFont); text ("< All >", 630, 59); noFill(); } else { fill (250); rect (602, 44, 96, 18); fill (0); stroke (0); textFont(myFont); text ("< All >", 630, 59); noFill(); } pushMatrix(); //into active window ++++++++++++++++++++++++++++++ translate (slidex + width/2, slidey + height/2, zoom - height/2); rotateZ (PI/2); rotateX (radians (rollx)); rotateY (radians (rolly) + PI/2); //scale (); pushMatrix(); rotateX (radians (-rollz)); // Cartesian Coordinates ++++++++++++++++++++++++++++++++++ line(10,0,-10,0); pushMatrix(); translate (10, 5, 15); rotateY (PI/2); textFont(myFont); fill (0); text("X", 12, 0); popMatrix(); line(0,10,0,-10); pushMatrix(); translate (-3, 10, -7); rotateX (PI/2); textFont(myFont); fill (0); text("Y", 0, 12); popMatrix(); line(0,0,10,0,0,-10); textFont(myFont); fill (0); text("Z", -3, 4, 12); noFill(); // Cusp Shape ++++++++++++++++++++++++++++++++++++++++++++ beginShape(POLYGON); vertex (0, 0, 0); // Origin Axis vertex (0, -20, -10); vertex (0, -100, -40); vertex (0, -150, -48); vertex (0, -200, -50); // NW corner vertex (-400, -200, -110); //SW corner vertex (-400, -150, -110); vertex (-400, -90, -108); vertex (-400, -50, -105); vertex (-400, 0, -100); //e vertex (-400, 10, -98); vertex (-400, 25, -90); vertex (-400, 35, -85); vertex (-400, 45, -70); vertex (-400, 50, -50); // E pleat max vertex (-400, 45, -30); vertex (-400, 35, -15); vertex (-400, 25, -10); vertex (-400, 10, -2); vertex (-400, 1, 0); vertex (-400, 0, 0); // Cusp Axis vertex (-400, -1, 0); vertex (-400, -10, 2); vertex (-400, -25, 10); vertex (-400, -35, 15); vertex (-400, -45, 30); vertex (-400, -50, 50); // W pleat max vertex (-400, -45, 70); vertex (-400, -35, 85); vertex (-400, -25, 90); vertex (-400, -10, 98); vertex (-400, 0, 100); // d vertex (-400, 50, 105); vertex (-400, 90, 108); vertex (-400, 150, 110); vertex (-400, 200, 110); //SE corner vertex (0, 200, 50); //NE corner vertex (0, 150, 48); vertex (0, 100, 40); vertex (0, 20, 10); endShape(); stroke (160); line (-100, 0, 0, -400, 50, -50); //cusp edge line (-100, 0, 0, -400, -50, 50); line (-100, 0, 0, -400, 0, -100); // transition line (-100, 0, 0, -400, 0, 100); // transition stroke (80); line (-100, 0, 0, -400, 0, 0); // axis stroke (0); // Node +++++++++++++++++++++++++++++++++++++++++++++++ noStroke(); fill (200); pushMatrix(); translate (nodex, nodey, nodez); sphere (noder); popMatrix(); stroke (0); popMatrix(); // out of active window popMatrix(); } void mousePressed() { if (mouseX > 1 && mouseX < 85 && mouseY > 1 && mouseY < 18) { // mouseoverbutton 1 slidexon = true; } if (mouseX > 100 && mouseX < 200 && mouseY > 1 && mouseY < 18) { // mouseoverbutton 2 slideyon = true; } if (mouseX > 200 && mouseX < 300 && mouseY > 1 && mouseY < 18) { // mouseoverbutton 3 rollxon = true; } if (mouseX > 300 && mouseX < 400 && mouseY > 1 && mouseY < 18) { // mouseoverbutton 4 rollyon = true; } if (mouseX > 400 && mouseX < 500 && mouseY > 1 && mouseY < 18) { // mouseoverbutton 5 rollzon = true; } if (mouseX > 500 && mouseX < 600 && mouseY > 1 && mouseY < 18) { // mouseoverbutton 6 zoomon = true; } if (mouseX > 1 && mouseX < 200 && mouseY > 40 && mouseY < 60) { // mouseoverbutton 1 - row 3 slidexon = true; slideyon = true; slideon = true; } if (mouseX > 200 && mouseX < 400 && mouseY > 40 && mouseY < 60) { // mouseoverbutton 2 - row 3 rollxon = true; rollyon = true; rotateon = true; } if (mouseX > 400 && mouseX < 600 && mouseY > 40 && mouseY < 60) { // mouseoverbutton 3 - row 3 rollzon = true; zoomon = true; twiston = true; } if (mouseX > 600 && mouseY > 40 && mouseY < 60) { // mouseoverbutton 4 - row 3 allon = true; twiston = true; rotateon = true; slideon = true; slidexon = true; slideyon = true; rollxon = true; rollyon = true; rollzon = true; zoomon = true; } if (mouseY > 60) { // cancel button engagement if (yon) { yon = false; } if (xon) { xon = false; } if (zoomon) { zoomon = false; } if (rollxon) { rollxon = false; } if (rollyon) { rollyon = false; } if (rollzon) { rollzon = false; } if (slidexon) { slidexon = false; } if (slideyon) { slideyon = false; } if (slideon) { slideon = false; } if (rotateon) { rotateon = false; } if (twiston) { twiston = false; } if (allon) { allon = false; } } if (mouseX <= nodex + noder && mouseX >= nodex - noder && mouseY <= nodey + noder && mouseY >= nodex - noder) { nodegrab = true; } else { nodegrab = false; } } //void mouseReleased() { //void mouseDragged() //void keyPressed () //void keyReleased ()