public class Main extends InteractiveMeshViewer {
+ public Matrix[] transforms;
+
public static int verts = 1;
public static final Random random = new Random();
StlFile stlf = new StlFile();
InputStream res = this.getClass().getClassLoader().getResourceAsStream(file);
stlf.readBinaryFile(file, res);
- goal = new Mesh(false);
+ setGoal(new Mesh(false));
for(int i=0; i<stlf.coordArray.length; i+=3) {
Point p0 = new Point(stlf.coordArray[i+0].x * MAG, stlf.coordArray[i+0].y * MAG, stlf.coordArray[i+0].z * MAG);
Point p1 = new Point(stlf.coordArray[i+1].x * MAG, stlf.coordArray[i+1].y * MAG, stlf.coordArray[i+1].z * MAG);
public Main(JFrame f) { super(f); }
- public void fixupTile() {
- synchronized(safeTriangles) {
+ public synchronized void fixupTile() {
for(Matrix m1 : transforms) {
for(Matrix m2 : transforms) {
if (m1==m2) continue;
tile.error_against = goal;
goal.error_against = tile;
fixupGoal();
- }
}
public void breakit() {
Vec v = new Vec(random.nextFloat(), random.nextFloat(), random.nextFloat());
v = v.norm().times((random.nextFloat() - 0.5f) * max);
Matrix m = Matrix.translate(v);
-
- boolean good = p.move(m, false);
+ boolean good = p.move(v, false);
if (!good) { return false; }
double new_tile_error = tile.error();
hits++;
p.goodp = p.p;
} else {
- p.move(Matrix.translate(v.times(-1)), true);
+ p.move(v.times(-1), true);
misses++;
}
p.reComputeErrorAround();
double acceptance = 1;
while(true) {
synchronized(this) {
- synchronized(safeTriangles) {
- safeTriangles.clear();
- for(Mesh.T t : tile)
- if (t.shouldBeDrawn())
- safeTriangles.add(t);
- }
- if (!anneal) { repaint(); Thread.sleep(10); continue; }
+ if (!anneal) { repaint(); Thread.sleep(10); continue; }
double ratio = (hits+misses==0) ? 1 : (hits / (hits+misses));
hits = 0;
public static void main(String[] s) throws Exception {
JFrame f = new JFrame();
+ f.setLayout(new BorderLayout());
Main main = new Main(f);
+ f.add(main, BorderLayout.CENTER);
f.setJMenuBar(main.new MyMenuBar());
f.pack();
f.show();
}
public void actionPerformed(ActionEvent event) {
synchronized(Main.this) {
- synchronized(safeTriangles) {
hit();
- }
}
}
public void hit() {}
}
public void hexBrick(boolean offset, boolean rotated) {
- tile = new Mesh(false);
+ setTile(new Mesh(false));
float width = (float)0.8;
float depth = (float)0.08;
float height = (float)0.4;
hexBrick(false, true);
}});
tileMenu.add(new MyMenuItem("Temp (do not use)") { public void hit() {
- tile = new Mesh(false);
+ setTile(new Mesh(false));
float width = (float)0.8;
float depth = (float)0.08;
float height = (float)0.4;
fixupTile();
} });
tileMenu.add(new MyMenuItem("Dense Packing (hex)") { public void hit() {
- tile = new Mesh(false);
+ setTile(new Mesh(false));
float width = (float)3.2;
float depth = (float)0.32;
float height = (float)1.6;
fixupTile();
} });
tileMenu.add(new MyMenuItem("Slim Dense Packing (Cubic)") { public void hit() {
- tile = new Mesh(false);
+ setTile(new Mesh(false));
float unit = 0.4f;
float r = unit/2;
float sin = (float)(unit * Math.sin(Math.PI/3));
} });
tileMenu.add(new MyMenuItem("Genus-1") { public void hit() {
synchronized(this) {
- tile = new Mesh(false);
+ setTile(new Mesh(false));
Matrix mm = Matrix.scale(0.1f);
float height = 4;
float width = 4;
Matrix.translate(new Vec(-0.2f,0,0))
.times(Matrix.rotate(new Vec(1,0,0), (float)(-1*Math.PI/2))),
+
//Matrix.rotate(new Vec(0,0,1), (float)(1*Math.PI/2)),
/*
}}});
tileMenu.add(new MyMenuItem("Hammerhead") { public void hit() {
synchronized(this) {
- tile = new Mesh(false);
+ setTile(new Mesh(false));
Matrix mm = Matrix.ONE;
float height1 = .1f;
float height2 = .1f;