import java.applet.Applet;import java.awt.*;import javax.swing.*;import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.geometry.ColorCube;import com.sun.j3d.utils.universe.SimpleUniverse;import javax.media.j3d.*;import javax.vecmath.*;public class Kuup2a extends JApplet implements Runnable{ TransformGroup keere1; TransformGroup keere2; TransformGroup keere3; TransformGroup keere21; TransformGroup keere22; TransformGroup keere23; TransformGroup keere11; TransformGroup keere12; TransformGroup keere13; double nurk; public Kuup2a() { Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); getContentPane().add(c, BorderLayout.CENTER); BranchGroup juur = new BranchGroup(); Transform3D keerd11=new Transform3D(); keerd11.setTranslation(new Vector3d(-0.6f, 0, 0)); keere11=new TransformGroup(keerd11); Transform3D keerd12=new Transform3D(); keerd12.setTranslation(new Vector3d(0, 0, 0)); keere12=new TransformGroup(keerd12); Transform3D keerd13=new Transform3D(); keerd13.setTranslation(new Vector3d(0.6f, 0, 0)); keere13=new TransformGroup(keerd13); Transform3D keerd1=new Transform3D(); keere1=new TransformGroup(keerd1); keere1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D keerd2=new Transform3D(); keere2=new TransformGroup(keerd2); keere2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D keerd3=new Transform3D(); keere3=new TransformGroup(keerd3); keere3.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); /*---Teine keeramine---*/ Transform3D keerd21=new Transform3D(); keere21=new TransformGroup(keerd21); keere21.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D keerd22=new Transform3D(); keere22=new TransformGroup(keerd22); keere22.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D keerd23=new Transform3D(); keere23=new TransformGroup(keerd3); keere23.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); /*---Teine keeramine lõpp---*/ juur.addChild(keere11); juur.addChild(keere12); juur.addChild(keere13); keere21.addChild(keere1); keere22.addChild(keere2); keere23.addChild(keere3); keere11.addChild(keere21); keere12.addChild(keere22); keere13.addChild(keere23); /*---Siit algab kuup---*/ keere1.addChild(new ColorCube(0.2)); /*---Siit lõppeb kuup---*/ /*---Siit algab silinder---*/ Cylinder s1=new Cylinder(0.1f, 0.5f); Appearance valimus1=new Appearance(); Material materjal1=new Material( new Color3f(Color.black), new Color3f(Color.red), new Color3f(Color.green), new Color3f(Color.black), 1 ); valimus1.setMaterial(materjal1); s1.setAppearance(valimus1); keere2.addChild(s1); /*---Siit lõppeb silinder---*/ /*---Siin on koonus---*/ Cone c1=new Cone(0.1f, 0.5f); Appearance valimus=new Appearance(); Material materjal=new Material( new Color3f(Color.black), new Color3f(Color.blue), new Color3f(Color.blue), new Color3f(Color.black), 1 ); valimus.setMaterial(materjal); c1.setAppearance(valimus); keere3.addChild(c1); /*---Siin lõppeb koonus---*/ juur.compile(); SimpleUniverse u = new SimpleUniverse(c); u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(juur); new Thread(this).start(); } public void run(){ while(true){ try{Thread.sleep(50);}catch(Exception e){} nurk+=0.1; Transform3D a=new Transform3D(); a.rotY(nurk); //Silindri jaoks Transform3D b=new Transform3D(); b.rotX(nurk); //Silindri jaoks Transform3D c=new Transform3D(); c.rotZ(nurk); Transform3D a1=new Transform3D(); a1.rotX(nurk); //Silindri jaoks Transform3D b1=new Transform3D(); b1.rotZ(nurk); //Silindri jaoks Transform3D c1=new Transform3D(); c1.rotY(nurk); keere1.setTransform(a); keere2.setTransform(b); keere3.setTransform(c); keere21.setTransform(a1); keere22.setTransform(b1); keere23.setTransform(c1); } } public static void main(String[] args) { Frame f=new Frame("Keerlevad kujundid"); f.add(new Kuup2a()); f.setSize(300, 300); f.setVisible(true); }}