- public boolean intersects(Point p1, Point p2) {
- double A0=v1().p.x, A1=v1().p.y, A2=v1().p.z;
- double B0=v2().p.x, B1=v2().p.y, B2=v2().p.z;
- double C0=v3().p.x, C1=v3().p.y, C2=v3().p.z;
- double j0=p1.x, j1=p1.y, j2=p1.z;
- double k0=p2.x, k1=p2.y, k2=p2.z;
- double J0, J1, J2;
- double K0, K1, K2;
- double i0, i1, i2;
- double a0, a1, a2;
- double b0, b1, b2;
- double c0, c1, c2;
- double in_det;
- double R00, R01, R02, R03,
- R10, R11, R12, R13,
- R20, R21, R22, R23,
- R30, R31, R32, R33;
-
-
- /* a = B - A */
- a0 = B0 - A0;
- a1 = B1 - A1;
- a2 = B2 - A2;
- /* b = C - B */
- b0 = C0 - A0;
- b1 = C1 - A1;
- b2 = C2 - A2;
- /* c = a × b */
- c0 = a1 * b2 - a2 * b1;
- c1 = a2 * b0 - a0 * b2;
- c2 = a0 * b1 - a1 * b0;
-
- /* M^(-1) = (1/det(M)) * adj(M) */
- in_det = 1 / (c0 * c0 + c1 * c1 + c2 * c2);
- R00 = (b1 * c2 - b2 * c1) * in_det;
- R01 = (b2 * c0 - b0 * c2) * in_det;
- R02 = (b0 * c1 - b1 * c0) * in_det;
- R10 = (c1 * a2 - c2 * a1) * in_det;
- R11 = (c2 * a0 - c0 * a2) * in_det;
- R12 = (c0 * a1 - c1 * a0) * in_det;
- R20 = (c0) * in_det;
- R21 = (c1) * in_det;
- R22 = (c2) * in_det;
-
- /* O = M^(-1) * A */
- R03 = -(R00 * A0 + R01 * A1 + R02 * A2);
- R13 = -(R10 * A0 + R11 * A1 + R12 * A2);
- R23 = -(R20 * A0 + R21 * A1 + R22 * A2);
-
- /* fill in last row of 4x4 matrix */
- R30 = R31 = R32 = 0;
- R33 = 1;
-
- J2 = R20 * j0 + R21 * j1 + R22 * j2 + R23;
- K2 = R20 * k0 + R21 * k1 + R22 * k2 + R23;
- if (J2 * K2 >= 0) return false;
-
- J0 = R00 * j0 + R01 * j1 + R02 * j2 + R03;
- K0 = R00 * k0 + R01 * k1 + R02 * k2 + R03;
- i0 = J0 + J2 * ((K0 - J0) / (J2 - K2));
- if (i0 < 0 || i0 > 1) return false;
-
- J1 = R10 * j0 + R11 * j1 + R12 * j2 + R13;
- K1 = R10 * k0 + R11 * k1 + R12 * k2 + R13;
- i1 = J1 + J2 * ((K1 - J1) / (J2 - K2));
- if (i1 < 0 || i1 > 1 || i0 + i1 > 1) return false;
-
- return true;
- }
-
- public void removeFromRTree() { tris.remove(this); }
- public void addToRTree() { tris.insert(this); }
-
- public void destroy() { tris.remove(this); }
+ public boolean red = false;
+ public boolean old = false;
+
+ public final int serial = max_serial++;
+ public boolean occluded;
+
+ public Point shatter() {
+ if (destroyed) return null;
+ E e = e1();
+
+ HashSet<E> forward = new HashSet<E>();
+ HashSet<E> backward = new HashSet<E>();
+ HashSet<E> both = new HashSet<E>();
+
+ for(E eb : (Iterable<E>)e.getBoundPeers()) {
+ if (eb==e) continue;
+ if (eb.next.isBoundTo(e.next) && eb.prev.isBoundTo(e.prev)) {
+ forward.add(eb);
+ both.add(eb);
+ }
+ if (eb.pair.next.pair.isBoundTo(e.prev) && eb.pair.prev.pair.isBoundTo(e.next)) {
+ backward.add(eb.pair);
+ both.add(eb.pair);
+ }
+ }
+
+ Vertex v1 = e.t.v1();
+ Vertex v2 = e.t.v2();
+ Vertex v3 = e.t.v3();
+ Point c = e.t.centroid();
+ E e_next = e.next;
+ E e_prev = e.prev;
+ e.t.destroy();
+ newT(v1, v2, c);
+ newT(c, v2, v3);
+ newT(v3, v1, c);
+
+ // FIXME: forward too
+ for(E ex : backward) {
+ Vertex v1x = ex.t.v1();
+ Vertex v2x = ex.t.v2();
+ Vertex v3x = ex.t.v3();
+ Point cx = ex.t.centroid();
+ E ex_next = ex.next;
+ E ex_prev = ex.prev;
+ ex.t.destroy();
+ newT(v1x, v2x, cx);
+ newT(cx, v2x, v3x);
+ newT(v3x, v1x, cx);
+
+ // FIXME: i have no idea if this is right
+ e.next.bindTo(e.getBindingMatrix(ex.pair), ex.prev);
+ e.prev.bindTo(e.getBindingMatrix(ex.pair), ex.next);
+ e.next.pair.bindTo(e.getBindingMatrix(ex.pair), ex.prev.pair);
+ e.prev.pair.bindTo(e.getBindingMatrix(ex.pair), ex.next.pair);
+
+ e_next.next.bindTo(e_next.getBindingMatrix(ex_prev.pair), ex_prev.prev.pair);
+ e_next.prev.bindTo(e_next.getBindingMatrix(ex_prev.pair), ex_prev.next.pair);
+
+ e_prev.next.bindTo(e_prev.getBindingMatrix(ex_next.pair), ex_next.prev.pair);
+ e_prev.prev.bindTo(e_prev.getBindingMatrix(ex_next.pair), ex_next.next.pair);
+ }
+
+ /*
+
+ E first = null;
+ E firste = null;
+ E firstx = null;
+ E firstq = null;
+ for(E e : (Iterable<E>)getBoundPeers()) {
+ E enext = e.next;
+ E eprev = e.prev;
+ E pnext = e.pair.next;
+ E pprev = e.pair.prev;
+ Point mid = e.midpoint();
+ Vertex r = e.next.v2;
+ Vertex l = e.pair.next.v2;
+ if (!e.destroyed) {
+ e.destroy();
+ e.pair.destroy();
+ newT(r.p, e.v1.p, mid, null, 0);
+ newT(r.p, mid, e.v2.p, null, 0);
+ newT(l.p, mid, e.v1.p, null, 0);
+ newT(l.p, e.v2.p, mid, null, 0);
+ }
+ }
+ for(E e : (Iterable<E>)getBoundPeers()) {
+ Point mid = e.midpoint();
+ if (first==null) {
+ first = e.v1.getE(mid);
+ firste = e;
+ firstx = e.pair;
+ firstq = e.v2.getE(mid).pair;
+ continue;
+ }
+ e.v1.getE(mid). bindTo(e.getBindingMatrix(firste), first);
+ e.v1.getE(mid).pair. bindTo(e.getBindingMatrix(firste), first.pair);
+ e.v2.getE(mid).pair. bindTo(e.getBindingMatrix(firste), firstq);
+ e.v2.getE(mid).pair.pair.bindTo(e.getBindingMatrix(firste), firstq.pair);
+ }
+ */
+ /*
+ first.setConstraint(firste.getConstraint());
+ firstq.setConstraint(firste.getConstraint());
+ */
+ return null;
+ }
+