// Copyright (c) 1996 David Engberg All rights reserved // $Id$ import java.io.RandomAccessFile; /** * This mini-program is used to spit out a panopticon VRML world with a * number of prisoners equal to the number of arguments given on the command- * line. */ public class Panopticon { public static final String kPrefixFileName = "prefix.wrl"; /** * This static function is invoked when this program is run. * The output of the program is a VRML file. The command-line is a * list of URLs. */ public static void main(String arguments[]) { int prisonerCount = arguments.length; if (prisonerCount < 4) { System.err.println(">>> At least 4 URLs are required for a panopticon"); return; } try { RandomAccessFile prefixFile = new RandomAccessFile(kPrefixFileName, "r"); String line; while ((line = prefixFile.readLine()) != null) { System.out.println(line); } } catch (IOException exception) { System.err.println(">>> File error reading prefix file: " + exception); return; } double radius = 2 + 2 / Math.tan(Math.PI / prisonerCount); System.out.println("# Circle radius = " + radius); double increment = 2 * Math.PI / prisonerCount; System.out.println("# Increment = " + increment); double angle = 0; System.out.println("\nTransform {"); double outer = radius + 2.5; System.out.println(" scale " + outer + " .1 " + outer); System.out.println(" translation 0 -1.1 0"); System.out.println(" children ["); System.out.println(" Shape {"); System.out.println(" appearance Appearance {"); System.out.println(" material Material {"); System.out.println(" diffuseColor 0.5 0.5 0.5"); System.out.println(" specularColor 0.3 0.3 0.3"); System.out.println(" shininess 0.1"); System.out.println(" }"); System.out.println(" }"); System.out.println(" geometry Cylinder {}"); System.out.println(" }"); System.out.println(" ]"); System.out.println("}"); for (int argument = 0; argument < arguments.length; ++argument) { double z = -radius * Math.cos(angle); double x = -radius * Math.sin(angle); System.out.println("\nTransform {"); System.out.println(" rotation 0 1 0 " + angle); System.out.println(" translation " + x + " 0 " + z); System.out.println(" children ["); System.out.println(" Anchor {"); System.out.println(" url \"" + arguments[argument] + "\""); System.out.println(" children [ USE Cell ]"); System.out.println(" }"); System.out.println(" ]"); System.out.println("}"); System.out.println("Transform {"); System.out.println(" rotation 0 1 0 " + angle); System.out.println(" translation " + x + " 4 " + z); System.out.println(" children ["); System.out.println(" Anchor {"); System.out.println(" url \"" + arguments[argument] + "\""); System.out.println(" children [ USE Cell ]"); System.out.println(" }"); System.out.println(" ]"); System.out.println("}"); angle += increment; } System.out.println("# End panopticon"); } }