import java.awt.*; import java.awt.event.*; import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.*; import javax.swing.*; import javax.media.j3d.*; import javax.vecmath.*; public class Simple3D extends JFrame { public Simple3D() { setSize(600, 600); GraphicsConfiguration graphicsConfig = SimpleUniverse.getPreferredConfiguration(); Canvas3D canvas = new Canvas3D(graphicsConfig); getContentPane().add("Center", canvas); BasicUniverse universe = new BasicUniverse(canvas, 8.0f); // Rotate the view platform by PI/4 radians about X in the BasicUniverse TransformGroup viewTransform = universe.getViewPlatformTransform(); Transform3D transform = new Transform3D(); transform.rotX(Math.PI / 4.0); Transform3D currentTransform = new Transform3D(); viewTransform.getTransform(currentTransform); transform.mul(currentTransform); viewTransform.setTransform(transform); // Add something to display BranchGroup scene = createCubeGraph(); universe.addBranchGraph(scene); } public BranchGroup createCubeGraph() { BranchGroup objRoot = new BranchGroup(); // Add an unrotated cube to the branch graph objRoot.addChild(new ColorCube()); // Create a transform to rotate by PI/4 radians about Y Transform3D T3D = new Transform3D(); T3D.rotY(Math.PI / 4.0); // Create a transform group for this transform TransformGroup TG = new TransformGroup(); TG.setTransform(T3D); // Add a second cube below this transform group TG.addChild(new ColorCube()); // Add the transform group to the branch graph objRoot.addChild(TG); return objRoot; } public static void main(String[] args) { Simple3D myCubes = new Simple3D(); myCubes.setVisible(true); } }