100 likes | 215 Views
Project P3: CSG Lecture 08, File P3.ppt Due Feb 14 Individual (Code and PPP). CS1050: Understanding and Constructing Proofs . Spring 2006. Jarek Rossignac. Objectives. Implement a 2D design system supporting Disk primitives CSG trees with Boolean operators
E N D
Project P3: CSGLecture 08, File P3.pptDue Feb 14Individual (Code and PPP) CS1050: Understanding and Constructing Proofs Spring 2006 Jarek Rossignac
Objectives • Implement a 2D design system supporting • Disk primitives • CSG trees with Boolean operators • Interactive placement of primitives • Rendering of the resulting image • Extensions for extra credit • Interactive editing of CSG tree
Disk class and point-in-disk test class Disk { // class for disk primitive int x, y, r; Disk (int px, int py, int pr) {x=px; y=py; r=pr;}; void move (int px, int py) {x=px; y=py;}; boolean in (int pi, int pj) { boolean isIn=false; if (sq(pi-x)+sq(pj-y)<sq(r)) {isIn=true;}; return(isIn); }; void write () {println("x="+x+", y="+y+", r="+r);}; void show () {ellipse(x,y,2*r,2*r);;}; };
Setting up 3 primitives Disk[] P = new Disk[np]; // array of primitives void setup() { … P[0]=new Disk(150,150,100); // make primitives with Cx, Cy, radius P[1]=new Disk(250,150,100); P[2]=new Disk(200,250,100);
Editing the primitives int pp=0; // currently selected primitive for moving it void keyPressed() { switch(key) { case 'p': for(int k=0; k<np; k++) {print("P["+k+"] : "); P[k].write();}; break; case '.': pp=(pp+1) % np; break; // select next primitive case ',': pp=(pp-1) % np; break; case '>': P[pp].r += 10; break; // incrase the radius of selected primitive case '<': P[pp].r -= 10; break; … }; void mousePressed() {P[pp].move(mouseX,mouseY);}; // move center of selected primitive
Draw calls pmc void draw() { // paints pixel (i,j) based on its classification for(int j=0; j<height; j++) { // j defines row and goes DOWN for (int i=0; i<width; i++) { // I defines the pixel in row if (pmc(0,i,j)) { set(i,j,green);} else set(i,j,red);};}; // set color depending on pmc … for(int k=0; k<np; k++) {P[k].show();}; // draws circles }
Point-in-CSG test boolean pmc (int n, int pi, int pj) { // returns true if pixel (pi,pj) is in region of node n boolean res=false; switch(o[n]) { case 'p': res=P[L[n]].in(pi,pj); break; // if n is a primitive, call its "in" method // *** edit to improve performance by avoiding redundant recursive calls case '-': res= pmc(L[n],pi,pj) && !pmc(R[n],pi,pj); break; // if difference, combine result of recursive call // *** add here the lines for union , intersection, xor }; return(res); };
Assigned implementation • Add the code for the other operations • Modify these statements to avoid redundant recursions • if P in A, then P in A–B, hence, no need to test against B • Manually edit the code defining the CSG tree and primitive lists to produce a Mikey Mouse face • Ears, slit eyes, smiley mouth. Front or profile • Add key action to change selected CSG node • (initially 0, root) • * P means go to parent (or stay if root) • * L means go toleft child (or stay if leaf) • * R means go to righ child (or stay if leaf) • Key actions to edit the operator at the selected CSG node • Key action to change the ID of the primitive at the currently selected leaf node to be the ID of the currently selected primitive
Extra credit Extra credit if develop data-structure and code to support: • Keys to expand primitive nodes to Boolean nodes (press key for desired operator): +5% • Keys to collapse Boolean nodes to primitive: +5% • Add code and key-actions to save and load the CSG and Primitives: +10%
Deliverables The usual on PPP with applet, code with COMMENTS, Include the definition and image of your Mikey Mouse Clearly indicate which extra credit parts you have implemented