int main(int argc, char **argv) { int i; Real x0, x1, y0, y1, z0, z1; Vector3 v1, v2, v3, v4, v5, v6, v7, v8; Hpoly *quad[2], *hplist = NULL; x0 = -5; x1 = 5; y0 = -2; y1 = 2; z0 = -5; z1 = 5; v1 = v3_make(x0, y0, z0); v2 = v3_make(x1, y0, z0); v3 = v3_make(x1, y0, z1); v4 = v3_make(x0, y0, z1); quad[0] = poly3_make(v2, v1, v3); quad[1] = poly3_make(v3, v1, v4); for (i = 0; i < 2; i++) hplist = poly_insert(hplist, quad[i]); hplist = hplist_refine(hplist, 0.0, 1); // trilist_write(plist, stdout); exit(1); }
Poly *gener_affine(int n, Vector3 *g, int m, Matrix4 *h) { int u, v; Poly *tl = NULL; Vector3 *a = NEWARRAY(n, Vector3); Vector3 *b = NEWARRAY(n, Vector3); for (v = 0; v < m; v++) { for (u = 0; u < n; u++) { b[u] = v3_m4mult(g[u], h[v]); if (u == 0 || v == 0) continue; tl = poly_insert(tl, poly3_make(a[u-1], a[u], b[u-1])); tl = poly_insert(tl, poly3_make(a[u], b[u], b[u-1])); } SWAP(a, b, Vector3 *); } efree(a); efree(b); return tl; }
static void tri_refine(Vector3 v0, Vector3 v1, Vector3 v2, Real s, int maxrec) { Real l1 = v3_norm(v3_sub(v0, v1)); Real l2 = v3_norm(v3_sub(v1, v2)); Real l3 = v3_norm(v3_sub(v2, v0)); if ((MAX(l1, MAX(l2, l3))) <= s || --maxrec < 0) { plist = poly_insert(plist, poly3_make(v0, v1, v2)); } else { Vector3 m1 = v3_scale(0.5, v3_add(v0, v1)); Vector3 m2 = v3_scale(0.5, v3_add(v1, v2)); Vector3 m3 = v3_scale(0.5, v3_add(v2, v0)); tri_refine(m1, v1, m2, s, maxrec); tri_refine(m2, v2, m3, s, maxrec); tri_refine(m3, v0, m1, s, maxrec); tri_refine(m1, m2, m3, s, maxrec); } }