Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
RangeSearch/kdtest/kdtest.pde
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
162 lines (141 sloc)
2.63 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Console con; | |
Camera cam; | |
Mode statusLine; | |
KdTree tree; | |
ArrayList<Point> pointList; | |
boolean drawCon, drawHelp, drawTree, drawGnoman; | |
float epsilon = 0.000001; | |
int G_mode; | |
// 1 = SCALE | |
// 2 = PAN | |
// 3 = ROTATE | |
// 4 = PLACE | |
// 5 = SELECT | |
void setup() { | |
size(800,800); | |
background(120); | |
ellipseMode(CENTER); | |
con = new Console(); | |
cam = new Camera(); | |
statusLine = new Mode(); | |
pointList = new ArrayList<Point>(); | |
tree = null; | |
drawCon = false; | |
drawHelp = true; | |
drawGnoman = true; | |
drawTree = true; | |
G_mode = 1; | |
} | |
void draw() { | |
background(c_background); | |
pushMatrix(); | |
cam.update(); | |
if(drawGnoman) drawGnoman(200); | |
if(drawTree && tree != null) { | |
tree.draw(); | |
} | |
for(Point p: pointList) { | |
p.draw(); | |
} | |
popMatrix(); | |
if(drawCon) con.draw(); | |
if (drawHelp) { | |
drawHelpMenu(); | |
} else { | |
statusLine.draw(); | |
} | |
} | |
void keyPressed() { | |
switch(key) { | |
case 't': | |
case 'T': | |
con.print("t"); | |
drawCon = !drawCon; | |
break; | |
case 'f': | |
case 'F': | |
G_mode = 1; | |
break; | |
case 'd': | |
case 'D': | |
G_mode = 2; | |
break; | |
case 's': | |
case 'S': | |
G_mode = 3; | |
break; | |
case 'a': | |
case 'A': | |
G_mode = 4; | |
break; | |
case 'g': | |
case 'G': | |
G_mode = 5; | |
break; | |
case 'c': | |
case 'C': | |
pointList.clear(); | |
tree = null; | |
break; | |
case 'h': | |
case 'H': | |
drawHelp = !drawHelp; | |
break; | |
case 'r': | |
case 'R': | |
drawTree = !drawTree; | |
break; | |
case 'e': | |
case 'E': | |
drawGnoman = !drawGnoman; | |
break; | |
} | |
} | |
void drawHelpMenu() { | |
float hwidth = 400; | |
float hheight = 600; | |
pushStyle(); | |
strokeWeight (i_helpStrokeWidth); | |
stroke(c_helpStroke); | |
fill(c_helpBackground); | |
rect(width/2 - hwidth/2, height/2 - hheight/2, hwidth, hheight, 50, 50, 50, 50); | |
textSize(40); | |
fill(c_helpText); | |
text("Help:", width/2 - 50, height/2 - hheight/2 + 50); | |
textSize (30); | |
float x = width/2 - 150; | |
float y = height/2 - hheight/2 + 100; | |
for (int i = 0; i < i_helpStrings; i++) { | |
text(s_helpStrings[i], x, y); | |
y += 35; | |
} | |
popStyle(); | |
} | |
void checkSelect() { | |
} | |
void drawGnoman(int r) { | |
pushStyle(); | |
stroke(c_gnoman); | |
line(-r,0,r,0); | |
line(0,-r,0,r); | |
popStyle(); | |
} | |
void mousePressed() { | |
if(G_mode == 4) { | |
Point p = cam.transform(new Point(mouseX, mouseY)); | |
pointList.add(p); | |
if(tree != null) { | |
tree.insert(p); | |
} | |
if(tree == null) { | |
tree = new KdTree (p, true, 0); | |
} | |
} | |
cam.mousePressed(); | |
} | |
void mouseDragged() { | |
cam.mouseDragged(); | |
} | |
void mouseReleased() { | |
cam.mouseReleased(); | |
} |