// Simulated screen for view control by dragging points // Written by Jarek Rossignac June 2006. Modified Septmber 2007 import processing.opengl.*; // load OpenGL import javax.media.opengl.*; import javax.media.opengl.glu.*; import java.nio.*; GL gl; GLU glu; boolean pickS=false; // ** SETUP ** void setup() { size(800, 800, OPENGL); setColors(); sphereDetail(12); //smooth(); PFont font = loadFont("Courier-14.vlw"); textFont(font, 12); // font for writing labels on screen this.addMouseWheelListener(new CMouseWheelEvent());// wheel gl=((PGraphicsOpenGL)g).gl; glu=((PGraphicsOpenGL)g).glu; M.declare(); S.declare(); C.makeMesh(M); threshold=C.average(); } // ** DRAW ** void draw() { lights(); directionalLight(0,0,128,0,1,0); directionalLight(0,0,128,0,0,1); background(white); fill(black); text("Click&drag on nodes to change their value. Hold 't' & drag to change v ("+threshold+")",10,20); noFill(); fill(black); text("Toggle 'r' to see refined isosurface. Press 's' to smooth it, 'f' to fit ("+C.value(S.g())+")",10,40); noFill(); fill(black); text("Hold 1, 2, or 3 and drag to change the view. Press 'h' to reset it.",10,60); noFill(); pushMatrix(); translate(float(height)/2, float(height)/2, 0.0); // center view wrt window if (!picked) if (keyPressed&&mousePressed) {changeView(); if (key=='t') {threshold+=(mouseX-pmouseX)/10.; }; }; updateView(); C.showBalls(); C.showThreshold(); if (!keyPressed&&mousePressed) { if (pick) {mark.setTo( fromMouse() ); eye.setTo(fromOrigin()); picked=C.pickBall(mark); pick=false;} ; if (picked) C.changeRadius(); else { viewPar[4][0]+=mouseX-pmouseX; viewPar[4][1]+=mouseY-pmouseY; }; }; C.updateCornerVertices(M); C.showEdges(); noFill(); stroke(black); M.showEdges(); fill(red); stroke(red); M.showIsopointsOnSticks(threshold); if (showRefined) {fill(cyan,80); noStroke(); S.showTriangles(); // fill(green); S.showVertices(2); if (pickS) {pickS=false; mark.setTo(fromMouse()); eye.setTo(fromOrigin()); S.hitTriangle(); }; stroke(dblue); noFill(); S.showBorder(); S.show(); } else { noFill(); stroke(dmagenta); M.traceIsocurves(threshold); fill(orange,80); stroke(red); M.fanIsocurves(threshold); }; popMatrix(); } //*** KEY ACTIONS (details in keys tab) void keyPressed() { keys(); }; void mousePressed() { pick=true; }; void mouseReleased() {picked=false;}; // reset the view if any key was pressed when mouse was released