import java.applet.Applet; import java.awt.*; import java.util.Enumeration; 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 Asukoht4 extends Applet { public Asukoht4() { setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); Canvas tasapind=new Canvas(); setLayout(new GridLayout(2, 1)); add(tasapind); add(c); BranchGroup juur = new BranchGroup(); for(int i=1; i<1000; i++){ 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(); Klahviliikur k=new Klahviliikur(tg, tasapind); k.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000)); juur.addChild(k); 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 Asukoht4()); f.setSize(400, 600); f.setVisible(true); } class Klahviliikur extends KeyNavigatorBehavior{ TransformGroup siht; Canvas louend; Transform3D t=new Transform3D(); Matrix3f m=new Matrix3f(); Vector3f v=new Vector3f(); public Klahviliikur(TransformGroup tg1, Canvas l1){ super(tg1); siht=tg1; louend=l1; } public void processStimulus(Enumeration e){ super.processStimulus(e); siht.getTransform(t); t.get(m, v); Graphics g=louend.getGraphics(); g.setColor(new Color(230, 230, 230)); g.fillRect(0, 0, louend.getWidth(), louend.getHeight()); g.setColor(Color.black); g.drawString((int)v.x+" "+(int)v.y+" "+(int)v.z , 100+(int)(2*v.x), 100+(int)(2*v.z)); } } }