import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.geometry.*;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import java.awt.*;


public class CubeTest extends Applet{
    SimpleUniverse u;// = new SimpleUniverse();

    public BranchGroup createScenegraph(){
     BranchGroup bg = new BranchGroup();

     IndexedQuadArray iqa = new IndexedQuadArray(24, GeometryArray.COORDINATES, 24);

     Point3f[] pts = new Point3f[8];
     pts[0] = new Point3f(-1.0f, -1.0f, -1.0f);
     pts[1] = new Point3f(1.0f, -1.0f, -1.0f);
     pts[2] = new Point3f(-1.0f, 1.0f, -1.0f);
     pts[3] = new Point3f(-1.0f, -1.0f, 1.0f);
     //pts[4] = new Point3f(1.0f, 1.0f, -1.0f);
     pts[4] = new Point3f(-1.0f, 1.0f, 1.0f);
     pts[5] = new Point3f(1.0f, -1.0f, 1.0f);
     pts[6] = new Point3f(1.0f, 1.0f, -1.0f);
     pts[7] = new Point3f(1.0f, 1.0f, 1.0f);

     int[] indices = {
         0, 3, 4, 2,
         0, 1, 5, 3,
         0, 2, 6, 1,
         7, 5, 1, 6,
         7, 6, 2, 4,
         7, 4, 3, 5
     };


     iqa.setCoordinates(0, pts);
     iqa.setCoordinateIndices(0, indices);

     Shape3D myShape3D = new Shape3D();
     myShape3D.setGeometry(iqa);
     //replace this line
     //bg.addChild(myShape3D);
     
     //with this:
     //--------------------
     Transform3D scaleTransform = new Transform3D();
     scaleTransform.setScale(0.4d);
     TransformGroup objScale = new TransformGroup(scaleTransform);
     objScale.addChild(myShape3D);
     bg.addChild(objScale);
     //--------------------
     
     return bg;
    }

    public void init(){
        setLayout(new BorderLayout());
        GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
        Canvas3D c = new Canvas3D(config);
        add("Center", c);
        BranchGroup scene = createScenegraph();
        u = new SimpleUniverse(c);
        u.getViewingPlatform().setNominalViewingTransform();
        u.addBranchGraph(scene);
    }

    public static void main(String[] args) {
        new MainFrame( new CubeTest(), 400, 400);
    }
}