import java.awt.*; import java.awt.event.*; import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; import javax.swing.*; public class RevolvingTetrahedron extends JFrame { public RevolvingTetrahedron() { initComponents (); setSize(600, 600); setTitle("Revolving Tetrahedron"); GraphicsConfiguration graphicsConfig = SimpleUniverse.getPreferredConfiguration(); Canvas3D canvas = new Canvas3D(graphicsConfig); getContentPane().add("Center", canvas); RevolvingUniverse universe = new RevolvingUniverse(canvas, 8.0f); /* Generate a branch graph with a RevolvingTetrahedron and attach it to the scene graph */ BranchGroup scene = createRevolvingTetrahedronGraph(); universe.addBranchGraph(scene); } public BranchGroup createRevolvingTetrahedronGraph() { BranchGroup objRoot = new BranchGroup(); // Create the geometry arrays - // - a 4 element co-ordinate array of vertices // - a 12 element index array (4 faces by 3 vertices each) IndexedTriangleArray RevolvingTetrahedronGeometry = new IndexedTriangleArray(4, GeometryArray.COORDINATES|GeometryArray.COLOR_3, 12); // Generate the co-ordinate array for the 4 vertices Point3d vertices[] = new Point3d[4]; vertices[0]= new Point3d(-1.0,-1.0,0.0); vertices[1]= new Point3d(1.0,-1.0,0.0); vertices[2]= new Point3d(0.0,1.0,0.0); vertices[3]= new Point3d(0.0,0.0,2.0); RevolvingTetrahedronGeometry.setCoordinates(0,vertices); // Generate an indexed array which defines the co-ordinates of the 4 faces int faceIndices[] = { 0,2,1, // Base 0,1,3, // Side 1 2,0,3, // Side 2 1,2,3 // Side 3 }; RevolvingTetrahedronGeometry.setCoordinateIndices(0,faceIndices); // Generate the colour array for the 4 vertices Color3f colours[] = new Color3f[4]; colours[0]= new Color3f(1.0f,1.0f,1.0f); colours[1]= new Color3f(1.0f,0.0f,0.0f); colours[2]= new Color3f(0.0f,1.0f,0.0f); colours[3]= new Color3f(0.0f,0.0f,1.0f); RevolvingTetrahedronGeometry.setColors(0,colours); // Generate an indexed array which defines the colours of the 4 faces int colourIndices[] = { 0,2,1, // Base 0,1,3, // Side 1 2,0,3, // Side 2 1,2,3 // Side 3 }; RevolvingTetrahedronGeometry.setColorIndices(0,colourIndices); // Create the RevolvingTetrahedron shape object Shape3D RevolvingTetrahedron = new Shape3D(RevolvingTetrahedronGeometry); // Set the appearance of the RevolvingTetrahedron /* PolygonAttributes RevolvingTetrahedronAttributes = new PolygonAttributes(); RevolvingTetrahedronAttributes.setPolygonMode(PolygonAttributes.POLYGON_LINE); Appearance appear = new Appearance(); appear.setPolygonAttributes(RevolvingTetrahedronAttributes); RevolvingTetrahedron.setAppearance(appear);*/ // Add the RevolvingTetrahedron into the branch graph objRoot.addChild(RevolvingTetrahedron); return objRoot; } private void initComponents() { addWindowListener (new WindowAdapter () { public void windowClosing (WindowEvent evt) {exitForm (evt);} } ); } /*** Exit Application ***/ private void exitForm(WindowEvent evt) {System.exit (0);} public static void main(String[] args) { RevolvingTetrahedron prettyTet = new RevolvingTetrahedron(); prettyTet.setVisible(true); } }