import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import java.util.*;
-import static edu.berkeley.qfat.Geom.*;
+import edu.berkeley.qfat.geom.*;
+import edu.berkeley.qfat.geom.Point;
// FIXME: recenter goal to have centroid coincident with tile
// FIXME: re-orient goal (how?)
mousey = e.getY();
}
- private Geom tile = new Geom();
- private Geom goal = new Geom();
+ private Mesh tile = new Mesh();
+ private Mesh goal = new Mesh();
/** magnification factor */
private static final float MAG = 1;
- Geom.M[] translations;
- Geom.Vert[] points;
+ Matrix[] translations;
+ Mesh.Vert[] points;
public Main(StlFile stlf) {
for(int i=0; i<stlf.coordArray.length; i+=3) {
- Geom.Vert p0 = goal.register(new Geom.Point(stlf.coordArray[i+0].x * MAG, stlf.coordArray[i+0].y * MAG, stlf.coordArray[i+0].z * MAG));
- Geom.Vert p1 = goal.register(new Geom.Point(stlf.coordArray[i+1].x * MAG, stlf.coordArray[i+1].y * MAG, stlf.coordArray[i+1].z * MAG));
- Geom.Vert p2 = goal.register(new Geom.Point(stlf.coordArray[i+2].x * MAG, stlf.coordArray[i+2].y * MAG, stlf.coordArray[i+2].z * MAG));
- Geom.Vec n = new Geom.Vec(stlf.normArray[i/3].x * MAG, stlf.normArray[i/3].y * MAG, stlf.normArray[i/3].z * MAG);
- Geom.T t = goal.newT(p0, p1, p2, n);
+ Mesh.Vert p0 = goal.register(new Point(stlf.coordArray[i+0].x * MAG, stlf.coordArray[i+0].y * MAG, stlf.coordArray[i+0].z * MAG));
+ Mesh.Vert p1 = goal.register(new Point(stlf.coordArray[i+1].x * MAG, stlf.coordArray[i+1].y * MAG, stlf.coordArray[i+1].z * MAG));
+ Mesh.Vert p2 = goal.register(new Point(stlf.coordArray[i+2].x * MAG, stlf.coordArray[i+2].y * MAG, stlf.coordArray[i+2].z * MAG));
+ Vec n = new Vec(stlf.normArray[i/3].x * MAG, stlf.normArray[i/3].y * MAG, stlf.normArray[i/3].z * MAG);
+ Mesh.T t = goal.newT(p0, p1, p2, n);
}
// rotate to align major axis -- this probably needs to be done by a human.
- goal.transform(new Geom.M(new Geom.Vec(0, 0, 1), (float)(Math.PI/2)));
+ goal.transform(new Matrix(new Vec(0, 0, 1), (float)(Math.PI/2)));
- float goal_width = goal.diagonal().dot(new Geom.Vec(1, 0, 0));
- float goal_height = goal.diagonal().dot(new Geom.Vec(0, 1, 0));
- float goal_depth = goal.diagonal().dot(new Geom.Vec(0, 0, 1));
+ float goal_width = goal.diagonal().dot(new Vec(1, 0, 0));
+ float goal_height = goal.diagonal().dot(new Vec(0, 1, 0));
+ float goal_depth = goal.diagonal().dot(new Vec(0, 0, 1));
float width = (float)0.6;
float height = (float)0.08;
float depth = (float)0.3;
- translations = new Geom.M[] {
-
- new Geom.M(new Geom.Vec(-(width/2), height, 0)),
- new Geom.M(new Geom.Vec( (width/2), height, 0)),
- new Geom.M(new Geom.Vec(-(width/2), -height, 0)),
- new Geom.M(new Geom.Vec( (width/2), -height, 0)),
- new Geom.M(new Geom.Vec(-(width/2), 0, depth)),
- new Geom.M(new Geom.Vec( (width/2), 0, depth)),
- new Geom.M(new Geom.Vec(-(width/2), 0, -depth)),
- new Geom.M(new Geom.Vec( (width/2), 0, -depth)),
-
- new Geom.M(new Geom.Vec( width, 0, 0)),
- new Geom.M(new Geom.Vec(-width, 0, 0)),
+ translations = new Matrix[] {
+
+ new Matrix(new Vec(-(width/2), height, 0)),
+ new Matrix(new Vec( (width/2), height, 0)),
+ new Matrix(new Vec(-(width/2), -height, 0)),
+ new Matrix(new Vec( (width/2), -height, 0)),
+ new Matrix(new Vec(-(width/2), 0, depth)),
+ new Matrix(new Vec( (width/2), 0, depth)),
+ new Matrix(new Vec(-(width/2), 0, -depth)),
+ new Matrix(new Vec( (width/2), 0, -depth)),
+
+ new Matrix(new Vec( width, 0, 0)),
+ new Matrix(new Vec(-width, 0, 0)),
/*
- new Geom.M(new Geom.Vec( 0, 0, depth)),
- new Geom.M(new Geom.Vec( 0, 0, -depth)),
+ new Matrix(new Vec( 0, 0, depth)),
+ new Matrix(new Vec( 0, 0, -depth)),
*/
};
- Geom.Vert ltf = tile.register(new Geom.Point(-(width/2), (height/2), (depth/2)));
- Geom.Vert mtf = tile.register(new Geom.Point( 0.0, (height/2), (depth/2)));
- Geom.Vert rtf = tile.register(new Geom.Point( (width/2), (height/2), (depth/2)));
- Geom.Vert ltn = tile.register(new Geom.Point(-(width/2), (height/2), -(depth/2)));
- Geom.Vert mtn = tile.register(new Geom.Point( 0.0, (height/2), -(depth/2)));
- Geom.Vert rtn = tile.register(new Geom.Point( (width/2), (height/2), -(depth/2)));
- Geom.Vert lbf = tile.register(new Geom.Point(-(width/2), -(height/2), (depth/2)));
- Geom.Vert mbf = tile.register(new Geom.Point( 0.0, -(height/2), (depth/2)));
- Geom.Vert rbf = tile.register(new Geom.Point( (width/2), -(height/2), (depth/2)));
- Geom.Vert lbn = tile.register(new Geom.Point(-(width/2), -(height/2), -(depth/2)));
- Geom.Vert mbn = tile.register(new Geom.Point( 0.0, -(height/2), -(depth/2)));
- Geom.Vert rbn = tile.register(new Geom.Point( (width/2), -(height/2), -(depth/2)));
+ Mesh.Vert ltf = tile.register(new Point(-(width/2), (height/2), (depth/2)));
+ Mesh.Vert mtf = tile.register(new Point( 0.0, (height/2), (depth/2)));
+ Mesh.Vert rtf = tile.register(new Point( (width/2), (height/2), (depth/2)));
+ Mesh.Vert ltn = tile.register(new Point(-(width/2), (height/2), -(depth/2)));
+ Mesh.Vert mtn = tile.register(new Point( 0.0, (height/2), -(depth/2)));
+ Mesh.Vert rtn = tile.register(new Point( (width/2), (height/2), -(depth/2)));
+ Mesh.Vert lbf = tile.register(new Point(-(width/2), -(height/2), (depth/2)));
+ Mesh.Vert mbf = tile.register(new Point( 0.0, -(height/2), (depth/2)));
+ Mesh.Vert rbf = tile.register(new Point( (width/2), -(height/2), (depth/2)));
+ Mesh.Vert lbn = tile.register(new Point(-(width/2), -(height/2), -(depth/2)));
+ Mesh.Vert mbn = tile.register(new Point( 0.0, -(height/2), -(depth/2)));
+ Mesh.Vert rbn = tile.register(new Point( (width/2), -(height/2), -(depth/2)));
- points = new Geom.Vert[] {
+ points = new Mesh.Vert[] {
ltf,
mtf,
rtf,
// top
- tile.newT(ltf, mtf, mtn);
- tile.newT(mtn, ltn, ltf);
- tile.newT(mtf, rtf, rtn);
- tile.newT(rtn, mtn, mtf);
+ tile.newT(ltf, mtf, mtn, null);
+ tile.newT(mtn, ltn, ltf, null);
+ tile.newT(mtf, rtf, rtn, null);
+ tile.newT(rtn, mtn, mtf, null);
// bottom (swap normals)
- tile.newT(mbf, lbf, mbn);
- tile.newT(lbn, mbn, lbf);
- tile.newT(rbf, mbf, rbn);
- tile.newT(mbn, rbn, mbf);
+ tile.newT(mbf, lbf, mbn, null);
+ tile.newT(lbn, mbn, lbf, null);
+ tile.newT(rbf, mbf, rbn, null);
+ tile.newT(mbn, rbn, mbf, null);
// left
- tile.newT(ltf, ltn, lbn);
- tile.newT(lbn, lbf, ltf);
+ tile.newT(ltf, ltn, lbn, null);
+ tile.newT(lbn, lbf, ltf, null);
// right (swap normals)
- tile.newT(rtn, rtf, rbn);
- tile.newT(rbf, rbn, rtf);
+ tile.newT(rtn, rtf, rbn, null);
+ tile.newT(rbf, rbn, rtf, null);
// front
- tile.newT(ltn, mtn, mbn);
- tile.newT(ltn, mbn, lbn);
- tile.newT(mtn, rtn, rbn);
- tile.newT(mtn, rbn, mbn);
+ tile.newT(ltn, mtn, mbn, null);
+ tile.newT(ltn, mbn, lbn, null);
+ tile.newT(mtn, rtn, rbn, null);
+ tile.newT(mtn, rbn, mbn, null);
// back
- tile.newT(mtf, ltf, mbf);
- tile.newT(mbf, ltf, lbf);
- tile.newT(rtf, mtf, rbf);
- tile.newT(rbf, mtf, mbf);
-
- for(Geom.M m : translations) {
- for(Geom.T t1 : tile) {
- for(Geom.T t2 : tile) {
+ tile.newT(mtf, ltf, mbf, null);
+ tile.newT(mbf, ltf, lbf, null);
+ tile.newT(rtf, mtf, rbf, null);
+ tile.newT(rbf, mtf, mbf, null);
+
+ for(Matrix m : translations) {
+ for(Mesh.T t1 : tile) {
+ for(Mesh.T t2 : tile) {
if (t1==t2) continue;
- if ((t1.p1().p.times(m).minus(t2.p1().p).mag() < Geom.EPSILON) &&
- (t1.p2().p.times(m).minus(t2.p3().p).mag() < Geom.EPSILON) &&
- (t1.p3().p.times(m).minus(t2.p2().p).mag() < Geom.EPSILON)) {
+ if ((t1.v1().p.times(m).minus(t2.v1().p).mag() < Mesh.EPSILON) &&
+ (t1.v2().p.times(m).minus(t2.v3().p).mag() < Mesh.EPSILON) &&
+ (t1.v3().p.times(m).minus(t2.v2().p).mag() < Mesh.EPSILON)) {
t1.e1().bind(t2.e3().pair);
t1.e2().bind(t2.e2().pair);
t1.e3().bind(t2.e1().pair);
}
- if ((t1.p2().p.times(m).minus(t2.p1().p).mag() < Geom.EPSILON) &&
- (t1.p3().p.times(m).minus(t2.p3().p).mag() < Geom.EPSILON) &&
- (t1.p1().p.times(m).minus(t2.p2().p).mag() < Geom.EPSILON)) {
+ if ((t1.v2().p.times(m).minus(t2.v1().p).mag() < Mesh.EPSILON) &&
+ (t1.v3().p.times(m).minus(t2.v3().p).mag() < Mesh.EPSILON) &&
+ (t1.v1().p.times(m).minus(t2.v2().p).mag() < Mesh.EPSILON)) {
t1.e2().bind(t2.e3().pair);
t1.e3().bind(t2.e2().pair);
t1.e1().bind(t2.e1().pair);
}
- if ((t1.p3().p.times(m).minus(t2.p1().p).mag() < Geom.EPSILON) &&
- (t1.p1().p.times(m).minus(t2.p3().p).mag() < Geom.EPSILON) &&
- (t1.p2().p.times(m).minus(t2.p2().p).mag() < Geom.EPSILON)) {
+ if ((t1.v3().p.times(m).minus(t2.v1().p).mag() < Mesh.EPSILON) &&
+ (t1.v1().p.times(m).minus(t2.v3().p).mag() < Mesh.EPSILON) &&
+ (t1.v2().p.times(m).minus(t2.v2().p).mag() < Mesh.EPSILON)) {
t1.e3().bind(t2.e3().pair);
t1.e1().bind(t2.e2().pair);
t1.e2().bind(t2.e1().pair);
}
}
- //xGeom.Vert mid = lbf.getE(mbn).shatter();
+ //xMesh.Vert mid = lbf.getE(mbn).shatter();
// rescale to match volume
float factor = (float)Math.pow(tile.volume() / goal.volume(), 1.0/3.0);
- goal.transform(new Geom.M(factor));
+ goal.transform(new Matrix(factor));
// translate to match centroid
- goal.transform(new Geom.M(tile.centroid().minus(goal.centroid())));
+ goal.transform(new Matrix(tile.centroid().minus(goal.centroid())));
//tx.e2.shatter();
//tx.e3.shatter();
tile.bind();
- //mid.move(new Geom.Vec((float)0,0,(float)-0.05));
- //ltn.move(new Geom.Vec((float)0,0,(float)-0.05));
+ //mid.move(new Vec((float)0,0,(float)-0.05));
+ //ltn.move(new Vec((float)0,0,(float)-0.05));
- //mtf.move(new Geom.Vec(0, (float)-0.05, (float)0.05));
+ //mtf.move(new Vec(0, (float)-0.05, (float)0.05));
System.out.println("tile volume: " + tile.volume());
if (verts > 300) return;
//double min = (tile.avgedge/tile.numedges)*(1+(4/(double)verts));
//if (verts>0 && tile.es.peek().length() < min) return;
- PriorityQueue<Geom.E> es = new PriorityQueue<Geom.E>();
- for(Geom.E e : tile.es) es.add(e);
+ PriorityQueue<Mesh.E> es = new PriorityQueue<Mesh.E>();
+ for(Mesh.E e : tile.es) es.add(e);
for(int i=0; i<10; i++) {
- Geom.E e = es.poll();
+ Mesh.E e = es.poll();
verts++;
System.out.println("shatter " + e);
e.shatter();
}
}
- public synchronized void rand(double temperature, Geom.Vert p) {
+ public synchronized void rand(double temperature, Mesh.Vert p) {
double tile_score = tile.score();
double goal_score = goal.score();
r1 = r1 - (float)Math.floor(r1);
r1 = r1 * (float)0.01;
r1 = r1 - (float)0.005;
- Geom.Vec v = p.watchback().p.minus(p.p).norm().times(r1);
+ Vec v = p.watchback().p.minus(p.p).norm().times(r1);
//v = p.norm().times(v.dot(p.norm()));
boolean aspect = false;//(Math.abs(random.nextInt()) % 100) <= 2;
- Geom.M old_tile_aspect = null;//goal.aspect;
+ Matrix old_tile_aspect = null;//goal.aspect;
boolean good = true;
if (aspect) {
/*
v = v.times(10);
- tile.aspect = new Geom.M(tile.aspect.a / (v.x+1), tile.aspect.f / (v.y+1), tile.aspect.k / (v.z+1));
- tile.invaspect = new Geom.M(1/tile.aspect.a, 1/tile.aspect.f, 1/tile.aspect.k);
+ tile.aspect = new Matrix(tile.aspect.a / (v.x+1), tile.aspect.f / (v.y+1), tile.aspect.k / (v.z+1));
+ tile.invaspect = new Matrix(1/tile.aspect.a, 1/tile.aspect.f, 1/tile.aspect.k);
goal.rescore();
tile.rescore();
*/
} else {
if (aspect) {
//tile.aspect = old_tile_aspect;
- //tile.invaspect = new Geom.M(1/tile.aspect.a, 1/tile.aspect.f, 1/tile.aspect.k);
+ //tile.invaspect = new Matrix(1/tile.aspect.a, 1/tile.aspect.f, 1/tile.aspect.k);
goal.rescore();
tile.rescore();
} else {
int i = 0;
//gl.glDisable(GL.GL_DEPTH_TEST);
gl.glColor4f(1,1,1,1);
- for(Geom.M m : translations) {
+ for(Matrix m : translations) {
//if (v1.z==0 && v1.y==0) continue;
i++;
if (i != 1 /*&& i!=4*/) continue;
- Geom.Point p = new Geom.Point(0, 0, 0).times(m);
- Geom.Vec v = new Geom.Vec(p.x, p.y, p.z);
+ Point p = new Point(0, 0, 0).times(m);
+ Vec v = new Vec(p.x, p.y, p.z);
v = v.times((float)1.04);
gl.glTranslatef(v.x, v.y, v.z);
draw(gl, false, tile);
//gl.glEnable(GL.GL_DEPTH_TEST);
}
- private synchronized void draw(GL gl, boolean triangles, Geom mesh) {
+ private synchronized void draw(GL gl, boolean triangles, Mesh mesh) {
float red = 0.0f;
float green = 0.0f;
float blue = 0.0f;
- for(Geom.T t : mesh) {
+ for(Mesh.T t : mesh) {
if (red < 0.15) red = 1.0f;
if (green < 0.15) green = 1.0f;
if (blue < 0.15) blue = 1.0f;
gl.glEnd();
}
- Geom.Point centroid = t.centroid();
+ Point centroid = t.centroid();
gl.glBegin(GL.GL_LINES);
gl.glColor3f(1, 1, 1);
/*
*/
if (mesh==goal)
- for(Geom.Vert p : new Geom.Vert[] { t.p1(), t.p2(), t.p3() }) {
+ for(Mesh.Vert p : new Mesh.Vert[] { t.v1(), t.v2(), t.v3() }) {
p.p.glVertex(gl);
//p.plus(p.norm().times(p.score()*10)).glVertex(gl);
p.partner().p.glVertex(gl);
for(int i=0; i<1; i++) {
glcanvas.repaint();
//tile.ts.get(Math.abs(random.nextInt()) % tile.ts.size()).e1().p1
- for(Geom.T t : tile)
- for(Geom.Vert p : new Geom.Vert[] { t.p1(), t.p2(), t.p3() }) {
+ for(Mesh.T t : tile)
+ for(Mesh.Vert p : new Mesh.Vert[] { t.v1(), t.v2(), t.v3() }) {
rand(10,p);
}
goal.rescore();