+ public static final float MATCHING_EPSILON = 0.001f;
+
+ private static boolean small(float f) { return Math.abs(f) < 0.001; }
+ public void generateTile(Matrix[] matrices, Mesh mesh) {
+ mesh.coalesce = true;
+ HashSet<HalfSpace> halfSpaces = new HashSet<HalfSpace>();
+ HashSet<Polygon> polygons = new HashSet<Polygon>();
+ for(Matrix m : matrices) {
+ Vec v = m.getTranslationalComponent();
+ if (v.mag() < 0.0001) continue;
+ v = v.times(0.5f);
+ Point p = Point.ORIGIN.plus(v);
+ Vec v0 = v;
+ /*
+ if (small(v.x) && small(v.y)) v = new Vec(0,0,1);
+ else if (small(v.y) && small(v.z)) v = new Vec(1,0,0);
+ else if (small(v.z) && small(v.x)) v = new Vec(0,1,0);
+ else if (small(v.x)) v = new Vec(0,v.y,0).minus(new Vec(0,0,v.z)).cross(new Vec(1,0,0));
+ else if (small(v.y)) v = new Vec(0,0,v.z).minus(new Vec(v.x,0,0)).cross(new Vec(0,1,0));
+ else if (small(v.z)) v = new Vec(v.x,0,0).minus(new Vec(0,v.y,0)).cross(new Vec(0,0,1));
+ else {
+ Point v1 = new Point(v.x, 0, 0);
+ Point v2 = new Point(0, v.y, 0);
+ Point v3 = new Point(0, 0, v.z);
+ v = v3.minus(v2).cross(v1.minus(v2));
+ }
+ */
+ if (v.dot(Point.ORIGIN.minus(p)) < 0) v = v.times(-1);
+
+ System.out.println(v);
+ HalfSpace hs = new HalfSpace(p, v.norm());
+ halfSpaces.add(hs);
+ polygons.add(new Polygon(hs));
+ }
+ for(Polygon p : polygons) {
+ System.out.println(p.plane.norm + " " + p.plane.dvalue);
+ for(HalfSpace hs : halfSpaces) {
+ if (p.plane==hs) continue;
+ p = p.intersect(hs);
+ }
+ p.tesselate(mesh);
+ }
+ }
+
+ private void quad(Mesh mesh, Matrix m, Point p1_, Point p2_, Point p3_, Point p4_) {
+ Point p1 = m.times(p1_);
+ Point p2 = m.times(p2_);
+ Point p3 = m.times(p3_);
+ Point p4 = m.times(p4_);
+ Point c = new Point((p1.x+p2.x+p3.x+p4.x)/4,
+ (p1.y+p2.y+p3.y+p4.y)/4,
+ (p1.z+p2.z+p3.z+p4.z)/4);
+ mesh.newT(p1, p2, c, null, 0);
+ mesh.newT(p2, p3, c, null, 0);
+ mesh.newT(p3, p4, c, null, 0);
+ mesh.newT(p4, p1, c, null, 0);
+ }