-
Notifications
You must be signed in to change notification settings - Fork 7
/
SketchIsoSurface3MetaBall.java
executable file
·90 lines (73 loc) · 2.99 KB
/
SketchIsoSurface3MetaBall.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package de.hfkbremen.algorithmiccliches.examples;
import de.hfkbremen.algorithmiccliches.isosurface.MetaBall;
import de.hfkbremen.algorithmiccliches.isosurface.MetaBallManager;
import de.hfkbremen.algorithmiccliches.util.ACArcBall;
import processing.core.PApplet;
import processing.core.PVector;
import java.util.ArrayList;
public class SketchIsoSurface3MetaBall extends PApplet {
private MetaBallManager mMetaBallManager;
private int mCurrentCircle = 0;
private ACArcBall mArcBall;
public void settings() {
size(1024, 768, P3D);
}
public void setup() {
textFont(createFont("Courier", 11));
mArcBall = new ACArcBall(width / 2.0f, height / 2.0f, 0, 400.0f, this, true);
mMetaBallManager = new MetaBallManager();
mMetaBallManager.dimension.set(width, height, height);
mMetaBallManager.resolution.set(30, 30, 30);
mMetaBallManager.position.set(width / -2.0f, height / -2.0f, height / -2.0f);
mMetaBallManager.add(new MetaBall(new PVector(0, 0, 0), 1, 100));
}
public void draw() {
background(255);
directionalLight(126, 126, 126, 0, 0, -1);
ambientLight(102, 102, 102);
/* draw extra info */
fill(0);
noStroke();
text("ISO VALUE : " + mMetaBallManager.isovalue(), 10, 12);
text("SELECTED : " + mCurrentCircle, 10, 24);
text("FPS : " + (int) frameRate, 10, 36);
/* draw iso surface */
mArcBall.update();
if (!mMetaBallManager.metaballs().isEmpty()) {
mMetaBallManager.metaballs().get(mCurrentCircle).position.x = mouseX - width / 2.0f;
mMetaBallManager.metaballs().get(mCurrentCircle).position.y = mouseY - height / 2.0f;
}
final ArrayList<PVector> myData = mMetaBallManager.createSurface();
/* draw metaballs */
translate(width / 2.0f, height / 2.0f);
fill(255, 127, 0);
noStroke();
beginShape(TRIANGLES);
for (PVector myDatum : myData) {
vertex(myDatum.x, myDatum.y, myDatum.z);
}
endShape();
}
public void keyPressed() {
switch (key) {
case '+':
mMetaBallManager.isovalue(mMetaBallManager.isovalue() + 0.01f);
break;
case '-':
mMetaBallManager.isovalue(mMetaBallManager.isovalue() - 0.01f);
break;
case ' ':
mCurrentCircle++;
mCurrentCircle %= mMetaBallManager.metaballs().size();
break;
case 'c':
mMetaBallManager.add(new MetaBall(new PVector(mouseX - width / 2.0f,
mouseY - height / 2.0f,
random(-100, 100)), random(1, 2), random(50, 150)));
break;
}
}
public static void main(String[] args) {
PApplet.main(new String[]{SketchIsoSurface3MetaBall.class.getName()});
}
}