import java.applet.Applet; import java.awt.*; import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.SimpleUniverse; import com.sun.j3d.utils.behaviors.keyboard.*; import com.sun.j3d.utils.behaviors.mouse.*; import javax.media.j3d.*; import javax.vecmath.*; public class ctuff extends Applet { public ctuff() { setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); add(c, BorderLayout.CENTER); BranchGroup juur = new BranchGroup(); Appearance post=new Appearance(); Material materjal=new Material( new Color3f(Color.black), //hajuvalgus new Color3f(Color.black), //eralduv new Color3f(Color.gray), //peegelduv valgus new Color3f(Color.gray), 0 //läige ); materjal.setCapability(Material.ALLOW_COMPONENT_WRITE); post.setMaterial(materjal); DirectionalLight suundvalgus=new DirectionalLight(); suundvalgus.setInfluencingBounds(new BoundingSphere(new Point3d(), 1000)); suundvalgus.setColor(new Color3f(0.2f,0.2f,0.2f)); //juur.addChild(suundvalgus); TransformGroup asd; Transform3D dfg; SpotLight val; for (int i=0; i<20; i=i+2){ dfg = new Transform3D(); dfg.setTranslation(new Vector3f(0, 0, -i)); asd = new TransformGroup(dfg); asd.addChild(new Cylinder(0.1f, 2, post)); juur.addChild(asd); dfg = new Transform3D(); dfg.rotZ(-4*Math.PI/10); dfg.setTranslation(new Vector3f(0.3f, 1.1f, -i)); asd = new TransformGroup(dfg); asd.addChild(new Cylinder(0.08f, 0.8f, post)); juur.addChild(asd); dfg = new Transform3D(); dfg.setTranslation(new Vector3f(0.8f, 1.2f, -i)); asd = new TransformGroup(dfg); asd.addChild(new Cylinder(0.2f, 0.1f, post)); juur.addChild(asd); if ((i != 4)&&(i != 8)&&(i != 10)) { dfg = new Transform3D(); dfg.setTranslation(new Vector3f(0.8f, 1.15f, -i)); asd = new TransformGroup(dfg); asd.addChild(new Cylinder(0.2f, 0.01f, new Appearance())); juur.addChild(asd); } if ((i != 4)&&(i != 8)&&(i != 10)) { dfg = new Transform3D(); dfg.setTranslation(new Vector3f(1, 1.1f, -i)); asd = new TransformGroup(dfg); val = new SpotLight(); val.setConcentration(4); val.setDirection(new Vector3f(0,-1,0)); val.setSpreadAngle((float)(Math.PI/2)); val.setColor(new Color3f(1, 1, 0.9f)); val.setInfluencingBounds(new BoundingSphere(new Point3d(), 4)); asd.addChild(val); juur.addChild(asd); } } Appearance plaat=new Appearance(); Material materja=new Material( new Color3f(Color.black), new Color3f(Color.black), new Color3f(Color.gray), new Color3f(Color.black), 0 ); materjal.setCapability(Material.ALLOW_COMPONENT_WRITE); plaat.setMaterial(materja); //kujund = new Shape3D(nurgad, plaat); for (int i=0; i<2; i++){ for (int j=0; j<82; j++){ dfg = new Transform3D(); dfg.setTranslation(new Vector3f((float)(i*2), -1, -j/2+1)); asd = new TransformGroup(dfg); asd.addChild(new Box(1f, 0.05f, 0.5f, plaat)); juur.addChild(asd); } } TransformGroup tg1=new TransformGroup(); tg1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D suund=new Transform3D(); suund.rotY(Math.PI/2); Alpha a=new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE , 0, 8000, 8000, 8000, 0, 8000, 8000, 0); PositionInterpolator liigutaja1= new PositionInterpolator(a, tg1, suund, 0, 10); liigutaja1.setSchedulingBounds(new BoundingSphere()); dfg = new Transform3D(); dfg.setTranslation(new Vector3f(1, 0, 0)); asd = new TransformGroup(dfg); asd.addChild(tg1); tg1.addChild(liigutaja1); PointLight val1 = new PointLight(); val1.setAttenuation(1, 0.8f, 0); val1.setColor(new Color3f(0.7f, 1, 1)); val1.setInfluencingBounds(new BoundingSphere(new Point3d(), 5)); tg1.addChild(val1); dfg = new Transform3D(); dfg.rotX(Math.PI/2); TransformGroup asdf = new TransformGroup(dfg); Appearance valgus=new Appearance(); Material aterjal=new Material( new Color3f(Color.black), //hajuvalgus new Color3f(0.7f, 1, 1), //eralduv new Color3f(Color.black), //peegelduv valgus new Color3f(Color.black), 1 //läige ); aterjal.setCapability(Material.ALLOW_COMPONENT_WRITE); valgus.setMaterial(aterjal); asdf.addChild(new Cylinder(0.05f, 0.2f, valgus)); tg1.addChild(asdf); juur.addChild(asd); SimpleUniverse u = new SimpleUniverse(c); TransformGroup tg=u.getViewingPlatform().getViewPlatformTransform(); KeyNavigatorBehavior k=new KeyNavigatorBehavior(tg); k.setSchedulingBounds(new BoundingSphere(new Point3d(), 100)); juur.addChild(k); juur.compile(); u.addBranchGraph(juur); } public static void main(String[] args) { Frame f=new Frame("Siplev 3d ctuff"); f.add(new ctuff()); f.setSize(400, 400); f.setVisible(true); } }