//constants int NONE = 0; int BASE1 = 1; int BASE2 = 2; int P1 = 3; int P2 = 4; int P3 = 5; int P4 = 6; int B1_P = 7; int B2_P = 8; int B3_P = 9; int B4_P = 10; int T1_P = 11; int T2_P = 12; int T3_P = 13; int T4_P = 14; int B1_E = 15; int B2_E = 16; int B3_E = 17; int B4_E = 18; int T1_E = 19; int T2_E = 20; int T3_E = 21; int T4_E = 22; //control points int control=NONE; Point plan_bline_1, plan_bline_2; // perspective points BLinePoint p1, p2, p3, p4; //corner points Point b1, b2, b3, b4; Point t1, t2, t3, t4; // perspective lines Line plan_p1b2, plan_p1t2, plan_p2b3, plan_p2t3, plan_p3b1, plan_p3t1, plan_p4b2, plan_p4t2; Line el_p1t2, el_p2t3, el_p3t1, el_p4t2; HLine fold; HLine el_bline; BLine plan_bline; void setup() { size(768,600); noFill(); background(0); smooth(); // set initial vals plan_bline_1 = new Point(0,(height/2) + 75); plan_bline_2 = new Point(width,height/2); plan_bline = new BLine(plan_bline_1, plan_bline_2); plan_bline.setColor(100); el_bline = new HLine(height-25); el_bline.setColor(100); fold = new HLine(height/2 + 100); fold.setColor(0,0,155); p1 = new BLinePoint(50, el_bline, plan_bline); p2 = new BLinePoint(100, el_bline, plan_bline); p3 = new BLinePoint(500, el_bline, plan_bline); p4 = new BLinePoint(575, el_bline, plan_bline); p1.setColor(255,0,0); p2.setColor(255,0,0); p3.setColor(255,0,0); p4.setColor(255,0,0); Point[] p_arr = {p1,p2,p3,p4}; plan_bline_1.children = p_arr; plan_bline_2.children = p_arr; initCornerPoints(); //perspective lines plan_p1b2 = new RLine(p1, b2); plan_p1t2 = new RLine(p1, t2); plan_p2b3 = new RLine(p2, b3); plan_p2t3 = new RLine(p2, t3); plan_p3b1 = new RLine(p3, b1); plan_p3t1 = new RLine(p3, t1); plan_p4b2 = new RLine(p4, b2); plan_p4t2 = new RLine(p4, t2); el_p1t2 = new RLine(p1, t2, ELEVATION); el_p2t3 = new RLine(p2, t3, ELEVATION); el_p3t1 = new RLine(p3, t1, ELEVATION); el_p4t2 = new RLine(p4, t2, ELEVATION); b1.onLines(plan_p1b2, plan_p3b1); t1.onLines(plan_p1t2, plan_p3t1); t1.onLinesZ(el_p1t2, el_p3t1); b2.onLines(plan_p1b2, plan_p4b2); t2.onLines(plan_p1t2, plan_p4t2); t2.onLinesZ(el_p1t2, el_p4t2); b3.onLines(plan_p4b2, plan_p2b3); t3.onLines(plan_p4t2, plan_p2t3); t3.onLinesZ(el_p4t2, el_p2t3); b4.onLines(plan_p2b3, plan_p3b1); t4.onLines(plan_p2t3, plan_p3t1); t4.onLinesZ(el_p2t3, el_p3t1); p4.initChildren(t3, b3); p3.initChildren(b4, t4); p2.initChildren(b4, t4); p1.initChildren(b1, t1); t1.initChildren(t4); b1.initChildren(b4); t3.initChildren(t4); b3.initChildren(b4); b2.initChildren(b1, b3); t2.initChildren(t1, t3); b4.children = new Point[0]; t4.children = new Point[0]; } void draw() { if (mousePressed) { if (control == P1) { p1.X(mouseLimits(0,width,mouseX)); } if (control == P2) { p2.X(mouseLimits(0,width,mouseX)); } if (control == P3) { p3.X(mouseLimits(0,width,mouseX)); } if (control == P4) { p4.X(mouseLimits(0,width,mouseX)); } if (control == B1_P) { b1.reposition(mouseLimits(0,width,mouseX), mouseLimits(0,fold.height,mouseY)); } if (control == B2_P) { b2.X(mouseLimits(0,width,mouseX)); b2.Y(mouseLimits(0,fold.height,mouseY)); } if (control == B3_P) { b3.reposition(mouseLimits(0,width,mouseX), mouseLimits(0,fold.height,mouseY)); } if (control == B4_P) { b4.reposition(mouseLimits(0,width,mouseX), mouseLimits(0,fold.height,mouseY)); } if (control == T1_P) { t1.reposition(mouseLimits(0,width,mouseX), mouseLimits(0,fold.height,mouseY)); } if (control == T2_P) { t2.X(mouseLimits(0,width,mouseX)); t2.Y(mouseLimits(0,fold.height,mouseY)); } if (control == T3_P) { t3.reposition(mouseLimits(0,width,mouseX), mouseLimits(0,fold.height,mouseY)); t2.X(t2.x); } if (control == T4_P) { t4.reposition(mouseLimits(0,width,mouseX), mouseLimits(0,fold.height,mouseY)); t2.X(t2.x); } if (control == B1_E) { b1.X(mouseLimits(0,width,mouseX)); b1.Y(b1.on_line_1.getY(b1.x)); } if (control == B2_E) { b2.X(mouseLimits(0,width,mouseX)); } if (control == B3_E) { b3.X(mouseLimits(0,width,mouseX)); b3.Y(b3.on_line_1.getY(b3.x)); } if (control == B4_E) { b4.X(mouseLimits(0,width,mouseX)); b4.repositionBEl(); } if (control == T1_E) { //t1.X(mouseLimits(0,width,mouseX)); //t1.Z(mouseLimits(fold.height, el_bline.height, mouseY)); t1.repositionTEl(mouseLimits(0,width,mouseX), mouseLimits(fold.height, el_bline.height, mouseY)); } if (control == T2_E) { t2.X(mouseLimits(0,width,mouseX)); t2.Z(mouseLimits(fold.height, el_bline.height, mouseY)); } if (control == T3_E) { t3.repositionTEl(mouseLimits(0,width,mouseX), mouseLimits(fold.height, el_bline.height, mouseY)); t2.X(t2.x); } if (control == T4_E) { t4.repositionTEl(mouseLimits(0,width,mouseX), mouseLimits(fold.height, el_bline.height, mouseY)); t2.X(t2.x); } if (control == BASE1) { plan_bline.start.Y(mouseLimits(0, fold.height, mouseY)); } if (control == BASE2) { plan_bline.end.Y(mouseLimits(0, fold.height, mouseY)); } } drawEm(); } void mousePressed() { control = chooseControl(); } int chooseControl() { if (abs(mouseX - p1.x) < 3 && (abs(mouseY - el_bline.height) < 3 || abs(mouseY - p1.y) <3)) { return P1; } else if (abs(mouseX - p2.x) < 3 && (abs(mouseY - el_bline.height) < 3 || abs(mouseY - p2.y) <3)) { return P2; } else if (abs(mouseX - p3.x) < 3 && (abs(mouseY - el_bline.height) < 3 || abs(mouseY - p3.y) <3)) { return P3; } else if (abs(mouseX - p4.x) < 3 && (abs(mouseY - el_bline.height) < 3 || abs(mouseY - p4.y) <3)) { return P4; } else if (abs(mouseX-b1.x) < 3 && (abs(mouseY - b1.y) < 3)) { return B1_P; } else if (abs(mouseX-b2.x) < 3 && (abs(mouseY - b2.y) < 3)) { return B2_P; } else if (abs(mouseX-b3.x) < 3 && (abs(mouseY - b3.y) < 3)) { return B3_P; } else if (abs(mouseX-b4.x) < 3 && (abs(mouseY - b4.y) < 3)) { return B4_P; } else if (abs(mouseX-t1.x) < 3 && (abs(mouseY - t1.y) < 3)) { return T1_P; } else if (abs(mouseX-t2.x) < 3 && (abs(mouseY - t2.y) < 3)) { return T2_P; } else if (abs(mouseX-t3.x) < 3 && (abs(mouseY - t3.y) < 3)) { return T3_P; } else if (abs(mouseX-t4.x) < 3 && (abs(mouseY - t4.y) < 3)) { return T4_P; } else if (abs(mouseX-b1.x) < 3 && (abs(mouseY - el_bline.height) < 3)) { return B1_E; } else if (abs(mouseX-b2.x) < 3 && (abs(mouseY - el_bline.height) < 3)) { return B2_E; } else if (abs(mouseX-b3.x) < 3 && (abs(mouseY - el_bline.height) < 3)) { return B3_E; } else if (abs(mouseX-b4.x) < 3 && (abs(mouseY - el_bline.height) < 3)) { return B4_E; } else if (abs(mouseX-t1.x) < 3 && (abs(mouseY - t1.z) < 3)) { return T1_E; } else if (abs(mouseX-t2.x) < 3 && (abs(mouseY - t2.z) < 3)) { return T2_E; } else if (abs(mouseX-t3.x) < 3 && (abs(mouseY - t3.z) < 3)) { return T3_E; } else if (abs(mouseX-t4.x) < 3 && (abs(mouseY - t4.z) < 3)) { return T4_E; } else if (abs(mouseX - 0) < 3 && abs(mouseY-plan_bline.start.y) < 4) { return BASE1; } else if (abs(mouseX - width) < 3 && abs(mouseY-plan_bline.end.y) < 4) { return BASE2; } else return 0; } float mouseLimits(float upper, float lower, float val) { if (val > lower) { return lower; } else if (val < upper) { return upper; } else return val; } // get the y coordinate at point x on a line spanning width of screen // simpler version of setPt() float getY(float x, float y1, float y2) { float a = (y2-y1)/width; return (a*x)+y1; } // find y coordinate at point x on line given by endpoints float setPt(float x, float x1, float y1, float x2, float y2) { float a = (y2-y1)/(x2-x1); float b = y1-(a*x1); return (a*x)+b; } // returns x coordinate of intersection of two lines float intersect(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { float a1 = (y2-y1)/(x2-x1); float a2 = (y4-y3)/(x4-x3); float b1 = y1 - (a1*x1); float b2 = y3 - (a2*x3); return (b2 - b1)/(a1 - a2); }