/Users/lyon/j4p/src/j3d/cr325/Tetrahedron.java

1    package j3d.cr325; 
2     
3    import com.sun.j3d.utils.universe.SimpleUniverse; 
4    import gui.ClosableJFrame; 
5    import j3d.Utils; 
6     
7    import javax.media.j3d.*; 
8    import javax.vecmath.Point3d; 
9    import java.awt.*; 
10    
11    
12   /** 
13    * DocJava, Inc. 
14    * http://www.docjava.com 
15    * Programmer: dlyon 
16    * Date: Mar 30, 2004 
17    * Time: 3:08:11 PM 
18    */ 
19   public class Tetrahedron extends ClosableJFrame { 
20       BranchGroup createTetrahedronBranchGroup() { 
21           BranchGroup objectRoot = new BranchGroup(); 
22           TriangleArray tetrahedronArray = new 
23                   TriangleArray(12, GeometryArray.COORDINATES); 
24           Point3d coords[] = new Point3d[12]; 
25           //base 
26           coords[0] = new Point3d(-0.5, -0.5, 0); 
27           coords[1] = new Point3d(0.5, -0.5, 0); 
28           coords[2] = new Point3d(0, 0.5, 0); 
29    
30           //side1 
31           coords[3] = new Point3d(-0.5, -0.5, 0); 
32           coords[4] = new Point3d(0.5, -0.5, 0); 
33           coords[5] = new Point3d(0, 0, 1); 
34    
35           //side2 
36           coords[6] = new Point3d(-0.5, -0.5, 0); 
37           coords[7] = new Point3d(0, 0.5, 0); 
38           coords[8] = new Point3d(0, 0, 1); 
39           //side3 
40           coords[9] = new Point3d(0.5, -0.5, 0); 
41           coords[10] = new Point3d(0, 0.5, 0); 
42           coords[11] = new Point3d(0, 0, 1); 
43    
44           tetrahedronArray.setCoordinates(0, coords); 
45           Shape3D tetrahedron = new Shape3D(tetrahedronArray); 
46           objectRoot.addChild(tetrahedron); 
47           objectRoot.addChild(Shapes.getBarrel()); 
48           return objectRoot; 
49       } 
50    
51       public void createScene() { 
52           GraphicsConfiguration gc 
53                   = SimpleUniverse.getPreferredConfiguration(); 
54           Canvas3D c3d = new Canvas3D(gc); 
55           Container c = getContentPane(); 
56           c.add(BorderLayout.CENTER, c3d); 
57           BranchGroup bg = createTetrahedronBranchGroup(); 
58           Utils.addLights(bg); 
59           BasicUniverse universe = new BasicUniverse(c3d,4); 
60           universe.addBranchGraph(bg); 
61       } 
62    
63       public Tetrahedron() { 
64           super("Terahedron"); 
65           setSize(200, 200); 
66           createScene(); 
67           show(); 
68       } 
69    
70       public static void main(String[] args) { 
71           new Tetrahedron(); 
72       } 
73   } 
74