import java.applet.Applet; import java.awt.*; import com.sun.j3d.utils.geometry.ColorCube; import com.sun.j3d.utils.universe.SimpleUniverse; import com.sun.j3d.utils.behaviors.keyboard.*; import javax.media.j3d.*; import javax.vecmath.*; public class Asukoht2 extends Applet { public Asukoht2() { setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); add(c, BorderLayout.CENTER); BranchGroup juur = new BranchGroup(); for(int i=1; i<10; i++){ //luuakse hulk juhuslikke kuupe taevasse for(int j=1; j<10; j++){ for(int k=1; k<10; k++){ Transform3D t3=new Transform3D(); t3.setTranslation(new Vector3f((float)(100*Math.random()-50), (float)(100*Math.random()-50), (float)(100*Math.random()-50))); TransformGroup tg=new TransformGroup(t3); tg.addChild(new ColorCube(0.4)); juur.addChild(tg); } } } SimpleUniverse u = new SimpleUniverse(c); TransformGroup tg=u.getViewingPlatform().getViewPlatformTransform(); KeyNavigatorBehavior kb=new KeyNavigatorBehavior(tg); kb.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000)); juur.addChild(kb); Transform3D t=new Transform3D(); //Määratakse vaatekoht t.setTranslation(new Vector3f(0, 0, -5)); u.getViewingPlatform().getViewPlatformTransform().setTransform(t); Background taust=new Background(new Color3f(Color.blue)); //sinine taust taust.setApplicationBounds(new BoundingSphere(new Point3d(), 1000)); juur.addChild(taust); u.addBranchGraph(juur); } public static void main(String[] args) { Frame f=new Frame("Kuubid taevas"); f.add(new Asukoht2()); f.setSize(300, 300); f.setVisible(true); } }