load("zegraph.dll"); PI2 = 6.28318530717959; class Shape3D { /******************************************************************** * Disk with slice n and radius r on the x-y ********************************************************************/ function disk(n, r) { assert(n > 4); poly = zegraph("polygon"); vert = zegraph("vertex"); norm = zegraph("vertex"); poly.type("trianglefan"); poly.vertex(vert); poly.normal(norm); norm.add(0, 0, 1); d = PI2 / (n - 1); for (a = 0.0; a <= PI2; a += d) { x = r*cos(a); y = r*sin(a); vert.add(x, y, 0); } return poly; } /******************************************************************** * Cylinder with slice n, radius r, and height h on the x-y ********************************************************************/ function cylinder(n, r, h) { assert(n > 4); poly = zegraph("polygon"); vert = zegraph("vertex"); norm = zegraph("vertex"); poly.type("quadstrip"); poly.vertex(vert); poly.normal(norm); d = PI2 / (n - 1); for (i = 0; i <= n; i++) { a = i * d; ca = cos(a); sa = sin(a); x = r*ca; y = r*sa; vert.add(x, y, h, x, y, 0); b = planenormal(x, y, 0, r*cos(a + 1.e-5), r*sin(a + 1.e-5), 0, x, y, h); norm.add(b[0], b[1], b[2], b[0], b[1], b[2]); } return poly; } /******************************************************************** * Cone with slice n, radius r, and height h on the x-y ********************************************************************/ function cone(n, r, h) { assert(n > 4); poly = zegraph("polygon"); vert = zegraph("vertex"); norm = zegraph("vertex"); poly.type("quadstrip"); poly.vertex(vert); poly.normal(norm); d = PI2 / (n - 1); for (i = 0; i < n; i++) { a = i * d; ca = cos(a); sa = sin(a); x = r*ca; y = r*sa; vert.add(0, 0, h, x, y, 0); b = planenormal(x, y, 0, r*cos(a + 1.e-5), r*sin(a + 1.e-5), 0, 0, 0, h); norm.add(b[0], b[1], b[2], b[0], b[1], b[2]); } return poly; } /******************************************************************** * Simple sphere object ********************************************************************/ function sphere(n, r) { assert(n > 0 && n <= 8); poly = zegraph("polygon"); poly.sphere(r, n); return poly; } }